]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-519: When setting payload headers, users of our Java Client API (including...
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 12 Oct 2009 20:16:09 +0000 (20:16 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 12 Oct 2009 20:16:09 +0000 (20:16 +0000)
19 files changed:
services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java
services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java
services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java
services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java
services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java
services/pom.xml
services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
services/sdk/sample/pom.xml
services/sdk/sample/src/main/java/org/collectionspace/services/sdk/sample/Sample.java
services/sdk/sample/src/main/resources/collectionspace-client.properties [new file with mode: 0644]
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java

index 06390f9720c08b7feb4d089c0b899f0cb2c22920..0b0c31f38b0034f678495b5a2605cd8e83c8b819 100644 (file)
@@ -3,6 +3,7 @@ package org.collectionspace.services.client;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
 import org.jboss.resteasy.client.ClientResponse;
@@ -17,7 +18,14 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class AcquisitionClient extends BaseServiceClient {
 
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+        */
+       public String getServicePathComponent() {
+               return "acquisitions";
+       }
 
+       // FIXME: Is the "instance" member still needed/used?
     /**
      *
      */
@@ -39,7 +47,7 @@ public class AcquisitionClient extends BaseServiceClient {
     }
 
     /**
-     * FIXME Comment this
+     * FIXME Is this method still needed/used?
      *
      * @return
      */
index 6c029f69071c8ddb3bdc2fa5459cb8e5f6989e23..c43f4c15ddebe719609427c008f165258d1993f9 100644 (file)
@@ -49,7 +49,6 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Instance variables specific to this test.
     private AcquisitionClient client = new AcquisitionClient();
-    final String SERVICE_PATH_COMPONENT = "acquisitions";
     private String knownResourceId = null;
 
     // ---------------------------------------------------------------
@@ -178,7 +177,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
         try{
             MultipartInput input = (MultipartInput) res.getEntity();
             AcquisitionsCommon acquistionObject = (AcquisitionsCommon) extractPart(input,
-                    getCommonPartName(), AcquisitionsCommon.class);
+                       client.getCommonPartName(), AcquisitionsCommon.class);
             Assert.assertNotNull(acquistionObject);
         }catch(Exception e){
             throw new RuntimeException(e);
@@ -269,7 +268,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
             verbose("got object to update with ID: " + knownResourceId);
             MultipartInput input = (MultipartInput) res.getEntity();
             AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
-                    getCommonPartName(), AcquisitionsCommon.class);
+                       client.getCommonPartName(), AcquisitionsCommon.class);
             Assert.assertNotNull(acquisition);
 
             // Update the content of this resource.
@@ -278,7 +277,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
             // Submit the request to the service and store the response.
             MultipartOutput output = new MultipartOutput();
             OutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
-            commonPart.getHeaders().add("label", getCommonPartName());
+            commonPart.getHeaders().add("label", client.getCommonPartName());
 
             res = client.update(knownResourceId, output);
             int statusCode = res.getStatus();
@@ -292,7 +291,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
             input = (MultipartInput) res.getEntity();
             AcquisitionsCommon updatedAcquisition =
                     (AcquisitionsCommon) extractPart(input,
-                    getCommonPartName(), AcquisitionsCommon.class);
+                               client.getCommonPartName(), AcquisitionsCommon.class);
             Assert.assertNotNull(updatedAcquisition);
 
             Assert.assertEquals(updatedAcquisition.getAccessionDate(),
@@ -498,7 +497,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // ---------------------------------------------------------------
     @Override
     public String getServicePathComponent() {
-        return SERVICE_PATH_COMPONENT;
+        return client.getServicePathComponent();
     }
 
 
@@ -507,7 +506,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
         acquisition.setAccessionDate("accessionDate-"  + identifier);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+        commonPart.getHeaders().add("label", client.getCommonPartName());
 
         verbose("to be created, acquisition common ", acquisition, AcquisitionsCommon.class);
         return multipart;
index 9561cd40a36b5480c413f2d31cc8dbc07fddfd6a..4b65524a170b3224aba468d950ab925580c7d687 100644 (file)
@@ -38,279 +38,404 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * AuthenticationServiceTest uses CollectionObject service to test authentication
+ * AuthenticationServiceTest uses CollectionObject service to test
+ * authentication
  * 
- * $LastChangedRevision: 434 $
- * $LastChangedDate: 2009-07-28 14:34:15 -0700 (Tue, 28 Jul 2009) $
+ * $LastChangedRevision: 434 $ $LastChangedDate: 2009-07-28 14:34:15 -0700 (Tue,
+ * 28 Jul 2009) $
  */
 public class AuthenticationServiceTest extends AbstractServiceTest {
 
-    final String SERVICE_PATH_COMPONENT = "collectionobjects";
-    private String knownResourceId = null;
-    final Logger logger = LoggerFactory.getLogger(AuthenticationServiceTest.class);
+       /** The known resource id. */
+       private String knownResourceId = null;
+       
+       /** The logger. */
+       final Logger logger = LoggerFactory
+                       .getLogger(AuthenticationServiceTest.class);
 
-    @Override
-    public String getServicePathComponent() {
-        // @TODO Determine if it is possible to obtain this
-        // value programmatically.
-        //
-        // We set this in an annotation in the CollectionObjectProxy
-        // interface, for instance.  We also set service-specific
-        // constants in each service module, which might also
-        // return this value.
-        return SERVICE_PATH_COMPONENT;
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#getServicePathComponent()
+        */
+       protected String getServicePathComponent() {
+               // no need to return anything but null since no auth resources are
+               // accessed
+               return null;
+       }
 
-    @Test
-    @Override
-    public void create() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("create: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("create: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode(),
-                "expected " + Response.Status.CREATED.getStatusCode());
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#create()
+        */
+       @Test
+       @Override
+       public void create() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
 
-        // Store the ID returned from this create operation for additional tests below.
-        knownResourceId = extractId(res);
-    }
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger
+                                       .warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
+                               "test");
+               collectionObjectClient.setProperty(
+                               CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("create: caught " + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("create: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.CREATED
+                               .getStatusCode(), "expected "
+                               + Response.Status.CREATED.getStatusCode());
 
-    @Test(dependsOnMethods = {"create"})
-    public void createWithoutUser() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("createWithoutUser: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("createWithoutUser: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
-                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
-    }
+               // Store the ID returned from this create operation for additional tests
+               // below.
+               knownResourceId = extractId(res);
+       }
 
-    @Test(dependsOnMethods = {"createWithoutUser"})
-    public void createWithoutPassword() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
-        collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("createWithoutPassword: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("createWithoutPassword: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
-                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
-    }
+       /**
+        * Creates the without user.
+        */
+       @Test(dependsOnMethods = { "create" })
+       public void createWithoutUser() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger
+                                       .warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient
+                               .removeProperty(CollectionSpaceClient.USER_PROPERTY);
+               collectionObjectClient.setProperty(
+                               CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("createWithoutUser: caught " + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("createWithoutUser: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
+                               .getStatusCode(), "expected "
+                               + Response.Status.UNAUTHORIZED.getStatusCode());
+       }
 
-    @Test(dependsOnMethods = {"createWithoutPassword"})
-    public void createWithIncorrectPassword() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("createWithIncorrectPassword: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("createWithIncorrectPassword: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
-                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
-    }
+       /**
+        * Creates the without password.
+        */
+       @Test(dependsOnMethods = { "createWithoutUser" })
+       public void createWithoutPassword() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger
+                                       .warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
+                               "test");
+               collectionObjectClient
+                               .removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("createWithoutPassword: caught " + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("createWithoutPassword: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
+                               .getStatusCode(), "expected "
+                               + Response.Status.UNAUTHORIZED.getStatusCode());
+       }
 
-    @Test(dependsOnMethods = {"createWithoutPassword"})
-    public void createWithoutUserPassword() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.removeProperty(CollectionSpaceClient.USER_PROPERTY);
-        collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("createWithoutUserPassword: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("createWithoutUserPassword: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN.getStatusCode(),
-                "expected " + Response.Status.FORBIDDEN.getStatusCode());
-    }
+       /**
+        * Creates the with incorrect password.
+        */
+       @Test(dependsOnMethods = { "createWithoutPassword" })
+       public void createWithIncorrectPassword() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger
+                                       .warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
+                               "test");
+               collectionObjectClient.setProperty(
+                               CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("createWithIncorrectPassword: caught "
+                                       + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("createWithIncorrectPassword: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
+                               .getStatusCode(), "expected "
+                               + Response.Status.UNAUTHORIZED.getStatusCode());
+       }
 
-    @Test(dependsOnMethods = {"createWithoutPassword"})
-    public void createWithIncorrectUserPassword() {
-        String identifier = this.createIdentifier();
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "foo");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("createWithIncorrectUserPassword: caught " + e.getMessage());
-            return;
-        }
-        ClientResponse<Response> res = collectionObjectClient.create(multipart);
-        verbose("createWithIncorrectUserPassword: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
-                "expected " + Response.Status.UNAUTHORIZED.getStatusCode());
-    }
+       /**
+        * Creates the without user password.
+        */
+       @Test(dependsOnMethods = { "createWithoutPassword" })
+       public void createWithoutUserPassword() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger.warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient
+                               .removeProperty(CollectionSpaceClient.USER_PROPERTY);
+               collectionObjectClient
+                               .removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("createWithoutUserPassword: caught " + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("createWithoutUserPassword: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN
+                               .getStatusCode(), "expected "
+                               + Response.Status.FORBIDDEN.getStatusCode());
+       }
 
