From f8609a799bdbc23a36f7cc29c5e4e1f02d940be7 Mon Sep 17 00:00:00 2001 From: remillet Date: Tue, 26 Apr 2016 20:37:18 -0700 Subject: [PATCH] CSPACE-6937-A: Additional authority tests recfactoring. --- .../test/CitationAuthorityServiceTest.java | 22 ++-- .../test/AbstractAuthorityServiceTest.java | 101 ++++++++++++++---- .../services/client/test/BaseServiceTest.java | 2 +- .../test/ConceptAuthorityServiceTest.java | 20 ++-- .../client/LocationAuthorityClientUtils.java | 21 ++-- .../test/LocationAuthorityServiceTest.java | 30 +++--- .../test/MaterialAuthorityServiceTest.java | 34 +++--- .../client/test/OrgAuthorityServiceTest.java | 35 +++--- .../OrganizationDocumentModelHandler.java | 5 +- .../client/PersonAuthorityClientUtils.java | 1 + .../test/PersonAuthorityServiceTest.java | 42 ++++---- .../test/PlaceAuthorityServiceTest.java | 43 ++++---- .../test/TaxonomyAuthorityServiceTest.java | 36 ++++--- .../client/test/VocabularyServiceTest.java | 22 +++- .../client/test/WorkAuthorityServiceTest.java | 42 +++----- 15 files changed, 267 insertions(+), 189 deletions(-) diff --git a/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java index a20a9c819..d9b7c60e3 100644 --- a/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java +++ b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java @@ -37,10 +37,9 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.CitationAuthorityClient; import org.collectionspace.services.client.CitationAuthorityClientUtils; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.jaxb.AbstractCommonList; + import org.dom4j.DocumentException; -import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -59,16 +58,19 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest client = (AuthorityClientImpl) - this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName()); if (payloadInputPart != null) { result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody(); @@ -398,8 +445,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl) - this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); Response res = client.readItem(knownResourceId, NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -424,7 +470,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); Response res = client.readItem(knownResourceId, knownItemResourceId); try { int statusCode = res.getStatus(); @@ -456,8 +502,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl) - this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); Response res = client.deleteItem(knownResourceId, knownItemResourceId); int statusCode; try { @@ -481,7 +526,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); Response res = null; if (vcsid != null) { res = client.readItemList(vcsid, null, null); @@ -539,7 +584,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); int statusCode; try { @@ -565,7 +610,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClient client = (AuthorityClient) getClientInstance(); PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent()); PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance); result = payloadOut; @@ -755,5 +800,17 @@ public abstract class AbstractAuthorityServiceTest { * Tests can override this method to customize their identifiers. */ protected String createIdentifier() { - long identifier = System.currentTimeMillis() + random.nextInt(); + long identifier = System.currentTimeMillis() + Math.abs(random.nextInt()); return Long.toString(identifier); } diff --git a/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java index 67b248259..7b7052307 100644 --- a/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java +++ b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java @@ -34,14 +34,13 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.ConceptAuthorityClient; import org.collectionspace.services.client.ConceptAuthorityClientUtils; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.concept.ConceptTermGroup; import org.collectionspace.services.concept.ConceptTermGroupList; import org.collectionspace.services.concept.ConceptauthoritiesCommon; import org.collectionspace.services.concept.ConceptsCommon; import org.collectionspace.services.jaxb.AbstractCommonList; import org.dom4j.DocumentException; -import org.jboss.resteasy.client.ClientResponse; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -58,11 +57,15 @@ import org.testng.annotations.Test; public class ConceptAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ - private final String CLASS_NAME = ConceptAuthorityServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(ConceptAuthorityServiceTest.class); - private final static String CURRENT_DATE_UTC = - GregorianCalendarDateTimeUtils.currentDateUTC(); + /** + * Default constructor. Used to set the short ID for all tests authority items + */ + ConceptAuthorityServiceTest() { + TEST_SHORTID = "concept1"; + } + @Override public String getServicePathComponent() { return ConceptAuthorityClient.SERVICE_PATH_COMPONENT; @@ -80,7 +83,6 @@ public class ConceptAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ - private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class); - private final static String CURRENT_DATE_UTC = - GregorianCalendarDateTimeUtils.currentDateUTC(); + private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC(); + /** + * Default constructor. Used to set the short ID for all tests authority items + */ + LocationAuthorityServiceTest() { + TEST_SHORTID = "shelf1"; + } + @Override public String getServicePathComponent() { return LocationAuthorityClient.SERVICE_PATH_COMPONENT; @@ -82,7 +87,6 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest shelf1Map = new HashMap(); // TODO Make loc type and status be controlled vocabs. - shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, shortId); shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); @@ -144,7 +153,7 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest materialMap = new HashMap(); // TODO Make material type and status be controlled vocabs. - materialMap.put(MaterialJAXBSchema.SHORT_IDENTIFIER, TEST_MATERIAL_SHORT_IDENTIFIER); + materialMap.put(MaterialJAXBSchema.SHORT_IDENTIFIER, shortId); materialMap.put(MaterialJAXBSchema.MATERIAL_DESCRIPTION, TEST_MATERIAL_DESCRIPTION); List terms = new ArrayList(); @@ -136,7 +137,7 @@ public class MaterialAuthorityServiceTest extends AbstractAuthorityServiceTest allContactResourceIdsCreated = - new HashMap(); + private Map allContactResourceIdsCreated = new HashMap(); + /** + * + */ protected void setKnownItemResource(String id, String shortIdentifer) { knownItemResourceId = id; knownItemResourceShortIdentifer = shortIdentifer; @@ -125,7 +135,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); @@ -141,6 +151,11 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, TEST_ORG_FOUNDING_DATE); @@ -1046,11 +1060,6 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest allContactResourceIdsCreated = new HashMap(); + protected void setKnownResource(String id, String shortIdentifer, String refName) { knownResourceId = id; @@ -212,11 +225,6 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest terms, Map itemRepeatableFieldProperties) { + Map itemFieldProperties, List terms, Map> itemRepeatableFieldProperties) { final String testName = "createItemInAuthority"; if (logger.isDebugEnabled()) { @@ -333,7 +341,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest> NULL_REPEATABLE_FIELD_PROPERTIES = null; PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(knownResourceId, null /*knownResourceRefName*/, fieldProperties, terms, @@ -451,7 +458,6 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest entry : allContactResourceIdsCreated.entrySet()) { contactResourceId = entry.getKey(); itemResourceId = entry.getValue(); diff --git a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java index 63f093412..42d9d4efa 100644 --- a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java +++ b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java @@ -60,9 +60,15 @@ import org.testng.annotations.Test; public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ - private final String CLASS_NAME = PlaceAuthorityServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(PlaceAuthorityServiceTest.class); + /** + * Default constructor. Used to set the short ID for all tests authority items + */ + PlaceAuthorityServiceTest() { + TEST_SHORTID = "sanjose"; + } + @Override public String getServicePathComponent() { return PlaceAuthorityClient.SERVICE_PATH_COMPONENT; @@ -78,17 +84,9 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest sanjoseMap = new HashMap(); // TODO Make place type and status be controlled vocabs. - sanjoseMap.put(PlaceJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + sanjoseMap.put(PlaceJAXBSchema.SHORT_IDENTIFIER, shortId); sanjoseMap.put(PlaceJAXBSchema.PLACE_TYPE, TEST_PLACE_TYPE); sanjoseMap.put(PlaceJAXBSchema.NOTE, TEST_NOTE); @@ -149,7 +148,7 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest taxonMap = new HashMap(); // Fields present in all authority records. - taxonMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); + taxonMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, shortId); // TODO Make term status be controlled vocab. taxonMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS); @@ -174,7 +184,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest { - private final String CLASS_NAME = VocabularyServiceTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // The class for logging + private final Logger logger = LoggerFactory.getLogger(VocabularyServiceTest.class); + // Instance variables specific to this test. final String SERVICE_PATH_COMPONENT = VocabularyClient.SERVICE_PATH_COMPONENT;//"vocabularies"; final String SERVICE_PAYLOAD_NAME = VocabularyClient.SERVICE_PAYLOAD_NAME; final String SERVICE_ITEM_PAYLOAD_NAME = VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME; + /** + * Default constructor. Used to set the short ID for all tests authority items + */ + VocabularyServiceTest() { + TEST_SHORTID = "vocabTest"; + } + @Override + protected String getTestAuthorityItemShortId() { + return getTestAuthorityItemShortId(true); // The short ID of every person item we create should be unique + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -72,11 +85,10 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest itemInfo = new HashMap(); - String shortId = createIdentifier(); itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId); result = VocabularyClientUtils.createItemInVocabulary(authorityId, @@ -109,7 +121,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest { /** The logger. */ - private final String CLASS_NAME = WorkAuthorityServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(WorkAuthorityServiceTest.class); + /** + * Default constructor. Used to set the short ID for all tests authority items + */ + WorkAuthorityServiceTest() { + TEST_SHORTID = "muppetstakemanhattan"; + } + @Override public String getServicePathComponent() { return WorkAuthorityClient.SERVICE_PATH_COMPONENT; @@ -77,13 +83,6 @@ public class WorkAuthorityServiceTest extends AbstractAuthorityServiceTest workMap = new HashMap(); // TODO Make work type and status be controlled vocabs. - workMap.put(WorkJAXBSchema.SHORT_IDENTIFIER, TEST_WORK_SHORT_IDENTIFIER); + workMap.put(WorkJAXBSchema.SHORT_IDENTIFIER, shortId); workMap.put(WorkJAXBSchema.WORK_TYPE, TEST_WORK_TYPE); workMap.put(WorkJAXBSchema.WORK_HISTORY_NOTE, TEST_WORK_HISTORY_NOTE); @@ -154,7 +152,7 @@ public class WorkAuthorityServiceTest extends AbstractAuthorityServiceTest