From 0e3d3f8381ccde79b54cc36a384c6b0e176720c6 Mon Sep 17 00:00:00 2001 From: remillet Date: Thu, 28 Apr 2016 01:14:31 -0700 Subject: [PATCH] CSPACE-6937-A: Getting all XMLReplay tests working again. --- .../IntegrationTests/xmlreplay/XmlReplay.java | 26 +++++++++++++--- .../xmlreplay/XmlReplayTransport.java | 1 - .../import-locationitem-dollarsign.xml | 2 +- .../import-locationitem-varexpansion.xml | 2 +- .../import-locationitem-dollarsign.res.xml | 3 +- .../import-locationitem-varexpansion.res.xml | 2 +- .../vocabulary/res/GetVocabularyItems.res.xml | 1 - .../common/vocabulary/AuthorityResource.java | 11 +++++-- .../test/CitationAuthorityServiceTest.java | 3 +- .../services/client/AuthorityProxy.java | 2 +- .../test/AbstractAuthorityServiceTest.java | 31 ++++++++++++++++--- .../vocabulary/RefNameServiceUtils.java | 28 ++++++++++++----- .../test/ConceptAuthorityServiceTest.java | 3 +- .../client/test/LoanoutAuthRefsTest.java | 2 +- .../test/LocationAuthorityServiceTest.java | 3 +- .../test/MaterialAuthorityServiceTest.java | 3 +- .../client/test/MediaAuthRefsTest.java | 2 +- .../client/test/MovementAuthRefsTest.java | 5 ++- .../client/PersonAuthorityClientUtils.java | 2 +- .../test/PlaceAuthorityServiceTest.java | 3 +- .../test/TaxonomyAuthorityServiceTest.java | 3 +- .../client/test/VocabularyServiceTest.java | 6 ++-- .../client/test/WorkAuthorityServiceTest.java | 3 +- 23 files changed, 107 insertions(+), 40 deletions(-) diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java index 45d8c875a..7c042acb2 100644 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java @@ -28,6 +28,8 @@ public class XmlReplay { public static final String DEFAULT_CONTROL = "xml-replay-control.xml"; public static final String DEFAULT_MASTER_CONTROL = "xml-replay-master.xml"; public static final String DEFAULT_DEV_MASTER_CONTROL = "dev-master.xml"; + private static final int MAX_REATTEMPTS = 10; + private static final String REATTEMPT_KEY = "REATTEMPT_KEY"; private String reportsDir = ""; public String getReportsDir(){ @@ -228,7 +230,7 @@ public class XmlReplay { } public List autoDelete(String logName){ - return autoDelete(this.serviceResultsMap, logName); + return autoDelete(this.serviceResultsMap, logName, 0); } /** Use this method to clean up resources created on the server that returned CSIDs, if you have @@ -236,12 +238,17 @@ public class XmlReplay { * @param serviceResultsMap a Map of ServiceResult objects, which will contain ServiceResult.deleteURL. * @return a List of debug info about which URLs could not be deleted. */ - public static List autoDelete(Map serviceResultsMap, String logName){ + private static List autoDelete(Map serviceResultsMap, String logName, int reattempt) { List results = new ArrayList(); - for (ServiceResult pr : serviceResultsMap.values()){ + HashMap reattemptList = new HashMap(); + int deleteFailures = 0; + for (ServiceResult pr : serviceResultsMap.values()) { try { if (Tools.notEmpty(pr.deleteURL)){ ServiceResult deleteResult = XmlReplayTransport.doDELETE(pr.deleteURL, pr.auth, pr.testID, "[autodelete:"+logName+"]"); + if (deleteResult.gotExpectedResult() == false || deleteResult.responseCode != 200) { + reattemptList.put(REATTEMPT_KEY + deleteFailures++, pr); // We need to try again after our dependents have been deleted. cow() + } results.add(deleteResult); } else { ServiceResult errorResult = new ServiceResult(); @@ -263,6 +270,15 @@ public class XmlReplay { results.add(errorResult); } } + // + // If there were things we had trouble deleting, it might have been because they had dependents that + // needed to be deleted first. Therefore, we're going to try again and again (recursively) up until we reach + // our MAX_REATTEMPTS limit. + // + if (reattemptList.size() > 0 && reattempt < MAX_REATTEMPTS) { + return autoDelete(reattemptList, logName, ++reattempt); // recursive call + } + return results; } @@ -716,8 +732,8 @@ public class XmlReplay { results.add(serviceResult); } } - if (Tools.isTrue(autoDeletePOSTS)&¶m_autoDeletePOSTS){ - autoDelete(serviceResultsMap, "default"); + if (Tools.isTrue(autoDeletePOSTS) && param_autoDeletePOSTS){ + autoDelete(serviceResultsMap, "default", 0); } } diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java index 3d52e1793..0cf0cd4d3 100644 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java @@ -37,7 +37,6 @@ import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-dollarsign.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-dollarsign.xml index 1f926ec70..96f63e6c7 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-dollarsign.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-dollarsign.xml @@ -9,7 +9,7 @@ ${shortIdentifierValue} - urn:cspace:core.collectionspace.org:locationauthorities:name(${shortIdentifierValue})'${termDisplayNameValue}' + urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${shortIdentifierValue})'${termDisplayNameValue}' ${inAuthorityValue} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-varexpansion.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-varexpansion.xml index 245260973..128ddbd7c 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-varexpansion.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/import-locationitem-varexpansion.xml @@ -16,7 +16,7 @@ ${shortIdentifierValue} - urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding' + urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${shortIdentifierValue})'Wattford & Gump Outbuilding' ${inAuthorityValue} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-dollarsign.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-dollarsign.res.xml index 5c5e75427..4cf123d69 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-dollarsign.res.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-dollarsign.res.xml @@ -15,7 +15,8 @@ 1 ${uriValue} - urn:cspace:core.collectionspace.org:locationauthorities:name(${shortIdentifierValue})'${termDisplayNameValue}' + urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${importLocationItemWithDollarSignInRefName.shortIdentifierValue})'${termDisplayNameValue}' + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-varexpansion.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-varexpansion.res.xml index 3fd8879fe..98ad6b3e9 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-varexpansion.res.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/imports/res/import-locationitem-varexpansion.res.xml @@ -22,7 +22,7 @@ 1 ${uriValue} - urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding' + urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${importLocationItemWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding' diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml index 6b20dc881..5c2866b06 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml @@ -6,7 +6,6 @@ 0 3 3 - csid|uri|refName|updatedAt|workflowState|rev|order|termStatus|displayName|shortIdentifier ${Item1.displayName} ${Item1.itemID} diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index a50bc4f03..9ed8ab264 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -1324,7 +1324,8 @@ public abstract class AuthorityResource * @param itemIdentifier * @throws Exception */ - public void deleteAuthorityItem(ServiceContext existingCtx, + @SuppressWarnings("rawtypes") + public void deleteAuthorityItem(ServiceContext existingCtx, String parentIdentifier, String itemIdentifier, boolean shouldUpdateRevNumber @@ -1337,7 +1338,13 @@ public abstract class AuthorityResource ctx.setProperties(existingCtx.getProperties()); } - String parentcsid = lookupParentCSID(ctx, parentIdentifier, "deleteAuthorityItem(parent)", "DELETE_ITEM", null); + String parentcsid = null; + try { + parentcsid = lookupParentCSID(ctx, parentIdentifier, "deleteAuthorityItem(parent)", "DELETE_ITEM", null); + } catch (DocumentNotFoundException de) { + logger.warn(String.format("Could not find parent with ID='%s' when trying to delete item ID='%s'", + parentIdentifier, itemIdentifier)); + } String itemCsid = lookupItemCSID(ctx, itemIdentifier, parentcsid, "deleteAuthorityItem(item)", "DELETE_ITEM"); //use itemServiceCtx if it is not null DocumentHandler handler = createDocumentHandler(ctx); 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 d9b7c60e3..656dde424 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 @@ -68,7 +68,8 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); - personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + random.nextInt(1000)); // avoid short ID conflicts with pass test session records that never got cleaned up List personTerms = new ArrayList(); PersonTermGroup term = new PersonTermGroup(); String termName = firstName + " " + surName; diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index 81a27275d..03df14293 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -66,7 +66,8 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); - personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + random.nextInt(1000)); List personTerms = new ArrayList(); PersonTermGroup term = new PersonTermGroup(); String termName = firstName + " " + surName; diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java index fa3e9a1a5..5eb255909 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java @@ -118,8 +118,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { // references, and will refer to Person resources by their refNames. MovementClient movementClient = new MovementClient(); PoxPayloadOut multipart = createMovementInstance( - "movementReferenceNumber-" + identifier, - GregorianCalendarDateTimeUtils.timestampUTC(), + "movementReferenceNumber-" + identifier, GregorianCalendarDateTimeUtils.timestampUTC(), movementContactRefName); String newId = null; Response res = movementClient.create(multipart); @@ -190,7 +189,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); - personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + Math.abs(random.nextInt())); List personTerms = new ArrayList(); PersonTermGroup term = new PersonTermGroup(); String termName = firstName + " " + surName; diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index a2b36d094..61e9549bd 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -139,7 +139,7 @@ public class PersonAuthorityClientUtils { String displayName, String shortIdentifier, String headerLabel ) { PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon(); personAuthority.setDisplayName(displayName); - personAuthority.setShortIdentifier(shortIdentifier); + personAuthority.setShortIdentifier(shortIdentifier + random.nextInt(10000)); //String refName = createPersonAuthRefName(shortIdentifier, displayName); //personAuthority.setRefName(refName); personAuthority.setVocabType("PersonAuthority"); 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 42d9d4efa..c7d66a88b 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 @@ -65,7 +65,8 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest