]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6965: Added tests to check workflow state changes for the cs_replicating workf...
authorremillet <remillet@yahoo.com>
Wed, 29 Jun 2016 04:06:57 +0000 (21:06 -0700)
committerremillet <remillet@yahoo.com>
Wed, 29 Jun 2016 04:06:57 +0000 (21:06 -0700)
services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index 38e534d23e20be986388150e4e6e54d51ea51e64..5f65c036cc48c582a3d40765fe3f11541a2044ab 100644 (file)
@@ -349,7 +349,6 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
     public void createItem(String testName) throws Exception {
         // Perform setup.
         setupCreate();
-
         String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId());
 
         // Store the ID returned from the first item resource created
@@ -361,6 +360,28 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
             }
         }
     }
+       
+       @Test(dataProvider = "testName", dependsOnMethods = {"readItem", "CRUDTests"})
+    public void checkAuthorityWorkflowTransitions(String testName) throws Exception {
+        //
+        // First check to see if the authority supports synchronization -i.e., the "cs_replicating" lifecycle policy.
+        //
+       assertSupportsSync();
+               
+        String itemCsid = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId() + testName);
+        // Add workflow states
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE, WorkflowClient.WORKFLOWSTATE_REPLICATED);
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_DEPRECATE, WorkflowClient.WORKFLOWSTATE_REPLICATED_DEPRECATED);
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_DELETE, WorkflowClient.WORKFLOWSTATE_REPLICATED_DEPRECATED_DELETED);
+        // Substract workflow states
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_UNREPLICATE, WorkflowClient.WORKFLOWSTATE_DEPRECATED_DELETED);
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_UNDELETE, WorkflowClient.WORKFLOWSTATE_DEPRECATED);
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_UNDEPRECATE, WorkflowClient.WORKFLOWSTATE_PROJECT);
+        // Add other workflow states
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_DELETE, WorkflowClient.WORKFLOWSTATE_DELETED);
+        updateItemLifeCycleState(testName, knownResourceId, itemCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE, WorkflowClient.WORKFLOWSTATE_REPLICATED_DELETED);
+    }
+
     
     /**
      * Verify that we can test synchronization with this authority.  Otherwise, we skip the test.
index 182af836303c5d0d68f42f1cd0b299da5f69e61f..5854b3f27944a3bf85cdebc6522ee4da720ab10e 100644 (file)
@@ -902,7 +902,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
     
 
     @SuppressWarnings("rawtypes")
-    protected void updateLifeCycleState(String testName, String resourceId, String workflowTransition, String lifeCycleState) throws Exception {
+    protected void updateLifeCycleState(String testName, String resourceId, String workflowTransition, String expectedLifeCycleState) throws Exception {
         //
         // Read the existing object
         //
@@ -924,7 +924,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         // Mark it for a soft delete.
         //
         logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
-        workflowCommons.setCurrentLifeCycleState(lifeCycleState);
+        workflowCommons.setCurrentLifeCycleState(expectedLifeCycleState);
         PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
         PayloadOutputPart commonPart = output.addPart(WorkflowClient.SERVICE_COMMONPART_NAME, workflowCommons);
         //
@@ -955,8 +955,8 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
                        updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
                        Assert.assertNotNull(workflowCommons);
                        String currentWorkflowState = updatedWorkflowCommons.getCurrentLifeCycleState();
-                       if (currentWorkflowState.equalsIgnoreCase(lifeCycleState)) {
-                               logger.debug("Expected workflow state found: " + lifeCycleState);
+                       if (currentWorkflowState.equalsIgnoreCase(expectedLifeCycleState)) {
+                               logger.debug("Expected workflow state found: " + expectedLifeCycleState);
                                break;
                        }
                } finally {
@@ -969,7 +969,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         //
         // Finally, assert the state change happened as expected.
         //
-        Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);
+        Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), expectedLifeCycleState);
     }
 
     private CollectionSpacePoxClient assertPoxClient() throws Exception {
@@ -1179,7 +1179,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         }
     }
 
-    protected void updateItemLifeCycleState(String testName, String parentCsid, String itemCsid, String workflowTransition, String lifeCycleState) throws Exception {
+    protected String updateItemLifeCycleState(String testName, String parentCsid, String itemCsid, String workflowTransition, String expectedLifeCycleState) throws Exception {
         //
         // Read the existing object
         //
@@ -1187,6 +1187,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         Response res = client.readItemWorkflow(parentCsid, itemCsid);
         WorkflowCommon workflowCommons = null;
         try {
+               setupRead();
                assertStatusCode(res, testName);
                logger.debug("Got object to update life cycle state with ID: " + itemCsid);
                PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
@@ -1201,7 +1202,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         //
         // Mark it for a state change.
         //
-        workflowCommons.setCurrentLifeCycleState(lifeCycleState);
+        workflowCommons.setCurrentLifeCycleState(expectedLifeCycleState);
         PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
         PayloadOutputPart commonPart = output.addPart(WorkflowClient.SERVICE_COMMONPART_NAME, workflowCommons);
         //
@@ -1210,6 +1211,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         res = client.updateItemWorkflowWithTransition(parentCsid, itemCsid, workflowTransition);
         WorkflowCommon updatedWorkflowCommons = null;
         try {
+               setupUpdate();
                assertStatusCode(res, testName);
                PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
                updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
@@ -1222,6 +1224,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         
         int trials = 0;
         boolean passed = false;
+        setupRead();
         while (trials < 30) { //wait to see if the lifecycle transition will happen
                //
                // Read the updated object and make sure it was updated correctly.
@@ -1235,8 +1238,8 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
                        updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
                        Assert.assertNotNull(workflowCommons);
                        String currentState = updatedWorkflowCommons.getCurrentLifeCycleState();
-                       if (currentState.equalsIgnoreCase(lifeCycleState)) {
-                               logger.debug("Expected workflow state found: " + lifeCycleState);
+                       if (currentState.equalsIgnoreCase(expectedLifeCycleState)) {
+                               logger.debug("Expected workflow state found: " + expectedLifeCycleState);
                                break;
                        }
                        logger.debug("Workflow state not yet updated for object with id: " + itemCsid + " state is=" +
@@ -1251,7 +1254,8 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
         //
         // Finally check to see if the state change was updated as expected.
         //
-        Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);
+        Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), expectedLifeCycleState);
+        return updatedWorkflowCommons.getCurrentLifeCycleState();
     }
 }
 
index 67153aeba8f45d3a6176d50cca954613eefacf35..324601e2f470ead9378873ceec985a8adf96cdbc 100644 (file)
@@ -54,7 +54,7 @@ import org.collectionspace.services.lifecycle.TransitionDefList;
 import org.collectionspace.services.lifecycle.TransitionList;
 import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
-import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentFilter;
+
 import org.dom4j.Document;
 import org.dom4j.io.SAXReader;
 import org.mortbay.log.Log;