From 97db1b7816a1e8b5b6ac55d2f5af487c7c740881 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 4 May 2012 16:48:04 -0700 Subject: [PATCH] CSPACE-5135,CSPACE-5155,CSPACE-5156: All but one Organization test passes after term info group changes. --- .../tenants/tenant-bindings-proto.xml | 4 +- .../services/client/OrgAuthorityClient.java | 2 +- .../client/OrgAuthorityClientUtils.java | 53 ++-- .../client/test/OrgAuthorityAuthRefsTest.java | 29 +-- .../client/test/OrgAuthorityServiceTest.java | 245 +++++------------- .../services/OrganizationJAXBSchema.java | 5 +- .../client/PersonAuthorityClientUtils.java | 22 +- .../test/PersonAuthorityServiceTest.java | 5 +- 8 files changed, 124 insertions(+), 241 deletions(-) diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 7d0bbedf9..008be55b6 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -1807,8 +1807,8 @@ inauthority - organizations_common - displayname + orgtermgroup + termdisplayname organizations_common diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java index ebeeb796e..79f5f5f0b 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -36,7 +36,7 @@ public class OrgAuthorityClient extends AuthorityWithContactsClientImpl terms, Map orgInfo, + String orgAuthorityRefName, Map orgInfo, List terms, Map> orgRepeatablesInfo, OrgAuthorityClient client) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; - String displayName = createDisplayName(orgInfo); + + String displayName = ""; + if (terms !=null && terms.size() > 0) { + displayName = terms.get(0).getTermDisplayName(); + } if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+displayName @@ -247,9 +237,11 @@ public class OrgAuthorityClientUtils { String value = null; List values = null; + // Set values in the Term Information Group + OrgTermGroupList termList = new OrgTermGroupList(); + termList.getOrgTermGroup().addAll(terms); + organization.setOrgTermGroupList(termList); - // Handle terms here - if((values = (List)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) { ContactNameList contactsList = new ContactNameList(); List contactNames = contactsList.getContactName(); @@ -394,20 +386,13 @@ public class OrgAuthorityClientUtils { return newStr.toString(); } - public static String createDisplayName(Map orgInfo) { - String displayName = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME); - String displayNameComputedStr = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true"); - if( displayName == null ) { - if(!displayNameComputed) { - throw new RuntimeException( - "CreateItem: Must supply a displayName if displayNameComputed is set to false."); - } - displayName = prepareDefaultDisplayName( - orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ), - orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE )); - } - return displayName; + public static List getTermGroupInstance(String identifier) { + List terms = new ArrayList(); + OrgTermGroup term = new OrgTermGroup(); + term.setTermDisplayName(identifier); + term.setTermName(identifier); + terms.add(term); + return terms; } } diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java index 2125087e2..7e5f25e58 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java @@ -40,9 +40,8 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.organization.MainBodyGroup; -import org.collectionspace.services.organization.MainBodyGroupList; import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrgTermGroup; import org.collectionspace.services.person.PersonTermGroup; import org.jboss.resteasy.client.ClientResponse; @@ -194,22 +193,14 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest testOrgSubBodies = new ArrayList(); - testOrgSubBodies.add(subBodyRefName); - testOrgRepeatablesMap.put(OrganizationJAXBSchema.SUB_BODIES, testOrgSubBodies); - - MainBodyGroupList mainBodyList = new MainBodyGroupList(); - List mainBodyGroups = mainBodyList.getMainBodyGroup(); - MainBodyGroup mainBodyGroup = new MainBodyGroup(); - mainBodyGroup.setShortName("Test Organization-" + shortId); - mainBodyGroup.setLongName("Test Organization Name"); - mainBodyGroups.add(mainBodyGroup); + + List terms = OrgAuthorityClientUtils.getTermGroupInstance("Org name"); // Finishing creating the new Organization item, then // submit the request to the service and store the response. knownItemResourceId = OrgAuthorityClientUtils.createItemInAuthority( knownResourceId, knownResourceRefName, testOrgMap, - testOrgRepeatablesMap, mainBodyList, orgAuthClient); + terms, testOrgRepeatablesMap, orgAuthClient); // Store the IDs from every item created by tests, // so they can be deleted after tests have been run. @@ -241,13 +232,13 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest personInfo = new HashMap(); - personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); - personInfo.put(PersonJAXBSchema.SUR_NAME, surName); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); List personTerms = new ArrayList(); PersonTermGroup term = new PersonTermGroup(); String termName = firstName + " " + surName; term.setTermDisplayName(termName); term.setTermName(termName); + term.setForeName(firstName); + term.setSurName(surName); personTerms.add(term); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); + null, personInfo, personTerms, personAuthClient.getItemCommonPartName()); String result = null; ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index fde3af062..aa6b29162 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -44,10 +44,10 @@ import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.client.OrgAuthorityClient; import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.organization.MainBodyGroup; -import org.collectionspace.services.organization.MainBodyGroupList; import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrgTermGroup; +import org.collectionspace.services.organization.OrgTermGroupList; import org.jboss.resteasy.client.ClientResponse; @@ -81,11 +81,12 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); - testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME); - testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); - testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907"); + testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE); - - return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel); + + List terms = new ArrayList(); + OrgTermGroup term = new OrgTermGroup(); + term.setTermDisplayName(TEST_ORG_NAME); + term.setTermName(TEST_ORG_NAME); + term.setMainBodyName(TEST_ORG_MAIN_BODY_NAME); + terms.add(term); + + return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, terms, headerLabel); } /** @@ -148,29 +155,28 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); - testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME); - testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); - testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907"); + testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE); - + + List terms = new ArrayList(); + OrgTermGroup term = new OrgTermGroup(); + term.setTermDisplayName(TEST_ORG_NAME); + term.setTermName(TEST_ORG_NAME); + term.setMainBodyName(TEST_ORG_MAIN_BODY_NAME); + terms.add(term); + Map> testOrgRepeatablesMap = new HashMap>(); List testOrgContactNames = new ArrayList(); testOrgContactNames.add("joe@example.org"); testOrgContactNames.add("sally@example.org"); testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames); - MainBodyGroupList mainBodyList = new MainBodyGroupList(); - List mainBodyGroups = mainBodyList.getMainBodyGroup(); - MainBodyGroup mainBodyGroup = new MainBodyGroup(); - mainBodyGroup.setShortName(TEST_ORG_SHORTNAME); - mainBodyGroup.setLongName("The real official test organization"); - mainBodyGroups.add(mainBodyGroup); - String newID = OrgAuthorityClientUtils.createItemInAuthority( - vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client); + vcsid, authRefName, testOrgMap, terms, testOrgRepeatablesMap, client); // Store the ID returned from the first item resource created // for additional tests below. @@ -442,139 +448,14 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest 0); Assert.assertNotNull(contactNames.get(0)); } - - /** - * Verify item display name. - * - * @param testName the test name - * @throws Exception the exception - */ - @Test(dataProvider = "testName", - dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"}) - public void verifyItemDisplayName(String testName) throws Exception { - // Perform setup. - setupRead(); - // - // First, read our known resource. - // - OrgAuthorityClient client = new OrgAuthorityClient(); - PoxPayloadIn input = null; - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - try { - assertStatusCode(res, testName); - // Check whether organization has expected displayName. - input = new PoxPayloadIn(res.getEntity()); - Assert.assertNotNull(input); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - - // Check whether organization has expected displayName. - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - String displayName = organization.getDisplayName(); - // Make sure displayName matches computed form - String expectedDisplayName = - OrgAuthorityClientUtils.prepareDefaultDisplayName( - TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE); - Assert.assertNotNull(displayName, expectedDisplayName); - - // Update the shortName and verify the computed name is updated. - organization.setCsid(null); - organization.setDisplayNameComputed(true); - - MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); - List mainBodyGroups = mainBodyList.getMainBodyGroup(); - MainBodyGroup mainBodyGroup = new MainBodyGroup(); - String updatedShortName = "updated-" + TEST_ORG_SHORTNAME; - mainBodyGroup.setShortName(updatedShortName); - mainBodyGroups.clear(); //clear all the elements and do a sparse update - mainBodyGroups.add(mainBodyGroup); - organization.setMainBodyGroupList(mainBodyList); - - expectedDisplayName = - OrgAuthorityClientUtils.prepareDefaultDisplayName( - updatedShortName, TEST_ORG_FOUNDING_PLACE); - // - // Next, submit the updated resource to the service and store the response. - // - setupUpdate(); - PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), organization); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - try { - assertStatusCode(res, testName); - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - // - // Now verify the update was correct. - // - OrganizationsCommon updatedOrganization = - (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(updatedOrganization); - - // Verify that the updated resource received the correct data. - mainBodyList = organization.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), - updatedShortName, "Updated ShortName in Organization did not match submitted data."); - - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName, - "Updated ShortName in Organization not reflected in computed DisplayName."); - // - // Now Update the displayName, not computed and verify the computed name is overriden. - // - organization.setDisplayNameComputed(false); - expectedDisplayName = "TestName"; - organization.setDisplayName(expectedDisplayName); - - // Submit the updated resource to the service and store the response. - output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(client.getItemCommonPartName(), organization); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - input = null; - try { - assertStatusCode(res, testName); - // Retrieve the updated resource and verify that its contents exist. - input = new PoxPayloadIn(res.getEntity()); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - updatedOrganization = - (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(updatedOrganization); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false, - "Updated displayNameComputed in Organization did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedOrganization.getDisplayName(), - expectedDisplayName, - "Updated DisplayName (not computed) in Organization not stored."); - } - + /** * Verify illegal item display name. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider = "testName", - dependsOnMethods = {"verifyItemDisplayName"}) + @Test(dataProvider = "testName") public void verifyIllegalItemDisplayName(String testName) throws Exception { // Perform setup for read. setupRead(); @@ -596,11 +477,17 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest terms = termList.getOrgTermGroup(); + Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); + terms.get(0).setTermDisplayName(null); + terms.get(0).setTermName(null); setupUpdateWithInvalidBody(); // we expect a failure // Submit the updated resource to the service and store the response. @@ -1185,27 +1072,39 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest mainBodyGroups = mainBodyList.getMainBodyGroup(); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); - mainBodyGroups.get(0).setShortName(updatedShortName); - - return result; + + OrganizationsCommon result = organizationsCommon; + + OrgTermGroupList termList = result.getOrgTermGroupList(); + Assert.assertNotNull(termList); + List terms = termList.getOrgTermGroup(); + Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); + terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName()); + terms.get(0).setTermName("updated-" + terms.get(0).getTermName()); + + return result; } @Override protected void compareUpdatedItemInstances(OrganizationsCommon original, OrganizationsCommon updated) throws Exception { - MainBodyGroupList mainBodyList = original.getMainBodyGroupList(); - Assert.assertNotNull(mainBodyList); - Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); - Assert.assertEquals(updated.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), - original.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), - "Short name in updated Organization did not match submitted data."); + + OrgTermGroupList originalTermList = original.getOrgTermGroupList(); + Assert.assertNotNull(originalTermList); + List originalTerms = originalTermList.getOrgTermGroup(); + Assert.assertNotNull(originalTerms); + Assert.assertTrue(originalTerms.size() > 0); + + OrgTermGroupList updatedTermList = updated.getOrgTermGroupList(); + Assert.assertNotNull(updatedTermList); + List updatedTerms = updatedTermList.getOrgTermGroup(); + Assert.assertNotNull(updatedTerms); + Assert.assertTrue(updatedTerms.size() > 0); + + Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(), + originalTerms.get(0).getTermDisplayName(), + "Value in updated record did not match submitted data."); } @Override @@ -1234,11 +1133,10 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest nonexOrgMap = new HashMap(); nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent"); - nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); PoxPayloadOut result = OrgAuthorityClientUtils.createOrganizationInstance( knownResourceRefName, - nonexOrgMap, commonPartName); + nonexOrgMap, OrgAuthorityClientUtils.getTermGroupInstance(TEST_ORG_NAME), commonPartName); return result; } @@ -1260,4 +1158,5 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest> EMPTY_PERSON_REPEATABLES_INFO = new HashMap>(); + if (terms == null || terms.size() == 0) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } return createPersonInstance(inAuthority, null /*personAuthRefName*/, personInfo, terms, EMPTY_PERSON_REPEATABLES_INFO, headerLabel); } @@ -446,6 +445,17 @@ public class PersonAuthorityClientUtils { return newStr.toString(); } - + public static List getTermGroupInstance(String identifier) { + List terms = new ArrayList(); + PersonTermGroup term = new PersonTermGroup(); + term.setTermDisplayName(identifier); + term.setTermName(identifier); + terms.add(term); + return terms; + } + + private static String getGeneratedIdentifier() { + return "id" + new Date().getTime(); + } } diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 5f234d5a8..61f815534 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -46,7 +46,6 @@ import org.collectionspace.services.client.PersonAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; -import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.person.PersonauthoritiesCommon; import org.collectionspace.services.person.PersonTermGroup; import org.collectionspace.services.person.PersonTermGroupList; @@ -627,7 +626,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest terms = termList.getPersonTermGroup(); Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); terms.get(0).setTermDisplayName(null); terms.get(0).setTermName(null); @@ -1007,6 +1007,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest terms = termList.getPersonTermGroup(); Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); String foreName = terms.get(0).getForeName(); String updatedForeName = "updated-" + foreName; terms.get(0).setForeName(updatedForeName); -- 2.47.3