]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6937-A: More development of SAS related tests and test code refactoring.
authorRichard Millet <remillet@yahoo.com>
Tue, 26 Apr 2016 16:07:31 +0000 (09:07 -0700)
committerRichard Millet <remillet@yahoo.com>
Tue, 26 Apr 2016 16:07:31 +0000 (09:07 -0700)
services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

index c1312cd1d9b944c24c4c8e8aac88bca7b951108b..62e4d2e346015f92cb69cd150c44abb98796f779 100644 (file)
@@ -13,7 +13,6 @@ import org.collectionspace.services.client.AuthorityProxy;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.PayloadInputPart;
 import org.collectionspace.services.client.PayloadOutputPart;
-import org.collectionspace.services.client.PersonAuthorityClient;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.slf4j.Logger;
@@ -299,7 +298,6 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
         }
     }
 
-    
     /**
      * SAS - Create an item in the SAS authority on the SAS server.
      * @param testName
@@ -309,7 +307,8 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
         // Perform setup.
         setupCreate();
 
-        String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId);
+        String shortId = "SassyActor" + System.currentTimeMillis() + random.nextInt();; // short ID needs to be unique
+        String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
 
                // Store the ID returned from the first item resource created
         // for additional tests below.
@@ -319,6 +318,12 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
                 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
             }
         }
+        //
+        // Keep track of the SAS authority items we create, so we can delete them from
+        // the *local* authority after we perform a sync operation.  We need to keep track
+        // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
+        //
+        this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
     }
     
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
@@ -720,10 +725,11 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
             }
         }
         //
-        // Clean up authority items using the SAS client.
+        // Clean up authority items that were the result of a sync with the SAS
+        // all the IDs are URN (not CSIDs).  The URNs work for the local items as well
+        // as the SAS items.
         //
-        client = (AuthorityClient) this.getSASClientInstance();
-        for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
+        for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
             itemResourceId = entry.getKey();
             parentResourceId = entry.getValue();
             // Note: Any non-success responses from the delete operation
@@ -731,12 +737,23 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
             client.deleteItem(parentResourceId, itemResourceId).close();
         }
         //
-        // Call out superclass's cleanUp method to delete the SAS authorities
+        // Clean up authority items on the SAS using the SAS client.
         //
-        super.cleanUp(client);
+        client = (AuthorityClient) this.getSASClientInstance();
+        for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
+            itemResourceId = entry.getKey();
+            parentResourceId = entry.getValue();
+            client.deleteItem(parentResourceId, itemResourceId).close();
+        }
         //
         // Finally, call out superclass's cleanUp method to deleted the local authorities
         //
         super.cleanUp();
+        //
+        // Call out superclass's cleanUp method to delete the SAS authorities
+        //
+        super.cleanUp(client);        
     }
+    
+       abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);
 }
index 8dd3d4e78879beb454429bf31c8c7af689daefd6..137713f71e118b8d9bf6bba70039cf9d53b8ca3e 100644 (file)
@@ -99,7 +99,7 @@ public abstract class BaseServiceTest<CLT> {
     /* A runtime/command-line parameter to indicate if we should delete all the test related resource objects */
     static private final String NO_TEST_CLEANUP = "noTestCleanup";
     /* A random number generator */
-    static private final Random random = new Random(System.currentTimeMillis());
+    protected static final Random random = new Random(System.currentTimeMillis());
     
     
     /** The non-existent id. */
index ed8953990f5505805545076bba3f1471d6df6348..73b8bd5c2534ed3ab3a28bce9465b8f55d906d4e 100644 (file)
@@ -938,14 +938,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest<Orgaut
             // below are ignored and not reported.
             client.deleteContact(parentResourceId, itemResourceId, contactResourceId).close();
         }
-        // Clean up item resources.
-        for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
-            itemResourceId = entry.getKey();
-            parentResourceId = entry.getValue();
-            // Note: Any non-success responses from the delete operation
-            // below are ignored and not reported.
-            client.deleteItem(parentResourceId, itemResourceId).close();
-        }
+
         // Clean up parent resources.
         super.cleanUp();
 
index 29c3017916317f02887396de059b36a291f207a9..e3ce1442eb75911d46c865e8e2a2d4e1b9506294 100644 (file)
@@ -212,6 +212,12 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, terms, headerLabel);
     }
 
+    @Override
+    protected String createItemInAuthority(AuthorityClient client, String vcsid) {
+        String shortId = "johnWayneActor" + System.currentTimeMillis() + random.nextInt();; // short ID needs to be unique
+        return this.createItemInAuthority(client, vcsid, shortId);
+    }
+    
     /**
      * Creates an item in an authority, using test data.
      *
@@ -220,7 +226,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
      * @return the string
      */
     @Override
-    protected String createItemInAuthority(AuthorityClient client, String vcsid) {
+    protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId) {
 
         final String testName = "createItemInAuthority";
         if (logger.isDebugEnabled()) {
@@ -231,7 +237,6 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         //
         // Fill the property map
         //
-        String shortId = "johnWayneActor" + System.currentTimeMillis(); // short ID needs to be unique
         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
@@ -306,6 +311,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
             }
         }
+        
         if (logger.isDebugEnabled()) {
             logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")");
         }