]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6937-A: More development of SAS related tests and test code refactoring.
authorremillet <remillet@yahoo.com>
Tue, 26 Apr 2016 02:42:43 +0000 (19:42 -0700)
committerremillet <remillet@yahoo.com>
Tue, 26 Apr 2016 02:42:43 +0000 (19:42 -0700)
14 files changed:
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityServiceUtils.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
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/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/ServiceRequestType.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

index 498e979080865da7c898250df99a3c550d3092ab..3a92dfa9c46f57fd4949f146845a4231f64538c9 100644 (file)
@@ -6,6 +6,7 @@ import java.util.regex.Pattern;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
@@ -43,10 +44,19 @@ public class AuthorityServiceUtils {
 
     public static final Boolean NO_CHANGE = null;
 
+    /**
+     * Make a request to the SAS Server for an authority payload.
+     * 
+     * @param ctx
+     * @param specifier
+     * @param responseType
+     * @return
+     * @throws Exception
+     */
     static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception {
        PoxPayloadIn result = null;
        
-        AuthorityClient client = (AuthorityClient) ctx.getClient();
+        AuthorityClient client = (AuthorityClient) ctx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
         Response res = client.read(specifier.getURNValue());
         try {
                int statusCode = res.getStatus();
@@ -72,7 +82,7 @@ public class AuthorityServiceUtils {
        PoxPayloadIn result = null;
        
        ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName);
-        AuthorityClient client = (AuthorityClient) parentCtx.getClient();
+        AuthorityClient client = (AuthorityClient) parentCtx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
         Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue());
         try {
                int statusCode = res.getStatus();
index e9d2427df1209d0f75913774bbc895cff5e83b74..58af1e5a5a36857094eb3da325c0f6f99f928aef 100644 (file)
@@ -489,7 +489,15 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
        */
        
     }    
-        
+    
+    /**
+     * Request an authority item list payload from the SAS server.
+     * 
+     * @param ctx
+     * @param specifier
+     * @return
+     * @throws Exception
+     */
     private PoxPayloadIn requestPayloadInItemList(ServiceContext ctx, Specifier specifier) throws Exception {
        PoxPayloadIn result = null;
        
index d72a9d854778a21cbbdccb0b9691391c3c008afd..5a1191c70f79a370d6a660cbe9dfb53ac159ee51 100644 (file)
@@ -144,8 +144,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
      * @throws Exception 
      */
     public AbstractServiceClientImpl(String propertiesFileName) {
-        readClientProperties(propertiesFileName);
-        init();
+        setClientProperties(propertiesFileName);
     }
     
     /**
@@ -154,7 +153,6 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
      */
     public AbstractServiceClientImpl(Properties properties) {
         setClientProperties(properties);
-        init();
     }
     
     /**
@@ -165,8 +163,14 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
        if (this.properties.isEmpty() == true) {
                throw new RuntimeException("Client connection properties are empty.  Cannot proceed.");
        }
-        setupHttpClient();
-        setupHttpClient4(); // temp fix for CSPACE-6281
+       
+       try {
+               setupHttpClient();
+               setupHttpClient4(); // temp fix for CSPACE-6281
+       } catch (Exception e) {
+               throw new RuntimeException(e.getMessage());
+       }
+       
         ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
         RegisterBuiltin.register(factory);
         setProxy();        
@@ -332,7 +336,8 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
      *
      * @exception RuntimeException
      */
-    protected void readClientProperties(String clientPropertiesFilename) {
+    @Override
+    public void setClientProperties(String clientPropertiesFilename) {
        Properties inProperties = new Properties();
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         InputStream is = null;
@@ -364,7 +369,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
      * @throws Exception 
      */
     protected void setClientProperties(Properties inProperties) {
-        properties.putAll(inProperties);
+        properties = inProperties;
         
         if (logger.isDebugEnabled()) {
                System.getenv();
@@ -411,15 +416,21 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
         if (logger.isDebugEnabled()) {
             printProperties();
         }
+        //
+        // How use the properties to initialize the HTTP client
+        //
+        init();
     }    
 
     /**
      * setupHttpClient sets up HTTP client for the service client the setup
      * process relies on the following properties URL_PROPERTY USER_PROPERTY
      * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY
+     * 
+     * @throws Exception 
      */
     @Override
-    public void setupHttpClient() {
+    public void setupHttpClient() throws Exception {
        try {
                this.httpClient = new HttpClient();
                if (useAuth()) {
@@ -445,7 +456,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
                    }
                }
        } catch (Throwable e) {
-               e.printStackTrace();
+               throw new Exception("Could not setup an HTTP client as requested with ", e);
        }
     }
     
@@ -453,7 +464,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
      * This is a temp fix for RESTEasy upgrade in CSPACE-6281.  The long-term solution will be to use
      * the non-deprecated approach per the RESTEasy documentation.
      */
-    public void setupHttpClient4() {
+    public void setupHttpClient4() throws Exception {
        try {
                this.httpClient4 = new DefaultHttpClient();
                if (useAuth()) {
@@ -479,7 +490,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
                    }
                }
        } catch (Throwable e) {
-               e.printStackTrace();
+               throw new Exception("Could not setup an HTTP client as requested with ", e);
        }
     }    
 
@@ -556,8 +567,14 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
         } else {
             removeProperty(CollectionSpaceClient.AUTH_PROPERTY);
         }
-        setupHttpClient();
-        setupHttpClient(); // temp fix for CSPACE-6281
+        
+        try {
+               setupHttpClient();
+               setupHttpClient(); // temp fix for CSPACE-6281
+        } catch (Exception e) {
+               throw new RuntimeException(e.getMessage());
+        }
+        
         setProxy();
     }
     
index f492bdd9c02afbbe40f359fb4c81983440f08c47..a55aadd46b8a71e157b6073173b578ba065fd543 100644 (file)
@@ -1,8 +1,9 @@
 package org.collectionspace.services.client;
 
+import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
-import org.jboss.resteasy.client.ClientResponse;
 
+import org.jboss.resteasy.client.ClientResponse;
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
@@ -61,7 +62,13 @@ public interface AuthorityClient<AUTHORITY_ITEM_TYPE, P extends AuthorityProxy>
     public Response getItemAuthorityRefs(String parentcsid, String itemcsid);    
     
     /*
-     * 
+     * Synchronization methods
+     */
+    Response syncByName(String name);
+
+    
+    /*
+     * READ/GET by name method
      */
     
     Response readByName(String name);
index faa4fe75023a36e432a37ebe1f0e249ef704be7f..903c76f83017cb3880f113e6a8f3607f2981a5a8 100644 (file)
@@ -1,5 +1,6 @@
 package org.collectionspace.services.client;
 
+import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
 
 import org.jboss.resteasy.client.ClientResponse;
@@ -76,6 +77,13 @@ public abstract class AuthorityClientImpl<AUTHORITY_ITEM_TYPE, P extends Authori
         return getProxy().getItemAuthorityRefs(parentcsid, csid);
     }
     
+    /*
+     * Synchronization method
+     */
+    public Response syncByName(String name) {
+       return getProxy().syncByName(name);
+    }
+
     /*
      * 
      */
index f541478d2cb2fc123e19b7af384850e6819d976a..4102d548f2bbb90c73c519d1e02b8a7448603ff6 100644 (file)
@@ -75,7 +75,16 @@ public interface AuthorityProxy extends CollectionSpaceCommonListPoxProxy {
             @PathParam("itemcsid") String itemcsid);
     
     /*
-     * 
+     * Synchronization methods
+     */
+    
+    // Sync by name
+    @GET
+    @Path("/urn:cspace:name({name})/sync")
+    Response syncByName(@PathParam("name") String name);
+    
+    /*
+     * READ/GET Methods
      */
     
     //(R)ead by name
index 702605f1e159b63fce070c9e97c4cdc7a8ab0595..e56deba46d3cd87edea4d65d41eac1b19d7ec8d2 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
+
 import org.apache.commons.httpclient.HttpClient;
 import org.jboss.resteasy.client.ClientResponse;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
@@ -134,8 +135,9 @@ public interface CollectionSpaceClient<CLT, REQUEST_TYPE, RESPONSE_TYPE, P exten
      * PASSWORD_PROPERTY
      * AUTH_PROPERTY
      * SSL_PROPERTY
+     * @throws Exception 
      */
-    void setupHttpClient();
+    void setupHttpClient() throws Exception;
 
     /**
      * setProxy for the client
@@ -237,4 +239,11 @@ public interface CollectionSpaceClient<CLT, REQUEST_TYPE, RESPONSE_TYPE, P exten
      * @return the client response
      */
     public Response delete(String csid);
+
+    /**
+     * Uses a properties files to set the url and credentials for an HTTP connection.
+     * 
+     * @param clientPropertiesFilename
+     */
+       public void setClientProperties(String clientPropertiesFilename);
 }
index 141f96018137b83117148ffd4ccad4a94361487d..c1312cd1d9b944c24c4c8e8aac88bca7b951108b 100644 (file)
@@ -1,6 +1,8 @@
 package org.collectionspace.services.client.test;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
@@ -11,9 +13,9 @@ 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;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
@@ -38,6 +40,11 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
        protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems"; 
        protected String knownAuthorityWithItems = null;
        
+       protected static final String SAS_IDENTIFIER = "SAS"; 
+       protected String knownSASAuthorityResourceId = null;
+       protected String knownSASItemResourceId = null;
+       protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
+
        protected String knownResourceRefName = null;
     protected String knownItemResourceId = null;
     protected String knownItemResourceShortIdentifer = null;    
@@ -61,6 +68,24 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
         knownResourceRefName = refName;
     }
 
+       protected String getSASAuthorityIdentifier() {
+               // TODO Auto-generated method stub
+               return this.getKnowResourceIdentifier() + this.SAS_IDENTIFIER;
+       }
+    
+       protected String getUrnIdentifier(String shortId) {
+               return String.format("urn:cspace:name:(%s)", shortId);
+       }
+       
+    /**
+     * Sets up create tests.
+     */
+    protected void setupSync() {
+        testExpectedStatusCode = this.STATUS_OK;
+        testRequestType = ServiceRequestType.SYNC;
+        testSetup(testExpectedStatusCode, testRequestType);
+    }
+    
     /**
      * Gets a client to the SAS (Shared Authority Server)
      *
@@ -201,8 +226,7 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
        }
     }
     
-    @Test(dataProvider = "testName",
-               dependsOnMethods = {"CRUDTests"})
+    @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
     public void createItem(String testName) {
         // Perform setup.
         setupCreate();
@@ -220,23 +244,79 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
     }
     
     /**
-     * SAS - Create an item on the SAS server.
+     * Sync the local with the SAS
+     */
+    @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
+    public void syncWithSAS(String testName) {
+        setupSync();
+       AuthorityClient client = (AuthorityClient) this.getClientInstance();
+
+        //
+        // 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.
+        //
+       String localAuthorityId = null;
+        try {
+                       localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
+               } catch (Exception e) {
+                       Assert.assertNotNull(localAuthorityId);
+               }
+
+       //
+       // Now we can try to sync the SAS authority with the local one we just created.
+       //
+       Response response = client.syncByName(getSASAuthorityIdentifier()); // Notice we're using the Short ID (short ID is the same on the local and SAS)
+        try {
+               int statusCode = response.getStatus();
+               if (logger.isDebugEnabled()) {
+                   logger.debug(testName + ": HTTP status = " + statusCode);
+               }
+               Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+                       invalidStatusCodeMessage(testRequestType, statusCode));
+               Assert.assertEquals(statusCode, testExpectedStatusCode);
+        } finally {
+               response.close();
+        }
+    }
+    
+    /**
+     * SAS - Create a new authority on the SAS server.
+     * @param testName
+     */    
+    @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
+    public void createSASAuthority(String testName) {
+        // Perform setup.
+        setupCreate();
+
+        try {
+               String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier());
+               knownSASAuthorityResourceId = newID;
+            if (logger.isDebugEnabled()) {
+               String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
+            }
+        } catch (Exception e) {
+               logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
+        }
+    }
+
+    
+    /**
+     * SAS - Create an item in the SAS authority on the SAS server.
      * @param testName
      */
