Skip to content

Commit

Permalink
Keep status from spec when publishing profiles. Refs #13
Browse files Browse the repository at this point in the history
  • Loading branch information
twagoo committed Aug 23, 2016
1 parent 5446091 commit 778515b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ public Response publishRegisteredProfile(
try {
Principal principal = checkAndGetUserPrincipal();
ComponentRegistry registry = this.getBaseRegistry();
registry.setRegistrySpace(RegistrySpace.PUBLISHED);
ProfileDescription desc = registry.getProfileDescriptionAccessControlled(profileId);
if (desc != null) {
if (desc.isPublic()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import clarin.cmdi.componentregistry.UserUnauthorizedException;
import clarin.cmdi.componentregistry.components.ComponentSpec;
import clarin.cmdi.componentregistry.model.BaseDescription;
import clarin.cmdi.componentregistry.model.ComponentStatus;
import clarin.cmdi.componentregistry.model.RegisterResponse;

public class PublishAction implements RegisterAction {
Expand All @@ -25,7 +24,6 @@ public int execute(BaseDescription desc, ComponentSpec spec, RegisterResponse re
response.setIsPrivate(false);
spec.setCMDOriginalVersion(CmdVersion.CANONICAL_CMD_VERSION.getVersionNumber());
spec.setCMDVersion(CmdVersion.CANONICAL_CMD_VERSION.getVersionNumber());
spec.getHeader().setStatus(ComponentStatus.PRODUCTION.toString());
return registry.publish(desc, spec, principal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ public void testRegisterProfile() throws Exception {
}

@Test
public void testPublishProfile() throws Exception {
public void testPublishProfileAsProduction() throws Exception {

System.out.println("testPublishProfile");

Expand Down Expand Up @@ -1153,20 +1153,46 @@ public void testPublishProfile() throws Exception {
RegisterResponse.class, form);

assertEquals(1, getUserProfiles().size());

List<ProfileDescription> profiles = getPublicProfiles();
assertEquals(3, profiles.size());

ProfileDescription profileDescription = profiles.get(2);
assertNotNull(profileDescription.getId());
assertEquals(desc.getId(), profileDescription.getId());
assertEquals("http://localhost:9998" + REGISTRY_BASE + "/profiles/" + desc.getId(),
profileDescription.getHref());
assertEquals("publishedName3", profileDescription.getName());
assertEquals("publishedName3 description", profileDescription.getDescription());
assertEquals(PRODUCTION, profileDescription.getStatus());
ComponentSpec spec = getPublicSpec(profileDescription);
assertEquals("publishedName3", spec.getComponent().getName());
assertEquals(PRODUCTION.toString(), spec.getHeader().getStatus());
assertEquals("1.2", spec.getCMDVersion());
assertEquals("1.2", spec.getCMDOriginalVersion());
}

@Test
public void testPublishProfileAsDevelopment() throws Exception {
fillUpPrivateItems();
fillUpPublicItems();

//skipping some tests that already take place in the same context in testPublishProfileAsProduction

FormDataMultiPart form = createFormData(
RegistryTestHelper.getTestProfileContent(), "description");
RegisterResponse response = getAuthenticatedResource(getResource().path(REGISTRY_BASE + "/profiles")).type(
MediaType.MULTIPART_FORM_DATA).post(RegisterResponse.class, form);
BaseDescription desc = response.getDescription();
form = createFormData(
RegistryTestHelper.getTestProfileContent("publishedButDevelopment", DEVELOPMENT.toString()),
"publishedButDevelopment description");
//post
getAuthenticatedResource(getResource().path(
REGISTRY_BASE + "/profiles/" + desc.getId() + "/publish"))
.type(MediaType.MULTIPART_FORM_DATA).post(
RegisterResponse.class, form);

//skipping some tests that already take place in the same context in testPublishProfileAsProduction

ProfileDescription profileDescription = getPublicProfiles().get(2);
assertEquals(desc.getId(), profileDescription.getId());
assertEquals(DEVELOPMENT, profileDescription.getStatus());

ComponentSpec spec = getPublicSpec(profileDescription);
assertEquals(DEVELOPMENT.toString(), spec.getHeader().getStatus());
}

private ComponentSpec getPublicSpec(BaseDescription desc) {
Expand Down

0 comments on commit 778515b

Please sign in to comment.