-    @Override
-    @Test(dependsOnMethods = {"createWithIncorrectUserPassword"})
-    public void delete() {
-        CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
-        collectionObjectClient = new CollectionObjectClient();
-        if(!collectionObjectClient.isServerSecure()){
-            logger.warn("set -Dcspace.server.secure=true to run security tests");
-            return;
-        }
-        collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY, "true");
-        collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY, "test");
-        collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY, "test");
-        try{
-            collectionObjectClient.setupHttpClient();
-            collectionObjectClient.setProxy();
-        }catch(Exception e){
-            logger.error("deleteCollectionObject: caught " + e.getMessage());
-            return;
-        }
-        verbose("Calling deleteCollectionObject:" + knownResourceId);
-        ClientResponse<Response> res = collectionObjectClient.delete(knownResourceId);
-        verbose("deleteCollectionObject: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode(),
-                "expected " + Response.Status.OK.getStatusCode());
-    }
+       /**
+        * Creates the with incorrect user password.
+        */
+       @Test(dependsOnMethods = { "createWithoutPassword" })
+       public void createWithIncorrectUserPassword() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               String identifier = this.createIdentifier();
+               MultipartOutput multipart = createCollectionObjectInstance(
+                               collectionObjectClient.getCommonPartName(), identifier);
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger.warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
+                               "foo");
+               collectionObjectClient.setProperty(
+                               CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("createWithIncorrectUserPassword: caught "
+                                       + e.getMessage());
+                       return;
+               }
+               ClientResponse<Response> res = collectionObjectClient.create(multipart);
+               verbose("createWithIncorrectUserPassword: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
+                               .getStatusCode(), "expected "
+                               + Response.Status.UNAUTHORIZED.getStatusCode());
+       }
 
