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(){
}
public List<ServiceResult> 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
* @param serviceResultsMap a Map of ServiceResult objects, which will contain ServiceResult.deleteURL.
* @return a List<String> of debug info about which URLs could not be deleted.
*/
- public static List<ServiceResult> autoDelete(Map<String, ServiceResult> serviceResultsMap, String logName){
+ private static List<ServiceResult> autoDelete(Map<String, ServiceResult> serviceResultsMap, String logName, int reattempt) {
List<ServiceResult> results = new ArrayList<ServiceResult>();
- for (ServiceResult pr : serviceResultsMap.values()){
+ HashMap<String, ServiceResult> reattemptList = new HashMap<String, ServiceResult>();
+ 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();
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;
}
results.add(serviceResult);
}
}
- if (Tools.isTrue(autoDeletePOSTS)&¶m_autoDeletePOSTS){
- autoDelete(serviceResultsMap, "default");
+ if (Tools.isTrue(autoDeletePOSTS) && param_autoDeletePOSTS){
+ autoDelete(serviceResultsMap, "default", 0);
}
}
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
</locTermGroup>
</locTermGroupList>
<shortIdentifier>${shortIdentifierValue}</shortIdentifier>
- <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${shortIdentifierValue})'${termDisplayNameValue}'</refName>
+ <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${shortIdentifierValue})'${termDisplayNameValue}'</refName>
<inAuthority>${inAuthorityValue}</inAuthority>
</schema>
</import>
</locTermGroup>
</locTermGroupList>
<shortIdentifier>${shortIdentifierValue}</shortIdentifier>
- <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding'</refName>
+ <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${shortIdentifierValue})'Wattford & Gump Outbuilding'</refName>
<inAuthority>${inAuthorityValue}</inAuthority>
</schema>
</import>
<!-- Note: This test may fail if the identifier for the core tenant changes. -->
<tenantId>1</tenantId>
<uri>${uriValue}</uri>
- <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${shortIdentifierValue})'${termDisplayNameValue}'</refName>
+ <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${importLocationItemWithDollarSignInRefName.shortIdentifierValue})'${termDisplayNameValue}'</refName>
+
</ns2:collectionspace_core>
</document>
<!-- Note: This test may fail if the identifier for the core tenant changes. -->
<tenantId>1</tenantId>
<uri>${uriValue}</uri>
- <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding'</refName>
+ <refName>urn:cspace:core.collectionspace.org:locationauthorities:name(${importLocationAuthorityWithVarExpansion.shortIdentifierValue}):item:name(${importLocationItemWithVarExpansion.shortIdentifierValue})'Wattford & Gump Outbuilding'</refName>
</ns2:collectionspace_core>
</document>
<pageNum>0</pageNum>
<itemsInPage>3</itemsInPage>
<totalItems>3</totalItems>
- <fieldsReturned>csid|uri|refName|updatedAt|workflowState|rev|order|termStatus|displayName|shortIdentifier</fieldsReturned>
<list-item>
<displayName>${Item1.displayName}</displayName>
<shortIdentifier>${Item1.itemID}</shortIdentifier>
* @param itemIdentifier
* @throws Exception
*/
- public void deleteAuthorityItem(ServiceContext existingCtx,
+ @SuppressWarnings("rawtypes")
+ public void deleteAuthorityItem(ServiceContext existingCtx,
String parentIdentifier,
String itemIdentifier,
boolean shouldUpdateRevNumber
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<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- CitationAuthorityServiceTest() {
+ public CitationAuthorityServiceTest() {
+ super();
TEST_SHORTID = "citation1";
}
// Sync by name or CSID
@GET
@Path("/{identifier}/sync")
- public Response sync(String identifier);
+ public Response sync(@PathParam("identifier") String identifier);
/*
* READ/GET Methods
private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
protected String knownResourceShortIdentifer = null;
- protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems";
+ protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems" + random.nextInt(1000);
protected String knownAuthorityWithItems = null;
protected static final String SAS_IDENTIFIER = "SAS";
*/
protected String getSASAuthorityIdentifier() {
// TODO Auto-generated method stub
- return this.getKnowResourceIdentifier() + this.SAS_IDENTIFIER;
+ return this.getKnowResourceIdentifier() + SAS_IDENTIFIER;
}
/**
@Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
public void syncWithSAS(String testName) {
//
- // First create an empty instance of the authority, so we can sync items with it. We're
- // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
+ // First check to see if the authority supports synchronization.
//
AuthorityClient client = (AuthorityClient) this.getClientInstance();
+ if (client.supportsSync() == false) {
+ return; // Exit the test since this authority doesn't support synchronization
+ }
+
+ //
+ // Create an empty instance of the authority, so we can sync items with it. We're
+ // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
+ //
String localAuthorityId = null;
try {
localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
*/
@Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
public void createSASAuthority(String testName) {
+ //
+ // First check to see if the authority supports synchronization.
+ //
+ AuthorityClient client = (AuthorityClient) this.getClientInstance();
+ if (client.supportsSync() == false) {
+ return; // Exit the test since this authority doesn't support synchronization
+ }
+
// Perform setup.
setupCreate();
*/
@Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
public void createSASItem(String testName) {
+ //
+ // First check to see if the authority supports synchronization.
+ //
+ AuthorityClient client = (AuthorityClient) this.getClientInstance();
+ if (client.supportsSync() == false) {
+ return; // Exit the test since this authority doesn't support synchronization
+ }
+
// Perform setup.
setupCreate();
+ "='" + name + "'";
}
- public static String buildWhereForAuthItemByName(String authorityItemCommonSchemaName, String name, String parentcsid) {
- return authorityItemCommonSchemaName
- + ":" + AuthorityItemJAXBSchema.SHORT_IDENTIFIER
- + "='" + name + "' AND "
- + authorityItemCommonSchemaName + ":"
- + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" // parent value must be a CSID, not a URN short ID form
- + "'" + parentcsid + "'";
+ /**
+ * Build an NXQL query for finding an item by its short ID
+ *
+ * @param authorityItemCommonSchemaName
+ * @param shortId
+ * @param parentcsid
+ * @return
+ */
+ public static String buildWhereForAuthItemByName(String authorityItemCommonSchemaName, String shortId, String parentcsid) {
+ String result = null;
+
+ result = String.format("%s:%s='%s'", authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId);
+ //
+ // Technically, we don't need the parent CSID since the short ID is unique so it can be null
+ //
+ if (parentcsid != null) {
+ result = String.format("%s AND %s:%s='%s'",
+ result, authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY, parentcsid);
+ }
+
+ return result;
}
/*
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- ConceptAuthorityServiceTest() {
+ public ConceptAuthorityServiceTest() {
+ super();
TEST_SHORTID = "concept1";
}
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);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + random.nextInt(1000)); // avoid short ID conflicts with pass test session records that never got cleaned up
List<PersonTermGroup> personTerms = new ArrayList<PersonTermGroup>();
PersonTermGroup term = new PersonTermGroup();
String termName = firstName + " " + surName;
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- LocationAuthorityServiceTest() {
+ public LocationAuthorityServiceTest() {
+ super();
TEST_SHORTID = "shelf1";
}
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- MaterialAuthorityServiceTest() {
+ public MaterialAuthorityServiceTest() {
+ super();
TEST_SHORTID = "superglass";
}
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);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + random.nextInt(1000));
List<PersonTermGroup> personTerms = new ArrayList<PersonTermGroup>();
PersonTermGroup term = new PersonTermGroup();
String termName = firstName + " " + surName;
// 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);
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);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId + Math.abs(random.nextInt()));
List<PersonTermGroup> personTerms = new ArrayList<PersonTermGroup>();
PersonTermGroup term = new PersonTermGroup();
String termName = firstName + " " + surName;
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");
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- PlaceAuthorityServiceTest() {
+ public PlaceAuthorityServiceTest() {
+ super();
TEST_SHORTID = "sanjose";
}
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- TaxonomyAuthorityServiceTest() {
+ public TaxonomyAuthorityServiceTest() {
+ super();
TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
}
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- VocabularyServiceTest() {
+ public VocabularyServiceTest() {
+ super();
TEST_SHORTID = "vocabTest";
}
testSetup(STATUS_CREATED, ServiceRequestType.CREATE);
// Create a new vocabulary
+ String shortId = "nonunique" + random.nextInt(1000); // Prevent collisions with past test sessions that never cleaned up properly
VocabularyClient client = new VocabularyClient();
PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
- "Vocab with non-unique Short Id", "nonunique", client.getCommonPartName());
+ "Vocab with non-unique Short Id", shortId, client.getCommonPartName());
Response res = client.create(multipart);
try {
assertStatusCode(res, testName);
/**
* Default constructor. Used to set the short ID for all tests authority items
*/
- WorkAuthorityServiceTest() {
+ public WorkAuthorityServiceTest() {
+ super();
TEST_SHORTID = "muppetstakemanhattan";
}