From d17bac1956aff791468e90a934778805589ad1e9 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 30 Mar 2009 22:30:54 +0000 Subject: [PATCH] All CollectionObject-related client (i.e. via JAX-RS proxy) tests now execute successfully. --- .../client/test/CollectionObjectTest.java | 111 +++++++++++------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/CollectionObjectTest.java b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/CollectionObjectTest.java index db00786bf..b5aa197aa 100644 --- a/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/CollectionObjectTest.java +++ b/sandbox/aron/HelloWorld-CollectionObject/HelloWorldClient/src/test/java/org/collectionspace/hello/client/test/CollectionObjectTest.java @@ -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 res = CollectionObjectClient.createCollectionObject(CollectionObject); + CollectionObject co = + createCollectionObject("1984.021.0049", "Radio News, vol. 10, no. 2, August 1928"); + ClientResponse 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 res = CollectionObjectClient.createCollectionObject(CollectionObject); + CollectionObject co = + createCollectionObject("1997.005.0437", "Toy, Gotham City Police Helicopter, 1992"); + ClientResponse 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 list = CollectionObjectList.getCollectionObjectListItem(); + CollectionObjectList coList = client.getCollectionObjectList().getEntity(); + List 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 res = client.getCollectionObject("foo"); + ClientResponse 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 res = CollectionObjectClient.updateCollectionObject(9999L, touCollectionObject); + ClientResponse 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 res = CollectionObjectClient.deleteCollectionObject(updateId); + ClientResponse 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 res) { + private String extractId(ClientResponse 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) { -- 2.47.3