]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
All CollectionObject-related client (i.e. via JAX-RS proxy) tests now execute success...
authorAron Roberts <aron@socrates.berkeley.edu>
Mon, 30 Mar 2009 22:30:54 +0000 (22:30 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Mon, 30 Mar 2009 22:30:54 +0000 (22:30 +0000)
sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/CollectionObjectTest.java

index db00786bf125d7421f7f4a573982801523c95f2a..b5aa197aa7f05e8261b997685d848737396ba29e 100644 (file)
@@ -8,6 +8,8 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 import org.collectionspace.hello.CollectionObject;
 import org.collectionspace.hello.CollectionObjectList;
+import org.collectionspace.hello.CollectionObjectListItem;
+import org.collectionspace.hello.DefaultCollectionObject;
 import org.collectionspace.hello.client.CollectionObjectClient;
 import org.jboss.resteasy.client.ClientResponse;
 import org.testng.Assert;
@@ -21,13 +23,18 @@ import org.testng.annotations.Test;
 public class CollectionObjectTest {
 
     private CollectionObjectClient client = CollectionObjectClient.getInstance();
+    
     private String updateId = "1";
+    private String nonexistentId = "foo";
+
 
-/*
     @Test
     public void createCollectionObject() {
-        CollectionObject CollectionObject = createCollectionObject("Chris", "Hoffman");
-        ClientResponse<Response> res = CollectionObjectClient.createCollectionObject(CollectionObject);
+        CollectionObject co =
+          createCollectionObject("1984.021.0049", "Radio News, vol. 10, no. 2, August 1928");
+        ClientResponse<Response> res = client.createCollectionObject(co);
+        verbose("created status=" + Response.Status.CREATED.getStatusCode());
+        verbose("response status=" + Response.Status.CREATED.getStatusCode());
         Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
         //store updateId locally
         updateId = extractId(res);
@@ -35,45 +42,55 @@ public class CollectionObjectTest {
 
     @Test
     public void createCollectionObjectList() {
-        CollectionObject CollectionObject = createCollectionObject("Aron", "Roberts");
-        ClientResponse<Response> res = CollectionObjectClient.createCollectionObject(CollectionObject);
+        CollectionObject co =
+          createCollectionObject("1997.005.0437", "Toy, Gotham City Police Helicopter, 1992");
+        ClientResponse<Response> res = client.createCollectionObject(co);
         Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
-        CollectionObject = createCollectionObject("Dan", "Sheppard");
-        res = CollectionObjectClient.createCollectionObject(CollectionObject);
+        co = createCollectionObject(
+          "1984.052.0001", " Pathescope Model 9061 28mm motion picture projector, 1914");
+        res = client.createCollectionObject(co);
         Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
     }
 
     @Test(dependsOnMethods = {"createCollectionObject"})
     public void updateCollectionObject() {
-        CollectionObject touCollectionObject = CollectionObjectClient.getCollectionObject(updateId).getEntity();
+        CollectionObject touCollectionObject =
+          client.getCollectionObject(updateId).getEntity();
         verbose("got CollectionObject to update", touCollectionObject, CollectionObject.class);
-        touCollectionObject.setFirstName("Richard");
-        touCollectionObject.setLastName("Millet");
-        int initialVersion = touCollectionObject.getVersion();
-        CollectionObject uCollectionObject = CollectionObjectClient.updateCollectionObject(updateId, touCollectionObject).getEntity();
+        if ( touCollectionObject.getDefaultCollectionObject() == null ) {
+          touCollectionObject.setDefaultCollectionObject( new DefaultCollectionObject() );
+        }
+        String updatedObjNum = "1981.297.0049";
+        touCollectionObject.getDefaultCollectionObject().setObjectNumber(updatedObjNum);
+        touCollectionObject.getDefaultCollectionObject().setObjectName(
+          "Preview slide, It's the Old Army Game, 1926");
+        // int initialVersion = touCollectionObject.getVersion();
+        CollectionObject uCollectionObject =
+        client.updateCollectionObject(updateId, touCollectionObject).getEntity();
         verbose("updated CollectionObject", uCollectionObject, CollectionObject.class);
-        Assert.assertNotSame(uCollectionObject.getVersion(), initialVersion);
-        Assert.assertEquals(uCollectionObject.getFirstName(), "Richard");
+        // Assert.assertNotSame(uCollectionObject.getVersion(), initialVersion);
+        Assert.assertEquals(
+          uCollectionObject.getDefaultCollectionObject().getObjectNumber(), updatedObjNum);
     }
 
     @Test(dependsOnMethods = {"createCollectionObject"})
     public void getCollectionObjectList() {
         //the resource method is expected to return at least an empty list
-        CollectionObjectList CollectionObjectList = CollectionObjectClient.getCollectionObjectList().getEntity();
-        List<CollectionObjectList.CollectionObjectListItem> list = CollectionObjectList.getCollectionObjectListItem();
+        CollectionObjectList coList = client.getCollectionObjectList().getEntity();
+        List<CollectionObjectListItem> list = coList.getCollectionObjectListItem();
         int i = 0;
-        for (CollectionObjectList.CollectionObjectListItem pli : list) {
-            verbose("getCollectionObjectList: list-item[" + i + "] firstName=" + pli.getFirstName());
-            verbose("getCollectionObjectList: list-item[" + i + "] lastName=" + pli.getLastName());
+        for (CollectionObjectListItem pli : list) {
+            verbose("getCollectionObjectList: list-item[" + i + "] objectNumber=" + pli.getObjectNumber());
+            verbose("getCollectionObjectList: list-item[" + i + "] objectName=" + pli.getObjectName());
             verbose("getCollectionObjectList: list-item[" + i + "] uri=" + pli.getUri());
             i++;
         }
     }
 
-*/
+
     @Test
     public void getNonExistingCollectionObject() {
-        ClientResponse<CollectionObject> res = client.getCollectionObject("foo");
+        ClientResponse<CollectionObject> res = client.getCollectionObject(nonexistentId);
 
         Response.Status status = res.getResponseStatus();
         verbose(this.getClass().getName() + ": " +
@@ -89,15 +106,21 @@ public class CollectionObjectTest {
         }
     }
 
-/*
     @Test(dependsOnMethods = {"updateCollectionObject"})
     public void updateWrongCollectionObject() {
-        CollectionObject touCollectionObject = CollectionObjectClient.getCollectionObject(updateId).getEntity();
+        CollectionObject touCollectionObject =
+          client.getCollectionObject(updateId).getEntity();
         verbose("updateWrongCollectionObject: got CollectionObject to update", touCollectionObject, CollectionObject.class);
-        touCollectionObject.setFirstName("Richard");
-        touCollectionObject.setLastName("Millet");
+        if ( touCollectionObject.getDefaultCollectionObject() == null ) {
+          touCollectionObject.setDefaultCollectionObject( new DefaultCollectionObject() );
+        }
+        String updatedObjNum = "1981.297.0049";
+        touCollectionObject.getDefaultCollectionObject().setObjectNumber(updatedObjNum);
+        touCollectionObject.getDefaultCollectionObject().setObjectName(
+          "Preview slide, It's the Old Army Game, 1926");
         //use non existing CollectionObject to update
-        ClientResponse<CollectionObject> res = CollectionObjectClient.updateCollectionObject(9999L, touCollectionObject);
+        ClientResponse<CollectionObject> res =
+          client.updateCollectionObject(nonexistentId, touCollectionObject);
         if (res.getResponseStatus().equals(Response.Status.NOT_FOUND)) {
             verbose("updateWrongCollectionObject: Status=" + res.getResponseStatus().toString());
             String msg = res.getEntity(String.class, String.class);
@@ -108,36 +131,40 @@ public class CollectionObjectTest {
 
     @Test(dependsOnMethods = {"updateWrongCollectionObject"})
     public void deleteCollectionObject() {
-        ClientResponse<Response> res = CollectionObjectClient.deleteCollectionObject(updateId);
+        ClientResponse<Response> res = client.deleteCollectionObject(updateId);
         verbose("deleteCollectionObject: id=" + updateId);
         verbose("deleteCollectionObject: status = " + res.getStatus());
         Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
     }
     
-    private CollectionObject createCollectionObject(String firstName, String lastName) {
-        CollectionObject CollectionObject = new CollectionObject();
-        CollectionObject.setFirstName(firstName);
-        CollectionObject.setLastName(lastName);
-        CollectionObject.setStreet("2195 Hearst Ave.");
-        CollectionObject.setCity("Berkeley");
-        CollectionObject.setState("CA");
-        CollectionObject.setZip("94704");
-        CollectionObject.setCountry("US");
-        return CollectionObject;
+    // ###################################################################################
+    // Utility methods used by tests above
+    // ###################################################################################
+    
+    private CollectionObject createCollectionObject(String objectNumber, String objectName) {
+        verbose("objectNumber=" + objectNumber);
+        verbose("objectName=" + objectName);
+        verbose("Before new CollectionObject() ...");
+        CollectionObject co = new CollectionObject();
+        verbose("Before co.getDefaultCollectionObject().setObjectNumber ...");
+        co.setDefaultCollectionObject( new DefaultCollectionObject() );
+        co.getDefaultCollectionObject().setObjectNumber(objectNumber);
+        co.getDefaultCollectionObject().setObjectName(objectName);
+        return co;
     }
 
-    private Long extractId(ClientResponse<Response> res) {
+    private String extractId(ClientResponse<Response> res) {
         MultivaluedMap mvm = res.getMetadata();
         String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
         String[] segments = uri.split("/");
-        verbose("id=" + segments[segments.length - 1]);
-        return Long.valueOf(segments[segments.length - 1]);
+        String id = segments[segments.length - 1];
+        verbose("id=" + id);
+        return id;
     }
 
-*/
 
     private void verbose(String msg) {
-        System.out.println("CollectionObjectListerviceTest : " + msg);
+        System.out.println("CollectionObjectServiceTest : " + msg);
     }
 
     private void verbose(String msg, Object o, Class clazz) {