-    // ---------------------------------------------------------------
-    // Utility methods used by tests above
-    // ---------------------------------------------------------------
-    private MultipartOutput createCollectionObjectInstance(String identifier) {
-        return createCollectionObjectInstance("objectNumber-" + identifier,
-                "objectName-" + identifier);
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#delete()
+        */
+       @Override
+       @Test(dependsOnMethods = { "createWithIncorrectUserPassword" })
+       public void delete() {
+               CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+               collectionObjectClient = new CollectionObjectClient();
+               if (!collectionObjectClient.isServerSecure()) {
+                       logger.warn("set -Dcspace.server.secure=true to run security tests");
+                       return;
+               }
+               collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
+                               "true");
+               collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
+                               "test");
+               collectionObjectClient.setProperty(
+                               CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+               try {
+                       collectionObjectClient.setupHttpClient();
+                       collectionObjectClient.setProxy();
+               } catch (Exception e) {
+                       logger.error("deleteCollectionObject: caught " + e.getMessage());
+                       return;
+               }
+               verbose("Calling deleteCollectionObject:" + knownResourceId);
+               ClientResponse<Response> res = collectionObjectClient
+                               .delete(knownResourceId);
+               verbose("deleteCollectionObject: status = " + res.getStatus());
+               Assert.assertEquals(res.getStatus(),
+                               Response.Status.OK.getStatusCode(), "expected "
+                                               + Response.Status.OK.getStatusCode());
+       }
 
-    private MultipartOutput createCollectionObjectInstance(String objectNumber, String objectName) {
-        CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
+       // ---------------------------------------------------------------
+       // Utility methods used by tests above
+       // ---------------------------------------------------------------
+       /**
+        * Creates the collection object instance.
+        * 
+        * @param commonPartName the common part name
+        * @param identifier the identifier
+        * 
+        * @return the multipart output
+        */
+       private MultipartOutput createCollectionObjectInstance(
+                       String commonPartName, String identifier) {
+               return createCollectionObjectInstance(commonPartName, "objectNumber-"
+                               + identifier, "objectName-" + identifier);
+       }
 
-        collectionObject.setObjectNumber(objectNumber);
-        collectionObject.setObjectName(objectName);
-        MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+       /**
+        * Creates the collection object instance.
+        * 
+        * @param commonPartName the common part name
+        * @param objectNumber the object number
+        * @param objectName the object name
+        * 
+        * @return the multipart output
+        */
+       private MultipartOutput createCollectionObjectInstance(
+                       String commonPartName, String objectNumber, String objectName) {
+               CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
 
-        verbose("to be created, collectionobject common ", collectionObject, CollectionobjectsCommon.class);
-        return multipart;
-    }
+               collectionObject.setObjectNumber(objectNumber);
+               collectionObject.setObjectName(objectName);
+               MultipartOutput multipart = new MultipartOutput();
+               OutputPart commonPart = multipart.addPart(collectionObject,
+                               MediaType.APPLICATION_XML_TYPE);
+               commonPart.getHeaders().add("label", commonPartName);
 
-    @Override
-    public void createList() {
-    }
+               verbose("to be created, collectionobject common ", collectionObject,
+                               CollectionobjectsCommon.class);
+               return multipart;
+       }
 
