/** \r
- * OrgAuthorityClientUtils.java\r
- *\r
- * {Purpose of This Class}\r
- *\r
- * {Other Notes Relating to This Class (Optional)}\r
- *\r
- * $LastChangedBy: $\r
- * $LastChangedRevision$\r
- * $LastChangedDate$\r
- *\r
* This document is a part of the source code and related artifacts\r
* for CollectionSpace, an open source collections management system\r
* for museums and related institutions:\r
* http://www.collectionspace.org\r
* http://wiki.collectionspace.org\r
*\r
- * Copyright © 2009 {Contributing Institution}\r
+ * Copyright © 2009 University of California, Berkeley\r
*\r
* Licensed under the Educational Community License (ECL), Version 2.0.\r
* You may not use this file except in compliance with this License.\r
import javax.ws.rs.core.Response;\r
\r
import org.collectionspace.services.OrganizationJAXBSchema;\r
-import org.collectionspace.services.client.test.BaseServiceTest;\r
import org.collectionspace.services.client.test.ServiceRequestType;\r
import org.collectionspace.services.organization.ContactNameList;\r
import org.collectionspace.services.organization.FunctionList;\r
import org.collectionspace.services.organization.OrgauthoritiesCommon;\r
import org.collectionspace.services.organization.OrgTermGroup;\r
import org.collectionspace.services.organization.OrgTermGroupList;\r
-import org.collectionspace.services.person.PersonauthoritiesCommon;\r
-import org.collectionspace.services.person.PersonsCommon;\r
import org.jboss.resteasy.client.ClientResponse;\r
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
/**\r
- * The Class OrgAuthorityClientUtils.\r
+ * OrgAuthorityClientUtils.\r
*/\r
public class OrgAuthorityClientUtils {\r
\r
* @return the string\r
*/\r
public static String createItemInAuthority( String inAuthority,\r
- String orgAuthorityRefName, List<OrgTermGroup> terms, Map<String, String> orgInfo,\r
+ String orgAuthorityRefName, Map<String, String> orgInfo, List<OrgTermGroup> terms,\r
Map<String, List<String>> orgRepeatablesInfo, OrgAuthorityClient client) {\r
// Expected status code: 201 Created\r
int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
// Type of service request being tested\r
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
- String displayName = createDisplayName(orgInfo);\r
+\r
+ String displayName = "";\r
+ if (terms !=null && terms.size() > 0) {\r
+ displayName = terms.get(0).getTermDisplayName();\r
+ }\r
\r
if(logger.isDebugEnabled()){\r
logger.debug("Import: Create Item: \""+displayName\r
String value = null;\r
List<String> values = null;\r
\r
+ // Set values in the Term Information Group\r
+ OrgTermGroupList termList = new OrgTermGroupList();\r
+ termList.getOrgTermGroup().addAll(terms);\r
+ organization.setOrgTermGroupList(termList);\r
\r
- // Handle terms here\r
-\r
if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) {\r
ContactNameList contactsList = new ContactNameList();\r
List<String> contactNames = contactsList.getContactName();\r
return newStr.toString();\r
}\r
\r
- public static String createDisplayName(Map<String, String> orgInfo) {\r
- String displayName = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME);\r
- String displayNameComputedStr = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
- boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true");\r
- if( displayName == null ) {\r
- if(!displayNameComputed) {\r
- throw new RuntimeException(\r
- "CreateItem: Must supply a displayName if displayNameComputed is set to false.");\r
- }\r
- displayName = prepareDefaultDisplayName(\r
- orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ),\r
- orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE ));\r
- }\r
- return displayName;\r
+ public static List<OrgTermGroup> getTermGroupInstance(String identifier) {\r
+ List<OrgTermGroup> terms = new ArrayList<OrgTermGroup>();\r
+ OrgTermGroup term = new OrgTermGroup();\r
+ term.setTermDisplayName(identifier);\r
+ term.setTermName(identifier);\r
+ terms.add(term);\r
+ return terms;\r
}\r
\r
}\r
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;
testOrgContactNames.add(organizationContactPersonRefName1);
testOrgContactNames.add(organizationContactPersonRefName2);
testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
- List<String> testOrgSubBodies = new ArrayList<String>();
- testOrgSubBodies.add(subBodyRefName);
- testOrgRepeatablesMap.put(OrganizationJAXBSchema.SUB_BODIES, testOrgSubBodies);
-
- MainBodyGroupList mainBodyList = new MainBodyGroupList();
- List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
- MainBodyGroup mainBodyGroup = new MainBodyGroup();
- mainBodyGroup.setShortName("Test Organization-" + shortId);
- mainBodyGroup.setLongName("Test Organization Name");
- mainBodyGroups.add(mainBodyGroup);
+
+ List<OrgTermGroup> 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.
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- String csid = createPerson("Charlie", "Orgcontact", "charlieOrgcontact", null ); // authRefName);
+ String csid = createPerson(personAuthCSID, "Charlie", "Orgcontact", "charlieOrgcontact", null ); // authRefName);
personIdsCreated.add(csid);
organizationContactPersonRefName1 = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- csid = createPerson("Chelsie", "Contact", "chelsieContact", null ); // authRefName);
+ csid = createPerson(personAuthCSID, "Chelsie", "Contact", "chelsieContact", null ); // authRefName);
personIdsCreated.add(csid);
organizationContactPersonRefName2 = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
}
* @param authRefName
* @return the string
*/
- protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
+ protected String createPerson(String personAuthCSID, String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
- personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
- personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
List<PersonTermGroup> personTerms = new ArrayList<PersonTermGroup>();
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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
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;
protected String getServiceName() {
return OrgAuthorityClient.SERVICE_NAME;
}
- /** The test organization shortname. */
- private final String TEST_ORG_SHORTNAME = "Test Org";
-
- /** The test organization founding place. */
+ private final String TEST_SHORT_ID = "TestOrg";
+ private final String TEST_ORG_NAME = "Test Org";
+ private final String TEST_ORG_MAIN_BODY_NAME = "The real official test organization";
private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
+ // FIXME: Change this to a structured date once this field changes in the schema.
+ private final String TEST_ORG_FOUNDING_DATE = "May 26, 1907";
private String knownItemResourceShortIdentifer = null;
@Override
protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
- String shortId = "testOrg";
+
+ String shortId = TEST_SHORT_ID;
Map<String, String> testOrgMap = new HashMap<String, String>();
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<OrgTermGroup> terms = new ArrayList<OrgTermGroup>();
+ 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);
}
/**
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
- String shortId = "testOrg";
+
+ String shortId = TEST_SHORT_ID;
Map<String, String> testOrgMap = new HashMap<String, String>();
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<OrgTermGroup> terms = new ArrayList<OrgTermGroup>();
+ 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<String, List<String>> testOrgRepeatablesMap = new HashMap<String, List<String>>();
List<String> testOrgContactNames = new ArrayList<String>();
testOrgContactNames.add("joe@example.org");
testOrgContactNames.add("sally@example.org");
testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
- MainBodyGroupList mainBodyList = new MainBodyGroupList();
- List<MainBodyGroup> 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.
Assert.assertTrue(contactNames.size() > 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<String> 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<MainBodyGroup> 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();
res.releaseConnection();
}
}
+
//
- // Try to Update with 'displayNameComputed' flag set to false and no displayName
+ // Make an invalid UPDATE request, without a display name
//
- organization.setDisplayNameComputed(false);
- organization.setDisplayName(null);
+ OrgTermGroupList termList = organization.getOrgTermGroupList();
+ Assert.assertNotNull(termList);
+ List<OrgTermGroup> 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.
@Override
protected OrganizationsCommon updateItemInstance(OrganizationsCommon organizationsCommon) {
- OrganizationsCommon result = organizationsCommon; //new OrganizationsCommon();
-
- MainBodyGroupList mainBodyList = organizationsCommon.getMainBodyGroupList();
- Assert.assertNotNull(mainBodyList);
- List<MainBodyGroup> 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<OrgTermGroup> 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<OrgTermGroup> originalTerms = originalTermList.getOrgTermGroup();
+ Assert.assertNotNull(originalTerms);
+ Assert.assertTrue(originalTerms.size() > 0);
+
+ OrgTermGroupList updatedTermList = updated.getOrgTermGroupList();
+ Assert.assertNotNull(updatedTermList);
+ List<OrgTermGroup> 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
String identifier) {
Map<String, String> nonexOrgMap = new HashMap<String, String>();
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;
}
original.getDisplayName(),
"Display name in updated object did not match submitted data.");
}
+
}