From dda676150eea5bf2eca83c1c221188f6d618c0b7 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 12 Oct 2009 20:16:09 +0000 Subject: [PATCH] CSPACE-519: When setting payload headers, users of our Java Client API (including our unit tests) should not need to define and describe the service path component and "_common" conventions. These are now made available to Java Client API users via the client classes. --- .../services/client/AcquisitionClient.java | 10 +- .../client/test/AcquisitionServiceTest.java | 13 +- .../client/AuthenticationServiceTest.java | 615 +++++++++++------- .../services/client/BaseServiceClient.java | 11 +- .../services/client/TestServiceClient.java | 14 +- .../client/test/AbstractServiceTest.java | 9 +- .../services/client/test/ServiceTest.java | 14 +- .../client/CollectionObjectClient.java | 34 + .../test/CollectionObjectServiceTest.java | 41 +- .../services/client/IntakeClient.java | 36 +- .../client/test/IntakeServiceTest.java | 10 +- services/pom.xml | 2 +- .../services/client/RelationClient.java | 8 + .../client/test/RelationServiceTest.java | 20 +- services/sdk/sample/pom.xml | 10 + .../services/sdk/sample/Sample.java | 45 +- .../collectionspace-client.properties | 6 + .../services/client/VocabularyClient.java | 7 + .../client/test/VocabularyServiceTest.java | 10 +- 19 files changed, 589 insertions(+), 326 deletions(-) create mode 100644 services/sdk/sample/src/main/resources/collectionspace-client.properties diff --git a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java index 06390f972..0b0c31f38 100644 --- a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java +++ b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java @@ -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 */ diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java index 6c029f690..c43f4c15d 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java @@ -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; diff --git a/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java b/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java index 9561cd40a..4b65524a1 100644 --- a/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java +++ b/services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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() { + } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java index 8579d5bd6..b7ca56bea 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/BaseServiceClient.java @@ -29,6 +29,7 @@ import java.util.Properties; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; +import org.collectionspace.services.common.context.ServiceContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +43,14 @@ public abstract class BaseServiceClient implements CollectionSpaceClient { private URL url; private HttpClient httpClient; + public String getCommonPartName() { + return getServicePathComponent() + + ServiceContext.PART_LABEL_SEPERATOR + + ServiceContext.PART_COMMON_LABEL; + } + + abstract public String getServicePathComponent(); + protected BaseServiceClient() { readProperties(); setupHttpClient(); @@ -68,7 +77,7 @@ public abstract class BaseServiceClient implements CollectionSpaceClient { logger.trace("begin property name=" + key + " value=" + properties.get(key)); } } - + @Override public String getBaseURL() { return properties.getProperty(URL_PROPERTY); diff --git a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java index a80d6dbbb..5a933543c 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java @@ -23,16 +23,12 @@ 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; + } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java index efeb736ec..8f98a96bf 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java @@ -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 diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java index 8f54216f8..b81168f72 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java @@ -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 diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index ea9c5b865..eb1abf460 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -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"; + } /** * diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index 60b43b6f4..fb04ecc5b 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -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 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 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); diff --git a/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java b/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java index 9a941c921..3ed7a507d 100644 --- a/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java +++ b/services/intake/client/src/main/java/org/collectionspace/services/client/IntakeClient.java @@ -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(); + /** * */ diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java index 3b069e03d..ed6fc8941 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java @@ -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); diff --git a/services/pom.xml b/services/pom.xml index 1eb56b06e..cd2d80007 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -29,7 +29,7 @@ intake JaxRsServiceProvider client - + diff --git a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java index 1014fb9cc..66a2a5ebd 100644 --- a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java +++ b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java @@ -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"; + } + /** * */ diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 26147f1d1..903634d33 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -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; diff --git a/services/sdk/sample/pom.xml b/services/sdk/sample/pom.xml index 368b9c0c8..4df79bd60 100644 --- a/services/sdk/sample/pom.xml +++ b/services/sdk/sample/pom.xml @@ -13,6 +13,16 @@ org.collectionspace.services.collectionobject.client 1.0 + + org.slf4j + slf4j-api + 1.5.8 + + + org.slf4j + slf4j-log4j12 + 1.5.8 + diff --git a/services/sdk/sample/src/main/java/org/collectionspace/services/sdk/sample/Sample.java b/services/sdk/sample/src/main/java/org/collectionspace/services/sdk/sample/Sample.java index 4e1605404..644751327 100644 --- a/services/sdk/sample/src/main/java/org/collectionspace/services/sdk/sample/Sample.java +++ b/services/sdk/sample/src/main/java/org/collectionspace/services/sdk/sample/Sample.java @@ -3,12 +3,19 @@ package org.collectionspace.services.sdk.sample; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import org.testng.Assert; import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.InputPart; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; @@ -22,6 +29,9 @@ public class Sample { * @param args */ public static void main(String[] args) { + + System.out.println("Base URL is: " + collectionObjectClient.getBaseURL()); + String csid = createCollectionObject(); System.out.println("Created a new collection object with CSID=" + csid); @@ -34,8 +44,12 @@ public class Sample { CollectionobjectsCommon co = new CollectionobjectsCommon(); co.setObjectName("Keiko CollectionobjectsCommon"); + + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName()); - ClientResponse response = collectionObjectClient.create(co); + ClientResponse response = collectionObjectClient.create(multipart); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); result = extractId(response); @@ -45,13 +59,21 @@ public class Sample { static CollectionobjectsCommon readCollectionObject(String csid) { CollectionobjectsCommon result = null; - ClientResponse response = collectionObjectClient.read(csid); + ClientResponse response = collectionObjectClient.read(csid); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); - result = response.getEntity(); + try{ + MultipartInput input = (MultipartInput) response.getEntity(); + result = (CollectionobjectsCommon) extractPart(input, + collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class); + } catch(Exception e){ + throw new RuntimeException(e); + } return result; - } - + } +// +// Utility methods that belong somewhere in the SDK and NOT the sample. +// static String extractId(ClientResponse res) { String result = null; @@ -63,4 +85,17 @@ public class Sample { return result; } + static Object extractPart(MultipartInput input, String label, Class clazz) throws Exception { + Object obj = null; + for(InputPart part : input.getParts()){ + String partLabel = part.getHeaders().getFirst("label"); + if(label.equalsIgnoreCase(partLabel)){ + String partStr = part.getBodyAsString(); + obj = part.getBody(clazz, null); + break; + } + } + return obj; + } + } 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 index 000000000..429b9f6fe --- /dev/null +++ b/services/sdk/sample/src/main/resources/collectionspace-client.properties @@ -0,0 +1,6 @@ +#url of the collectionspace server +cspace.url=http://localhost:8180/cspace-services/ +cspace.ssl=false +cspace.auth=false +cspace.user=test +cspace.password=test \ No newline at end of file diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java index 50cd35212..fd8692412 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -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"; + } /** * diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index 5a079653a..f40443af1 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -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); -- 2.47.3