-    @Override
-    public void createWithEmptyEntityBody() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#createList()
+        */
+       @Override
+       public void createList() {
+       }
 
-    @Override
-    public void createWithMalformedXml() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithEmptyEntityBody()
+        */
+       @Override
+       public void createWithEmptyEntityBody() {
+       }
 
-    @Override
-    public void createWithWrongXmlSchema() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithMalformedXml()
+        */
+       @Override
+       public void createWithMalformedXml() {
+       }
 
-    @Override
-    public void read() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithWrongXmlSchema()
+        */
+       @Override
+       public void createWithWrongXmlSchema() {
+       }
 
-    @Override
-    public void readNonExistent() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#read()
+        */
+       @Override
+       public void read() {
+       }
 
-    @Override
-    public void readList() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#readNonExistent()
+        */
+       @Override
+       public void readNonExistent() {
+       }
 
-    @Override
-    public void update() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#readList()
+        */
+       @Override
+       public void readList() {
+       }
 
-    @Override
-    public void updateWithEmptyEntityBody() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#update()
+        */
+       @Override
+       public void update() {
+       }
 
-    @Override
-    public void updateWithMalformedXml() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithEmptyEntityBody()
+        */
+       @Override
+       public void updateWithEmptyEntityBody() {
+       }
 
-    @Override
-    public void updateWithWrongXmlSchema() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithMalformedXml()
+        */
+       @Override
+       public void updateWithMalformedXml() {
+       }
 
-    @Override
-    public void updateNonExistent() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithWrongXmlSchema()
+        */
+       @Override
+       public void updateWithWrongXmlSchema() {
+       }
 
-    @Override
-    public void deleteNonExistent() {
-    }
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#updateNonExistent()
+        */
+       @Override
+       public void updateNonExistent() {
+       }
+
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#deleteNonExistent()
+        */
+       @Override
+       public void deleteNonExistent() {
+       }
 }
index 8579d5bd646a2a7f71f78b304c9d9d811ae7c558..b7ca56bead7bfbff6e8f155e6e0b59cee98a03d9 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Properties;
 import org.apache.commons.httpclient.HttpClient;\r
 import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
 import org.apache.commons.httpclient.auth.AuthScope;\r
