--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>\r
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
+ <classpathentry kind="output" path="target/classes"/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>javaee-addressbook-client</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Thu Mar 26 13:03:04 PDT 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5\r
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\r
+org.eclipse.jdt.core.compiler.compliance=1.5\r
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate\r
+org.eclipse.jdt.core.compiler.debug.localVariable=generate\r
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.5\r
--- /dev/null
+#Thu Feb 26 16:30:28 PST 2009\r
+activeProfiles=\r
+eclipse.preferences.version=1\r
+fullBuildGoals=process-test-resources\r
+includeModules=false\r
+resolveWorkspaceProjects=true\r
+resourceFilterGoals=process-resources resources\:testResources\r
+version=1\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+<!-- <parent>\r
+ <artifactId>helloworld</artifactId>\r
+ <groupId>org.collectionspace.hello.services</groupId>\r
+ <version>0.1</version>\r
+ </parent>\r
+-->\r
+ \r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>org.collectionspace.services.client</groupId>\r
+ <artifactId>collectionobject-client</artifactId>\r
+ <packaging>jar</packaging>\r
+ <version>0.2</version>\r
+ <name>CollectionObject Client</name>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>collectionobject-jaxb</artifactId>\r
+ <version>0.2</version>\r
+ </dependency> \r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org-collectionspace-services-common</artifactId>\r
+ <version>0.2</version>\r
+ </dependency>\r
+ \r
+ <dependency>\r
+ <groupId>org.testng</groupId>\r
+ <artifactId>testng</artifactId>\r
+ <version>5.6</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ <version>1.5.2</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ <version>1.5.2</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxrs</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ <!-- filter out unwanted jars -->\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>tjws</groupId>\r
+ <artifactId>webserver</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxb-provider</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-multipart-provider</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>commons-httpclient</groupId>\r
+ <artifactId>commons-httpclient</artifactId>\r
+ <version>3.1</version>\r
+ </dependency>\r
+ </dependencies>\r
+ \r
+ <build>\r
+ <plugins>\r
+ <plugin>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <version>2.0.2</version>\r
+ <configuration>\r
+ <source>1.5</source>\r
+ <target>1.5</target>\r
+ </configuration>\r
+ </plugin>\r
+ </plugins>\r
+ </build>\r
+</project>\r
--- /dev/null
+package org.collectionspace.services.client;
+
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.collectionobject.CollectionObject;
+import org.collectionspace.services.collectionobject.CollectionObjectList;
+
+import org.jboss.resteasy.client.ProxyFactory;
+import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+
+/**
+ * A CollectionObjectClient.
+
+ * @version $Revision:$
+ */
+public class CollectionObjectClient extends CollectionSpaceClient {
+
+
+ /**
+ *
+ */
+ private static final CollectionObjectClient instance = new CollectionObjectClient();
+ /**
+ *
+ */
+ private CollectionObjectProxy collectionObjectProxy;
+
+ /**
+ *
+ * Default constructor for CollectionObjectClient class.
+ *
+ */
+ private CollectionObjectClient() {
+ ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
+ RegisterBuiltin.register(factory);
+ collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class, getURL());
+ }
+
+ /**
+ * FIXME Comment this
+ *
+ * @return
+ */
+ public static CollectionObjectClient getInstance() {
+ return instance;
+ }
+
+ /**
+ * @return
+ * @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject()
+ */
+ public ClientResponse<CollectionObjectList> getCollectionObjectList() {
+ return collectionObjectProxy.getCollectionObjectList();
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject(java.lang.String)
+ */
+ public ClientResponse<CollectionObject> getCollectionObject(String csid) {
+ return collectionObjectProxy.getCollectionObject(csid);
+ }
+
+ /**
+ * @param collectionobject
+ * @return
+ * @see org.collectionspace.hello.client.CollectionObjectProxy#createCollectionObject(org.collectionspace.hello.CollectionObject)
+ */
+ public ClientResponse<Response> createCollectionObject(CollectionObject collectionObject) {
+ return collectionObjectProxy.createCollectionObject(collectionObject);
+ }
+
+ /**
+ * @param csid
+ * @param collectionobject
+ * @return
+ * @see org.collectionspace.hello.client.CollectionObjectProxy#updateCollectionObject(java.lang.Long, org.collectionspace.hello.CollectionObject)
+ */
+ public ClientResponse<CollectionObject> updateCollectionObject(String csid, CollectionObject collectionObject) {
+ return collectionObjectProxy.updateCollectionObject(csid, collectionObject);
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.CollectionObjectProxy#deleteCollectionObject(java.lang.Long)
+ */
+ public ClientResponse<Response> deleteCollectionObject(String csid) {
+ return collectionObjectProxy.deleteCollectionObject(csid);
+ }
+}
--- /dev/null
+package org.collectionspace.services.client;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.collectionobject.CollectionObject;
+import org.collectionspace.services.collectionobject.CollectionObjectList;
+import org.jboss.resteasy.client.ClientResponse;
+
+/**
+ * @version $Revision:$
+ */
+@Path("/collectionobjects/")
+@Produces({"application/xml"})
+@Consumes({"application/xml"})
+public interface CollectionObjectProxy {
+
+ @GET
+ ClientResponse<CollectionObjectList> getCollectionObjectList();
+
+ //(C)reate
+ @POST
+ ClientResponse<Response> createCollectionObject(CollectionObject co);
+
+ //(R)ead
+ @GET
+ @Path("/{csid}")
+ ClientResponse<CollectionObject> getCollectionObject(@PathParam("csid") String csid);
+
+ //(U)pdate
+ @PUT
+ @Path("/{csid}")
+ ClientResponse<CollectionObject> updateCollectionObject(@PathParam("csid") String csid, CollectionObject co);
+
+ //(D)elete
+ @DELETE
+ @Path("/{csid}")
+ ClientResponse<Response> deleteCollectionObject(@PathParam("csid") String csid);
+}
\ No newline at end of file
--- /dev/null
+package org.collectionspace.services.client.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import org.jboss.resteasy.client.ClientResponse;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.collectionspace.services.collectionobject.CollectionObject;
+import org.collectionspace.services.collectionobject.CollectionObjectList;
+import org.collectionspace.services.client.CollectionObjectClient;
+
+/**
+ * A CollectionObjectNuxeoServiceTest.
+ *
+ * @version $Revision:$
+ */
+public class CollectionObjectServiceTest {
+
+ private CollectionObjectClient collectionObjectClient = CollectionObjectClient.getInstance();
+ private String updateId = null;
+ private String deleteId = null;
+
+ @Test
+ public void createCollectionObject() {
+ long identifier = this.createIdentifier();
+
+ CollectionObject collectionObject = createCollectionObject(identifier);
+ ClientResponse<Response> res = collectionObjectClient.createCollectionObject(collectionObject);
+ Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
+
+ //store updateId locally for "update" test
+ if (updateId == null)
+ updateId = extractId(res);
+ else
+ deleteId = extractId(res);
+ }
+
+ @Test(dependsOnMethods = {"createCollectionObject"})
+ public void updateCollectionObject() {
+ ClientResponse<CollectionObject> res = collectionObjectClient.getCollectionObject(updateId);
+ CollectionObject collectionObject = res.getEntity();
+ verbose("Got CollectionObject to update with ID: " + updateId,
+ collectionObject, CollectionObject.class);
+
+ //collectionObject.setCsid("updated-" + updateId);
+ collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
+ collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
+
+ // make call to update service
+ res = collectionObjectClient.updateCollectionObject(updateId, collectionObject);
+
+ // check the response
+ CollectionObject updatedCollectionObject = res.getEntity();
+ Assert.assertEquals(updatedCollectionObject.getObjectName(), collectionObject.getObjectName());
+ verbose("updateCollectionObject: ", updatedCollectionObject, CollectionObject.class);
+
+ return;
+ }
+
+ @Test(dependsOnMethods = {"createCollectionObject"})
+ public void createCollection() {
+ for (int i = 0; i < 3; i++) {
+ this.createCollectionObject();
+ }
+ }
+
+ @Test(dependsOnMethods = {"createCollection"})
+ public void getCollectionObjectList() {
+ //the resource method is expected to return at least an empty list
+ CollectionObjectList coList = collectionObjectClient.getCollectionObjectList().getEntity();
+ List<CollectionObjectList.CollectionObjectListItem> coItemList = coList.getCollectionObjectListItem();
+ int i = 0;
+ for(CollectionObjectList.CollectionObjectListItem pli : coItemList) {
+ verbose("getCollectionObjectList: list-item[" + i + "] csid=" + pli.getCsid());
+ verbose("getCollectionObjectList: list-item[" + i + "] objectNumber=" + pli.getObjectNumber());
+ verbose("getCollectionObjectList: list-item[" + i + "] URI=" + pli.getUri());
+ i++;
+ }
+ }
+
+ @Test(dependsOnMethods = {"updateCollectionObject"})
+ public void deleteCollectionObject() {
+ ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(deleteId);
+ verbose("deleteCollectionObject: csid=" + deleteId);
+ verbose("deleteCollectionObject: status = " + res.getStatus());
+ Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
+ }
+
+ private CollectionObject createCollectionObject(long identifier) {
+ CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier,
+ "objectName-" + identifier);
+
+ return collectionObject;
+ }
+
+ private CollectionObject createCollectionObject(String objectNumber, String objectName) {
+ CollectionObject collectionObject = new CollectionObject();
+
+ collectionObject.setObjectNumber(objectNumber);
+ collectionObject.setObjectName(objectName);
+
+ return collectionObject;
+ }
+
+ private String extractId(ClientResponse<Response> res) {
+ MultivaluedMap mvm = res.getMetadata();
+ String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
+ String[] segments = uri.split("/");
+ String id = segments[segments.length - 1];
+ verbose("id=" + id);
+ return id;
+ }
+
+ private void verbose(String msg) {
+ System.out.println("CollectionObject Test: " + msg);
+ }
+
+ private void verbose(String msg, Object o, Class clazz) {
+ try{
+ verbose(msg);
+ JAXBContext jc = JAXBContext.newInstance(clazz);
+ Marshaller m = jc.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
+ Boolean.TRUE);
+ m.marshal(o, System.out);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ private void verboseMap(MultivaluedMap map) {
+ for(Object entry : map.entrySet()){
+ MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
+ verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
+ }
+ }
+
+ private long createIdentifier() {
+ long identifier = System.currentTimeMillis();
+ return identifier;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+
+ <appender name="unit-tests"
+ class="org.apache.log4j.RollingFileAppender">
+ <param name="File" value="./target/unit-tests.log" />
+ <param name="MaxFileSize" value="10240KB" />
+ <param name="MaxBackupIndex" value="6" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <logger name="org.apache.commons.httpclient" additivity="false">
+ <level value="warn" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <logger name="httpclient.wire" additivity="false">
+ <level value="info" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <root>
+ <priority value="debug" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </root>
+
+</log4j:configuration>
+
+
+
+