-    @Test(dataProvider = "testName",
-               dependsOnMethods = {"CRUDTests"})
+    @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
     public void createSASItem(String testName) {
         // Perform setup.
         setupCreate();
 
-        String newID = createItemInAuthority(getSASClientInstance(), knownResourceId);
+        String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId);
 
-        // Store the ID returned from the first item resource created
+               // Store the ID returned from the first item resource created
         // for additional tests below.
-        if (knownItemResourceId == null) {
-            knownItemResourceId = newID;
+        if (knownSASItemResourceId == null) {
+               knownSASItemResourceId = newID;
             if (null != testName && logger.isDebugEnabled()) {
-                logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
+                logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
             }
         }
     }
@@ -263,8 +343,7 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
         setupRead();
 
         // Submit the request to the service and store the response.
-        AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
-                       (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
+        AuthorityClient client = (AuthorityClient) this.getClientInstance();
         Response res = client.readByName(getKnowResourceIdentifier());
         try {
                int statusCode = res.getStatus();
@@ -609,5 +688,55 @@ public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHOR
        public void CRUDTests(String testName) {
                // TODO Auto-generated method stub
        }
-    
+        
+    @Override
+    public void cleanUp() {
+        String noTest = System.getProperty("noTestCleanup");
+        if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Skipping Cleanup phase ...");
+            }
+            return;
+        }
+        
+        AuthorityClient client = (AuthorityClient) this.getClientInstance();
+        String parentResourceId;
+        String itemResourceId;
+        //
+        // Clean up all authority item resources.
+        //
+        for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
+            itemResourceId = entry.getKey();
+            parentResourceId = entry.getValue();
+            Response response = client.deleteItem(parentResourceId, itemResourceId);
+            try {
+               int status = response.getStatus();
+               if (status != Response.Status.OK.getStatusCode()) {
+                       logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
+                                       itemResourceId, parentResourceId));
+               }
+            } finally {
+               response.close();
+            }
+        }
+        //
+        // Clean up authority items using the SAS client.
+        //
+        client = (AuthorityClient) this.getSASClientInstance();
+        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();
+        }
+        //
+        // Call out superclass's cleanUp method to delete the SAS authorities
+        //
+        super.cleanUp(client);
+        //
+        // Finally, call out superclass's cleanUp method to deleted the local authorities
+        //
+        super.cleanUp();
+    }
 }