+import org.collectionspace.services.common.context.ServiceContext;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -42,6 +43,14 @@ public abstract class BaseServiceClient implements CollectionSpaceClient {
     private URL url;\r
     private HttpClient httpClient;\r
 \r
+       public String getCommonPartName() {\r
+               return getServicePathComponent()\r
+               + ServiceContext.PART_LABEL_SEPERATOR\r
+               + ServiceContext.PART_COMMON_LABEL;\r
+       }\r
+\r
+       abstract public String getServicePathComponent();\r
+    \r
     protected BaseServiceClient() {\r
         readProperties();\r
         setupHttpClient();\r
@@ -68,7 +77,7 @@ public abstract class BaseServiceClient implements CollectionSpaceClient {
             logger.trace("begin property name=" + key + " value=" + properties.get(key));\r
         }\r
     }\r
-\r
+    \r
     @Override\r
     public String getBaseURL() {\r
         return properties.getProperty(URL_PROPERTY);\r
index a80d6dbbb676bf31be2ce1cb1a6dbeea04cbff55..5a933543c3582d273f53836de1d9f0163dbfcce4 100644 (file)
 
 package org.collectionspace.services.client;
 
-
-
 /**
  * A CollectionObjectClient.
 
  * @version $Revision:$
  */
 public class TestServiceClient extends BaseServiceClient {
-
-
     /**
      *
      * Default constructor for CollectionObjectClient class.
@@ -40,6 +36,14 @@ public class TestServiceClient extends BaseServiceClient {
      */
     public TestServiceClient() {
     }
-
     
+    /**
+    *
+    * Returning NULL since this class is a base-level client, used (only) 
+    * to obtain the base service URL.
+    *
+    */    
+       public String getServicePathComponent() {
+               return null;
+       }  
 }
index efeb736ec1b546140ac81dd649bddb0e2c95a5cc..8f98a96bf112e9ebd4884051eea2e6e4bf7f76fc 100644 (file)
@@ -262,14 +262,7 @@ public abstract class AbstractServiceTest implements ServiceTest {
      * This component will follow directly after the
      * base path, if any.
      */
-    @Override
-    public abstract String getServicePathComponent();
-
-    @Override
-    public String getCommonPartName() {
-        return getServicePathComponent() + ServiceContext.PART_LABEL_SEPERATOR + 
-               ServiceContext.PART_COMMON_LABEL;
-    }
+    protected abstract String getServicePathComponent();
 
     // ---------------------------------------------------------------
     // Utility methods
index 8f54216f82ea6fb33499c9e8404fed1d16e301f9..b81168f72e7b559f15d4267e14651d9f4b154658 100644 (file)
@@ -36,13 +36,13 @@ public interface ServiceTest {
      * This component will follow directly after the
      * base path, if any.
      */
-    public String getServicePathComponent();
-
-    /**
-     * getCommonPartName get common part name for the service request
-     * @return
-     */
-    public String getCommonPartName();
+//    public String getServicePathComponent();
+//
+//    /**
+//     * getCommonPartName get common part name for the service request
+//     * @return
+//     */
+//    public String getCommonPartName();
 
     // ---------------------------------------------------------------
     // CRUD tests : CREATE tests
index ea9c5b865bf1afcb1b9d0032026e4fc45dcc43fc..eb1abf460825f7a303cfc4f4381359d152300247 100644 (file)
@@ -1,9 +1,36 @@
+/**    
+ * CollectionObjectClient.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright Â© 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
 package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
 
 
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
 import org.jboss.resteasy.client.ClientResponse;
@@ -22,6 +49,13 @@ public class CollectionObjectClient extends BaseServiceClient {
      *
      */
     private CollectionObjectProxy collectionObjectProxy;
+    
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+        */
+       public String getServicePathComponent() {
+               return "collectionobjects";
+       }
 
     /**
      *
index 60b43b6f4ee86cd92f078da8e8ede23765e9410b..fb04ecc5b43d62495f1b14eaf26787b77cdee62f 100644 (file)
@@ -50,12 +50,14 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     // Instance variables specific to this test.
     private CollectionObjectClient client = new CollectionObjectClient();
-    final String SERVICE_PATH_COMPONENT = "collectionobjects";
     private String knownResourceId = null; 
     
-    //FIXME: Remove this method once ALL the services use "_common" instead of "-common"
-    public String getCommonPartName() {
-        return getServicePathComponent() + "_common";
+    /*
+     * This method is called only by the parent class, AbstractServiceTest
+     */
+    @Override
+    public String getServicePathComponent() {
+        return client.getServicePathComponent();
     }
 
     // ---------------------------------------------------------------
@@ -74,7 +76,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         // Submit the request to the service and store the response.
         String identifier = createIdentifier();
 
-        MultipartOutput multipart = createCollectionObjectInstance(identifier);
+        MultipartOutput multipart = createCollectionObjectInstance(client.getCommonPartName(), identifier);
         ClientResponse<Response> res = client.create(multipart);
 
         int statusCode = res.getStatus();
@@ -204,7 +206,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         try{
             MultipartInput input = (MultipartInput) res.getEntity();
             CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input,
-                    getCommonPartName(), CollectionobjectsCommon.class);
+                    client.getCommonPartName(), CollectionobjectsCommon.class);
             Assert.assertNotNull(collectionObject);
         }catch(Exception e){
             throw new RuntimeException(e);
@@ -296,7 +298,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
             verbose("got object to update with ID: " + knownResourceId);
             MultipartInput input = (MultipartInput) res.getEntity();
             CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input,
-                    getCommonPartName(), CollectionobjectsCommon.class);
+                       client.getCommonPartName(), CollectionobjectsCommon.class);
             Assert.assertNotNull(collectionObject);
 
             // Update the content of this resource.
@@ -306,7 +308,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
             // Submit the request to the service and store the response.
             MultipartOutput output = new MultipartOutput();
             OutputPart commonPart = output.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
-            commonPart.getHeaders().add("label", getCommonPartName());
+            commonPart.getHeaders().add("label", client.getCommonPartName());
 
             res = client.update(knownResourceId, output);
             int statusCode = res.getStatus();
@@ -320,7 +322,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
             input = (MultipartInput) res.getEntity();
             CollectionobjectsCommon updatedCollectionObject =
                     (CollectionobjectsCommon) extractPart(input,
-                    getCommonPartName(), CollectionobjectsCommon.class);
+                               client.getCommonPartName(), CollectionobjectsCommon.class);
             Assert.assertNotNull(updatedCollectionObject);
 
             Assert.assertEquals(updatedCollectionObject.getObjectName(),
@@ -419,7 +421,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         // Note: The ID used in this 'create' call may be arbitrary.
 
         // The only relevant ID may be the one used in updateCollectionObject(), below.
-        MultipartOutput multipart = createCollectionObjectInstance(NON_EXISTENT_ID);
+        MultipartOutput multipart = createCollectionObjectInstance(client.getCommonPartName(), NON_EXISTENT_ID);
         ClientResponse<MultipartInput> res =
                 client.update(NON_EXISTENT_ID, multipart);
 
@@ -504,31 +506,20 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // ---------------------------------------------------------------
     // Utility methods used by tests above
     // ---------------------------------------------------------------
-    @Override
-    public String getServicePathComponent() {
-        // @TODO Determine if it is possible to obtain this
-        // value programmatically.
-        //
-        // We set this in an annotation in the CollectionObjectProxy
-        // interface, for instance.  We also set service-specific
-        // constants in each service module, which might also
-        // return this value.
-        return SERVICE_PATH_COMPONENT;
-    }
 
-    private MultipartOutput createCollectionObjectInstance(String identifier) {
-        return createCollectionObjectInstance("objectNumber-" + identifier,
+    private MultipartOutput createCollectionObjectInstance(String commonPartName, String identifier) {
+        return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier,
                 "objectName-" + identifier);
     }
 
-    private MultipartOutput createCollectionObjectInstance(String objectNumber, String objectName) {
+    private MultipartOutput createCollectionObjectInstance(String commonPartName, String objectNumber, String objectName) {
         CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
 
         collectionObject.setObjectNumber(objectNumber);
         collectionObject.setObjectName(objectName);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+        commonPart.getHeaders().add("label", commonPartName);
 
         verbose("to be created, collectionobject common ", collectionObject, CollectionobjectsCommon.class);
 
index 9a941c921418e873932a490040823eb9e04c364d..3ed7a507d3ed1ab1d43a82d91c258958a6a42342 100644 (file)
@@ -1,7 +1,34 @@
+/**    
+ * IntakeClient.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright Â© 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
 package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.intake.IntakesCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
@@ -18,11 +45,18 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class IntakeClient extends BaseServiceClient {
 
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+        */
+       public String getServicePathComponent() {
+               return "intakes";
+       }
 
-    /**
+       /**
      *
      */
     private static final IntakeClient instance = new IntakeClient();
+    
     /**
      *
      */
index 3b069e03d39631f3d66662e41af0b32d6464cbf8..ed6fc894112979d529cc03177a5e5493fba57c35 100644 (file)
@@ -202,7 +202,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
         try{
             MultipartInput input = (MultipartInput) res.getEntity();
             IntakesCommon intake = (IntakesCommon) extractPart(input,
-                    getCommonPartName(), IntakesCommon.class);
+                    client.getCommonPartName(), IntakesCommon.class);
             Assert.assertNotNull(intake);
         }catch(Exception e){
             throw new RuntimeException(e);
@@ -294,7 +294,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
             verbose("got object to update with ID: " + knownResourceId);
             MultipartInput input = (MultipartInput) res.getEntity();
             IntakesCommon intake = (IntakesCommon) extractPart(input,
-                    getCommonPartName(), IntakesCommon.class);
+                       client.getCommonPartName(), IntakesCommon.class);
             Assert.assertNotNull(intake);
 
             // Update the content of this resource.
@@ -305,7 +305,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
             // Submit the request to the service and store the response.
             MultipartOutput output = new MultipartOutput();
             OutputPart commonPart = output.addPart(intake, MediaType.APPLICATION_XML_TYPE);
-            commonPart.getHeaders().add("label", getCommonPartName());
+            commonPart.getHeaders().add("label", client.getCommonPartName());
 
             res = client.update(knownResourceId, output);
             int statusCode = res.getStatus();
@@ -319,7 +319,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
             input = (MultipartInput) res.getEntity();
             IntakesCommon updatedIntake =
                     (IntakesCommon) extractPart(input,
-                    getCommonPartName(), IntakesCommon.class);
+                               client.getCommonPartName(), IntakesCommon.class);
             Assert.assertNotNull(updatedIntake);
 
             Assert.assertEquals(updatedIntake.getEntryDate(),
@@ -522,7 +522,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
         intake.setEntryDate(entryDate);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+        commonPart.getHeaders().add("label", client.getCommonPartName());
 
         verbose("to be created, intake common ", intake, IntakesCommon.class);
 
index 1eb56b06ebed66ba4cefaae7d3451d30d41cca2e..cd2d8000706e35099204751dd32e140c0b350c8d 100644 (file)
@@ -29,7 +29,7 @@
         <module>intake</module>\r
         <module>JaxRsServiceProvider</module>\r
         <module>client</module>\r
-        <!--<module>sdk</module>-->\r
+<!--        <module>sdk</module>-->\r
         <!--module>IntegrationTests</module-->\r
     </modules>\r
 \r
index 1014fb9cc0dcc5d48f0bd186bbfa9aca6959d380..66a2a5ebdf0a8fff97bf062dba8b5d6874e669b5 100644 (file)
@@ -2,6 +2,7 @@ package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.relation.RelationsCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
@@ -18,6 +19,13 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class RelationClient extends BaseServiceClient implements RelationProxy {
 
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+        */
+       public String getServicePathComponent() {
+               return "relations";
+       }
+       
     /**
      *
      */
index 26147f1d114e13ec126762fd500414303025bbc3..903634d33f351c56a59235bdc48edcb9af559733 100644 (file)
@@ -201,9 +201,9 @@ public class RelationServiceTest extends AbstractServiceTest {
         try{
             MultipartInput input = (MultipartInput) res.getEntity();
             RelationsCommon relation = (RelationsCommon) extractPart(input,
-                    getCommonPartName(), RelationsCommon.class);
+                    client.getCommonPartName(), RelationsCommon.class);
             Assert.assertNotNull(relation);
-        }catch(Exception e){
+        } catch(Exception e){
             throw new RuntimeException(e);
         }
 
@@ -290,7 +290,7 @@ public class RelationServiceTest extends AbstractServiceTest {
             verbose("Got object to update with ID: " + knownResourceId);
             MultipartInput input = (MultipartInput) res.getEntity();
             RelationsCommon relation = (RelationsCommon) extractPart(input,
-                    getCommonPartName(), RelationsCommon.class);
+                       client.getCommonPartName(), RelationsCommon.class);
             Assert.assertNotNull(relation);
 
             // Update the content of this resource.
@@ -303,7 +303,7 @@ public class RelationServiceTest extends AbstractServiceTest {
             // Submit the request to the service and store the response.
             MultipartOutput output = new MultipartOutput();
             OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
-            commonPart.getHeaders().add("label", getCommonPartName());
+            commonPart.getHeaders().add("label", client.getCommonPartName());
             res = client.update(knownResourceId, output);
             int statusCode = res.getStatus();
             // Check the status code of the response: does it match the expected response(s)?
@@ -312,11 +312,11 @@ public class RelationServiceTest extends AbstractServiceTest {
                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
-            input = (MultipartInput) res.getEntity();
-            RelationsCommon updatedObject =
-                    (RelationsCommon) extractPart(input,
-                    getCommonPartName(), RelationsCommon.class);
-            Assert.assertNotNull(updatedObject);
+                       input = (MultipartInput) res.getEntity();
+                       RelationsCommon updatedObject = (RelationsCommon) extractPart(
+                                       input, client.getCommonPartName(),
+                                       RelationsCommon.class);
+                       Assert.assertNotNull(updatedObject);
 
             final String msg =
                     "Data in updated object did not match submitted data.";
@@ -525,7 +525,7 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+        commonPart.getHeaders().add("label", client.getCommonPartName());
         verbose("to be created, relation common ", relation, RelationsCommon.class);
 
         return multipart;
index 368b9c0c86eddcbb325e8aed46fc0086670e628a..4df79bd60d7d83f8b379b6d220b94ae891807c3a 100644 (file)
             <artifactId>org.collectionspace.services.collectionobject.client</artifactId>\r
             <version>1.0</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.slf4j</groupId>\r
+            <artifactId>slf4j-api</artifactId>\r
+            <version>1.5.8</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.slf4j</groupId>\r
+            <artifactId>slf4j-log4j12</artifactId>\r
+            <version>1.5.8</version>\r
+        </dependency>\r
     </dependencies>\r
     \r
     <repositories>\r
index 4e16054049f5d286af56f80da76d4da1c44e7720..64475132795a046c39e54244f9f668f898515382 100644 (file)
@@ -3,12 +3,19 @@ package org.collectionspace.services.sdk.sample;
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.core.MediaType;\r
 import javax.ws.rs.core.MultivaluedMap;\r
 import javax.ws.rs.core.Response;\r
 \r
 import org.testng.Assert;\r
 \r
 import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
 \r
 import org.collectionspace.services.client.CollectionObjectClient;\r
 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;\r
@@ -22,6 +29,9 @@ public class Sample {
         * @param args\r
         */\r
        public static void main(String[] args) {\r
+               \r
+               System.out.println("Base URL is: " + collectionObjectClient.getBaseURL());\r
+               \r
                String csid = createCollectionObject();\r
                System.out.println("Created a new collection object with CSID=" + csid);\r
                \r
@@ -34,8 +44,12 @@ public class Sample {
 \r
                CollectionobjectsCommon co = new CollectionobjectsCommon();\r
                co.setObjectName("Keiko CollectionobjectsCommon");\r
+       \r
+        MultipartOutput multipart = new MultipartOutput();\r
+        OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);\r
+        commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName());\r
                \r
-           ClientResponse<Response> response = collectionObjectClient.create(co);\r
+           ClientResponse<Response> response = collectionObjectClient.create(multipart);\r
            Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());\r
            result = extractId(response);\r
            \r
@@ -45,13 +59,21 @@ public class Sample {
        static CollectionobjectsCommon readCollectionObject(String csid) {\r
                CollectionobjectsCommon result = null;\r
                \r
-               ClientResponse<CollectionobjectsCommon> response = collectionObjectClient.read(csid);\r
+        ClientResponse<MultipartInput> response = collectionObjectClient.read(csid);\r
                Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());\r
-               result = response.getEntity();\r
+        try{\r
+            MultipartInput input = (MultipartInput) response.getEntity();\r
+            result = (CollectionobjectsCommon) extractPart(input,\r
+                       collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class);\r
+        } catch(Exception e){\r
+            throw new RuntimeException(e);\r
+        }\r
                \r
                return result;\r
-       }\r
-       \r
+       }       \r
+//\r
+// Utility methods that belong somewhere in the SDK and NOT the sample.\r
+//     \r
        static String extractId(ClientResponse<Response> res) {\r
                String result = null;\r
                \r
@@ -63,4 +85,17 @@ public class Sample {
                return result;\r
        }       \r
 \r
+    static Object extractPart(MultipartInput input, String label, Class clazz) throws Exception {\r
+        Object obj = null;\r
+        for(InputPart part : input.getParts()){\r
+            String partLabel = part.getHeaders().getFirst("label");\r
+            if(label.equalsIgnoreCase(partLabel)){\r
+                String partStr = part.getBodyAsString();\r
+                obj = part.getBody(clazz, null);\r
+                break;\r
+            }\r
+        }\r
+        return obj;\r
+    }\r
+       \r
 }\r
diff --git a/services/sdk/sample/src/main/resources/collectionspace-client.properties b/services/sdk/sample/src/main/resources/collectionspace-client.properties
new file mode 100644 (file)
index 0000000..429b9f6
--- /dev/null
@@ -0,0 +1,6 @@
+#url of the collectionspace server\r
+cspace.url=http://localhost:8180/cspace-services/\r
+cspace.ssl=false\r
+cspace.auth=false\r
+cspace.user=test\r
+cspace.password=test
\ No newline at end of file
index 50cd35212cf408d27e9c8dadd021aa884fcc0cc9..fd8692412f608085504ffac6d418fe27eb1b7448 100644 (file)
@@ -2,6 +2,7 @@ package org.collectionspace.services.client;
 
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
@@ -18,6 +19,12 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  */
 public class VocabularyClient extends BaseServiceClient {
 
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent()
+        */
+       public String getServicePathComponent() {
+               return "vocabularies";
+       }
 
     /**
      *
index 5a079653aa08e7c4c7a74368b6a377ed5067e57c..f40443af18014cc2317d445487982b31c561ee6c 100644 (file)
@@ -202,7 +202,7 @@ public class VocabularyServiceTest extends AbstractServiceTest {
         try{
             MultipartInput input = (MultipartInput) res.getEntity();
             VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
-                    getCommonPartName(), VocabulariesCommon.class);
+                       client.getCommonPartName(), VocabulariesCommon.class);
             Assert.assertNotNull(vocabulary);
         }catch(Exception e){
             throw new RuntimeException(e);
@@ -294,7 +294,7 @@ public class VocabularyServiceTest extends AbstractServiceTest {
             verbose("got object to update with ID: " + knownResourceId);
             MultipartInput input = (MultipartInput) res.getEntity();
             VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
-                    getCommonPartName(), VocabulariesCommon.class);
+                       client.getCommonPartName(), VocabulariesCommon.class);
             Assert.assertNotNull(vocabulary);
 
             // Update the content of this resource.
@@ -304,7 +304,7 @@ public class VocabularyServiceTest extends AbstractServiceTest {
             // Submit the request to the service and store the response.
             MultipartOutput output = new MultipartOutput();
             OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
-            commonPart.getHeaders().add("label", getCommonPartName());
+            commonPart.getHeaders().add("label", client.getCommonPartName());
 
             res = client.update(knownResourceId, output);
             int statusCode = res.getStatus();
@@ -318,7 +318,7 @@ public class VocabularyServiceTest extends AbstractServiceTest {
             input = (MultipartInput) res.getEntity();
             VocabulariesCommon updatedVocabulary =
                     (VocabulariesCommon) extractPart(input,
-                    getCommonPartName(), VocabulariesCommon.class);
+                               client.getCommonPartName(), VocabulariesCommon.class);
             Assert.assertNotNull(updatedVocabulary);
 
             Assert.assertEquals(updatedVocabulary.getDisplayName(),
@@ -521,7 +521,7 @@ public class VocabularyServiceTest extends AbstractServiceTest {
         vocabulary.setVocabType(vocabType);
         MultipartOutput multipart = new MultipartOutput();
         OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
-        commonPart.getHeaders().add("label", getCommonPartName());
+        commonPart.getHeaders().add("label", client.getCommonPartName());
 
         verbose("to be created, vocabulary common ", vocabulary, VocabulariesCommon.class);