index 6026fe55cb2af543c7e4c8bbf93118c5d2882557..f38701f5133e8cbe433a0c05052cc8cfd8216f6b 100644 (file)
@@ -155,8 +155,16 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
     protected String createResource(String testName, String identifier) throws Exception {
         String result = null;
         
-       setupCreate();
        CollectionSpaceClient client = this.getClientInstance();
+        result = createResource(client, testName, identifier);
+       
+       return result;
+    }
+    
+    protected String createResource(CollectionSpaceClient client, String testName, String identifier) throws Exception {
+        String result = null;
+        
+       setupCreate();
         REQUEST_TYPE payload = createInstance(client.getCommonPartName(), identifier);
         Response res = client.create(payload);
        try {
@@ -177,7 +185,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
        }
        
        return result;
-    }
+    }    
     
        abstract public Class<RESPONSE_TYPE> getEntityResponseType();
     
index 538a37a253a23020a0f7d3a904793f191a621672..8dd3d4e78879beb454429bf31c8c7af689daefd6 100644 (file)
@@ -750,26 +750,10 @@ public abstract class BaseServiceTest<CLT> {
             }
             return;
         }
-        
-        if (logger.isDebugEnabled()) {
-            logger.debug("Cleaning up temporary resources created for testing ...");
-        }
-        CollectionSpaceClient client = this.getClientInstance();
-        //
-        // First, check to see if we need to cleanup any authority items
-        //
-        if (this.isAuthorityClient(client) == true) {
-            AuthorityClient authorityClient = (AuthorityClient) client;
-            for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
-                String itemResourceId = entry.getKey();
-                String authorityResourceId = entry.getValue();
-                // Note: Any non-success responses are ignored and not reported.
-                authorityClient.deleteItem(authorityResourceId, itemResourceId).close();
-            }
-        }
-        //
-        // Next, delete all other entities include possible authorities.
-        //
+        cleanUp(this.getClientInstance());
+    }
+    
+    public void cleanUp(CollectionSpaceClient client) {
         for (String resourceId : allResourceIdsCreated) {
             // Note: Any non-success responses are ignored and not reported.
             client.delete(resourceId).close();
index b28313d4bf17b5f4480337e6673c68d19989d9e8..45d1458ed82799ac92f96ea41d6b813ddf8d77f0 100644 (file)
@@ -109,6 +109,7 @@ public enum ServiceRequestType {
             return javax.ws.rs.HttpMethod.GET;
         }
     },
+    
     READ_LIST {
 
         @Override
@@ -143,6 +144,7 @@ public enum ServiceRequestType {
             return javax.ws.rs.HttpMethod.GET;
         }
     },
+    
     UPDATE {
 
         @Override
@@ -178,6 +180,7 @@ public enum ServiceRequestType {
             return javax.ws.rs.HttpMethod.PUT;
         }
     },
+    
     DELETE {
 
         @Override
@@ -212,6 +215,7 @@ public enum ServiceRequestType {
             return javax.ws.rs.HttpMethod.DELETE;
         }
     },
+    
     SEARCH {
 
         @Override
@@ -245,6 +249,42 @@ public enum ServiceRequestType {
             return javax.ws.rs.HttpMethod.GET;
         }
     },
+    
+    SYNC {
+
+        @Override
+        public int[] validStatusCodes() {
+            final int[] STATUS_CODES = {
+                Response.Status.OK.getStatusCode(),
+                Response.Status.BAD_REQUEST.getStatusCode(),
+                Response.Status.UNAUTHORIZED.getStatusCode(),
+                Response.Status.FORBIDDEN.getStatusCode(),
+                Response.Status.NOT_FOUND.getStatusCode(),
+                Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()
+            };
+            Arrays.sort(STATUS_CODES);
+            return STATUS_CODES;
+        }
+
+        @Override
+        public boolean isValidStatusCode(int statusCode) {
+            if (Arrays.binarySearch(SYNC.validStatusCodes(), statusCode) >= 0) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+
+        @Override
+        public String validStatusCodesAsString() {
+            return Arrays.toString(SYNC.validStatusCodes());
+        }
+
+        @Override
+        public String httpMethodName() {
+            return javax.ws.rs.HttpMethod.GET; // Should be POST
+        }
+    },
     // Used by guard code.
     NON_EXISTENT {
 
index 21fd25516e10adedb8d28d679475dbe8c71b5bb6..716ad14fb5544edac7e9f6658c841d860257a376 100644 (file)
@@ -33,6 +33,7 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.authentication.spi.AuthNContext;
 import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.IClientQueryParams;
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.workflow.WorkflowClient;
@@ -633,27 +634,51 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return valHandlers;
     }
     
+    /**
+     * If one doesn't already exist, use the default properties filename to load a set of properties that
+     * will be used to create an HTTP client to a CollectionSpace instance.
+     */
     @Override
     public AuthorityClient getClient() throws Exception {
        AuthorityClient result = authorityClient;
-       
+
         if (authorityClient == null) {
-               String authorityClientClazz = getServiceBinding().getClientHandler();
-               ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-               authorityClientClazz = authorityClientClazz.trim();
-               try {
-                   Class<?> c = tccl.loadClass(authorityClientClazz);
-                   if (AuthorityClient.class.isAssignableFrom(c)) {
-                       result = authorityClient = ((AuthorityClient) c.newInstance());
-                   } else {
-                       logger.error(String.format("The service binding clientHandler class '%s' for '%s' service was not of type AuthorityClient.",
-                                       authorityClientClazz, this.getServiceName()));
-                   }
-               } catch (ClassNotFoundException e) {
-                       String msg = String.format("Missing document validation handler: '%s'.", authorityClientClazz);
-                       logger.warn(msg);
-                       logger.trace(msg, e);
-               }
+               result = authorityClient = getClient(CollectionSpaceClient.DEFAULT_CLIENT_PROPERTIES_FILENAME);
+        }
+       
+        return result;
+    }
+    
+    /*
+     * Use the properties filename passed in to load the URL and credentials that will be used
+     * to create a new HTTP client.
+     * 
+     * Never uses or resets the this.authorityClient member.  Always creates a new HTTP client using
+     * the loaded properties.
+     * 
+     * (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getClient(java.lang.String)
+     */
+    @Override
+    public AuthorityClient getClient(String clientPropertiesFilename) throws Exception {
+       AuthorityClient result = null;
+       
+        String authorityClientClazz = getServiceBinding().getClientHandler();
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        authorityClientClazz = authorityClientClazz.trim();
+        try {
+            Class<?> c = tccl.loadClass(authorityClientClazz);
+            if (AuthorityClient.class.isAssignableFrom(c)) {
+               result = authorityClient = ((AuthorityClient) c.newInstance());
+               result.setClientProperties(clientPropertiesFilename);
+            } else {
+               logger.error(String.format("The service binding clientHandler class '%s' for '%s' service was not of type AuthorityClient.",
+                               authorityClientClazz, this.getServiceName()));
+            }
+        } catch (ClassNotFoundException e) {
+               String msg = String.format("Missing document validation handler: '%s'.", authorityClientClazz);
+               logger.warn(msg);
+               logger.trace(msg, e);
         }
         
         return result;
index 0275bf48420d48f5c91266673c6b0f4109828872..f72dbe648dabc2173a496751f4d2bfc787773818 100644 (file)
@@ -357,6 +357,8 @@ public interface ServiceContext<IT, OT> {
        public void setRepositoryDomain(RepositoryDomainType repositoryDomain);
 
        public CollectionSpaceClient getClient() throws Exception;
+       
+       public CollectionSpaceClient getClient(String clientProperitesFilename) throws Exception;
 
     /**
      * @return the JAX-RS resource of service for the current context.
index 54cb1ccbe63657bcefef853ea77c8b108bb40bff..29c3017916317f02887396de059b36a291f207a9 100644 (file)
@@ -49,8 +49,6 @@ import org.collectionspace.services.person.PersonauthoritiesCommon;
 import org.collectionspace.services.person.PersonTermGroup;
 import org.collectionspace.services.person.PersonTermGroupList;
 import org.collectionspace.services.person.PersonsCommon;
-import org.jboss.resteasy.client.ClientResponse;
-//import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
@@ -1269,9 +1267,11 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
             }
             return;
         }
+        
         if (logger.isDebugEnabled()) {
             logger.debug("Cleaning up temporary resources created for testing ...");
         }
+        
         String parentResourceId;
         String itemResourceId;
         String contactResourceId;
@@ -1287,34 +1287,8 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
                        contactResourceId);
             res.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.
-            Response response = client.deleteItem(parentResourceId, itemResourceId);
-            try {
-               int status = response.getStatus();
-               if (status != Response.Status.OK.getStatusCode()) {
-                       logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
-                                       itemResourceId, parentResourceId));
-               }
-            } finally {
-               response.close();
-            }
-        }
-        // Clean up item using the SAS client resources.
-        client = (PersonAuthorityClient) this.getSASClientInstance();
-        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();
-        }
         //
-        // Finally, clean up parent resources.
+        // Finally, clean call our superclass' cleanUp method.
         //
         super.cleanUp();
     }
@@ -1486,7 +1460,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         return result;
     }
                
-        @Override
+    @Override
        protected PersonauthoritiesCommon updateInstance(PersonauthoritiesCommon personauthoritiesCommon) {
                PersonauthoritiesCommon result = new PersonauthoritiesCommon();
                
@@ -1508,6 +1482,5 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
        @Override
        protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
                // Do nothing for now.  Add more 'read' validation checks here if applicable.
-       }
-        
+       }        
 }