]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-419,CSPACE-543:Added Exceptions to client test framework, client tests. Remov...
authorAron Roberts <aron@socrates.berkeley.edu>
Wed, 21 Oct 2009 03:58:21 +0000 (03:58 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Wed, 21 Oct 2009 03:58:21 +0000 (03:58 +0000)
services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java
services/authentication/client/src/test/java/org/collectionspace/services/authentication/client/AuthenticationServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java

index f5bd723045478cbf3c68aba50b9e520eb9f83f25..7a0d0117010fd1bba9fed13d4c5afd36f9479129 100644 (file)
@@ -38,6 +38,9 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * AcquisitionServiceTest, carries out tests against a
  * deployed and running Acquisition Service.
@@ -47,6 +50,9 @@ import org.testng.annotations.Test;
  */
 public class AcquisitionServiceTest extends AbstractServiceTest {
 
+    private final Logger logger =
+        LoggerFactory.getLogger(AcquisitionServiceTest.class);
+
     // Instance variables specific to this test.
     private AcquisitionClient client = new AcquisitionClient();
     private String knownResourceId = null;
@@ -57,7 +63,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test
-    public void create() {
+    public void create() throws Exception {
 
         // Perform setup, such as initializing the type of service request
         // (e.g. CREATE, DELETE), its valid and expected status codes, and
@@ -78,7 +84,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
         // Specifically:
         // Does it fall within the set of valid status codes?
         // Does it exactly match the expected status code?
-        verbose("create: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -86,12 +94,14 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
         // Store the ID returned from this create operation for
         // additional tests below.
         knownResourceId = extractId(res);
-        verbose("create: knownResourceId=" + knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: knownResourceId=" + knownResourceId);
+        }
     }
 
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void createList() {
+    public void createList() throws Exception {
         for(int i = 0; i < 3; i++){
             create();
         }
@@ -100,19 +110,22 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void createWithEmptyEntityBody() {
+    @Override
+    public void createWithEmptyEntityBody() throws Exception {
     }
 
-    public void createWithMalformedXml() {
+    @Override
+    public void createWithMalformedXml() throws Exception {
     }
 
-    public void createWithWrongXmlSchema() {
+    @Override
+    public void createWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithMalformedXml() {
+    public void createWithMalformedXml() throws Exception {
     
     // Perform setup.
     setupCreateWithMalformedXml();
@@ -125,7 +138,10 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithMalformedXml url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -133,7 +149,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithWrongXmlSchema() {
+    public void createWithWrongXmlSchema() throws Exception {
     
     // Perform setup.
     setupCreateWithWrongXmlSchema();
@@ -146,19 +162,23 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithWrongXmlSchema url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void read() {
+    public void read() throws Exception {
 
         // Perform setup.
         setupRead();
@@ -169,25 +189,24 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("read: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("read: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-        //FIXME: remove the following try catch once Aron fixes signatures
-        try{
-            MultipartInput input = (MultipartInput) res.getEntity();
-            AcquisitionsCommon acquistionObject = (AcquisitionsCommon) extractPart(input,
-                       client.getCommonPartName(), AcquisitionsCommon.class);
-            Assert.assertNotNull(acquistionObject);
-        }catch(Exception e){
-            throw new RuntimeException(e);
-        }
+
+        MultipartInput input = (MultipartInput) res.getEntity();
+        AcquisitionsCommon acquistionObject = (AcquisitionsCommon) extractPart(input,
+                client.getCommonPartName(), AcquisitionsCommon.class);
+        Assert.assertNotNull(acquistionObject);
+
     }
 
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void readNonExistent() {
+    public void readNonExistent() throws Exception {
 
         // Perform setup.
         setupReadNonExistent();
@@ -198,7 +217,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -210,7 +231,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"createList", "read"})
-    public void readList() {
+    public void readList() throws Exception {
 
         // Perform setup.
         setupReadList();
@@ -222,7 +243,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readList: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readList: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -234,11 +257,11 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
                     list.getAcquisitionListItem();
             int i = 0;
             for(AcquisitionsCommonList.AcquisitionListItem item : items){
-                verbose("readList: list-item[" + i + "] csid=" +
+                logger.debug("readList: list-item[" + i + "] csid=" +
                         item.getCsid());
-                verbose("readList: list-item[" + i + "] objectNumber=" +
+                logger.debug("readList: list-item[" + i + "] objectNumber=" +
                         item.getAccessionDate());
-                verbose("readList: list-item[" + i + "] URI=" +
+                logger.debug("readList: list-item[" + i + "] URI=" +
                         item.getUri());
                 i++;
             }
@@ -248,76 +271,83 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Failure outcomes
     // None at present.
+
     // ---------------------------------------------------------------
     // CRUD tests : UPDATE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void update() {
+    public void update() throws Exception {
 
         // Perform setup.
         setupUpdate();
-        try{ //ideally, just remove try-catch and let the exception bubble up
-            // Retrieve an existing resource that we can update.
-            ClientResponse<MultipartInput> res =
-                    client.read(knownResourceId);
-            verbose("update: read status = " + res.getStatus());
-            Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
-            verbose("got object to update with ID: " + knownResourceId);
-            MultipartInput input = (MultipartInput) res.getEntity();
-            AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
-                       client.getCommonPartName(), AcquisitionsCommon.class);
-            Assert.assertNotNull(acquisition);
-
-            // Update the content of this resource.
-            acquisition.setAccessionDate("updated-" + acquisition.getAccessionDate());
+
+        ClientResponse<MultipartInput> res =
+                client.read(knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("update: read status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+        if(logger.isDebugEnabled()){
+            logger.debug("got object to update with ID: " + knownResourceId);
+        }
+        MultipartInput input = (MultipartInput) res.getEntity();
+        AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
+                client.getCommonPartName(), AcquisitionsCommon.class);
+        Assert.assertNotNull(acquisition);
+
+        // Update the content of this resource.
+        acquisition.setAccessionDate("updated-" + acquisition.getAccessionDate());
+        if(logger.isDebugEnabled()){
             verbose("updated object", acquisition, AcquisitionsCommon.class);
-            // 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", 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)?
-            verbose("update: status = " + res.getStatus());
-            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
-
-            input = (MultipartInput) res.getEntity();
-            AcquisitionsCommon updatedAcquisition =
-                    (AcquisitionsCommon) extractPart(input,
-                               client.getCommonPartName(), AcquisitionsCommon.class);
-            Assert.assertNotNull(updatedAcquisition);
-
-            Assert.assertEquals(updatedAcquisition.getAccessionDate(),
-                    acquisition.getAccessionDate(),
-                    "Data in updated object did not match submitted data.");
-        }catch(Exception e){
-            e.printStackTrace();
         }
+        // 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", 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)?
+        if(logger.isDebugEnabled()){
+            logger.debug("update: status = " + res.getStatus());
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+        input = (MultipartInput) res.getEntity();
+        AcquisitionsCommon updatedAcquisition =
+                (AcquisitionsCommon) extractPart(input,
+                        client.getCommonPartName(), AcquisitionsCommon.class);
+        Assert.assertNotNull(updatedAcquisition);
+
+        Assert.assertEquals(updatedAcquisition.getAccessionDate(),
+                acquisition.getAccessionDate(),
+                "Data in updated object did not match submitted data.");
+
     }
 
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
     }
 
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
     }
 
-    public void updateWithWrongXmlSchema() {
+    public void updateWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
     
     // Perform setup.
     setupUpdateWithEmptyEntityBody();
@@ -331,7 +361,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        ("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -339,7 +371,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithEmptyEntityBody() {
+    public void createWithEmptyEntityBody() throws Exception {
     
     // Perform setup.
     setupCreateWithEmptyEntityBody();
@@ -353,7 +385,10 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithEmptyEntityBody url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -361,7 +396,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
 
     // Perform setup.
     setupUpdateWithMalformedXml();
@@ -374,7 +409,10 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithMalformedXml: url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -395,15 +433,19 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithWrongXmlSchema: url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+    
     @Override
     @Test(dependsOnMethods = {"update", "testSubmitRequest"})
-    public void updateNonExistent() {
+    public void updateNonExistent() throws Exception {
 
         // Perform setup.
         setupUpdateNonExistent();
@@ -418,7 +460,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("updateNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -430,7 +474,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create", "read", "update"})
-    public void delete() {
+    public void delete() throws Exception {
 
         // Perform setup.
         setupDelete();
@@ -441,7 +485,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("delete: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("delete: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -450,7 +496,7 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"delete"})
-    public void deleteNonExistent() {
+    public void deleteNonExistent() throws Exception {
 
         // Perform setup.
         setupDeleteNonExistent();
@@ -461,7 +507,9 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("deleteNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("deleteNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -475,10 +523,10 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
      * of the methods above.
      */
     @Test(dependsOnMethods = {"create", "read"})
-    public void testSubmitRequest() {
+    public void testSubmitRequest() throws Exception {
 
         // Expected status code: 200 OK
-        final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+        final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
 
         // Submit the request to the service and store the response.
         String method = ServiceRequestType.READ.httpMethodName();
@@ -487,8 +535,11 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        if(logger.isDebugEnabled()){
+            logger.debug("testSubmitRequest: url=" + url +
+                " status=" + statusCode);
+        }
+        Assert.assertEquals(statusCode, EXPECTED_STATUS);
 
     }
 
@@ -505,10 +556,14 @@ public class AcquisitionServiceTest extends AbstractServiceTest {
         AcquisitionsCommon acquisition = new AcquisitionsCommon();
         acquisition.setAccessionDate("accessionDate-"  + identifier);
         MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
+        OutputPart commonPart = multipart.addPart(acquisition,
+            MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", client.getCommonPartName());
 
-        verbose("to be created, acquisition common ", acquisition, AcquisitionsCommon.class);
+        if(logger.isDebugEnabled()){
+            verbose("to be created, acquisition common ",
+                acquisition, AcquisitionsCommon.class);
+        }
         return multipart;
     }
 }
index 91e5d2276bd09f02ca9801bec94d9eabb88ae1a1..72ebe285d0b2d51d688ed218455b55b75a4958d1 100644 (file)
@@ -56,6 +56,7 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#getServicePathComponent()
         */
+    @Override
        protected String getServicePathComponent() {
                // no need to return anything but null since no auth resources are
                // accessed
@@ -74,8 +75,7 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                                collectionObjectClient.getCommonPartName(), identifier);
 
                if (!collectionObjectClient.isServerSecure()) {
-                       logger
-                                       .warn("set -Dcspace.server.secure=true to run security tests");
+                       logger.warn("set -Dcspace.server.secure=true to run security tests");
                        return;
                }
                collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
@@ -92,7 +92,9 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("create: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("create: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.CREATED
                                .getStatusCode(), "expected "
                                + Response.Status.CREATED.getStatusCode());
@@ -103,7 +105,7 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
        }
 
        /**
-        * Creates the without user.
+        * Creates the collection object instance without user.
         */
        @Test(dependsOnMethods = { "create" })
        public void createWithoutUser() {
@@ -130,14 +132,16 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("createWithoutUser: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("createWithoutUser: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
                                .getStatusCode(), "expected "
                                + Response.Status.UNAUTHORIZED.getStatusCode());
        }
 
        /**
-        * Creates the without password.
+        * Creates the collection object instance without password.
         */
        @Test(dependsOnMethods = { "createWithoutUser" })
        public void createWithoutPassword() {
@@ -164,14 +168,16 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("createWithoutPassword: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("createWithoutPassword: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
                                .getStatusCode(), "expected "
                                + Response.Status.UNAUTHORIZED.getStatusCode());
        }
 
        /**
-        * Creates the with incorrect password.
+        * Creates the collection object instance with incorrect password.
         */
        @Test(dependsOnMethods = { "createWithoutPassword" })
        public void createWithIncorrectPassword() {
@@ -199,14 +205,16 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("createWithIncorrectPassword: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("createWithIncorrectPassword: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
                                .getStatusCode(), "expected "
                                + Response.Status.UNAUTHORIZED.getStatusCode());
        }
 
        /**
-        * Creates the without user password.
+        * Creates the collection object instance without user password.
         */
        @Test(dependsOnMethods = { "createWithoutPassword" })
        public void createWithoutUserPassword() {
@@ -232,14 +240,16 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("createWithoutUserPassword: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("createWithoutUserPassword: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN
                                .getStatusCode(), "expected "
                                + Response.Status.FORBIDDEN.getStatusCode());
        }
 
        /**
-        * Creates the with incorrect user password.
+        * Creates the collection object instance with incorrect user password.
         */
        @Test(dependsOnMethods = { "createWithoutPassword" })
        public void createWithIncorrectUserPassword() {
@@ -266,7 +276,10 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        return;
                }
                ClientResponse<Response> res = collectionObjectClient.create(multipart);
-               verbose("createWithIncorrectUserPassword: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("createWithIncorrectUserPassword: status = " +
+                res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED
                                .getStatusCode(), "expected "
                                + Response.Status.UNAUTHORIZED.getStatusCode());
@@ -297,10 +310,14 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                        logger.error("deleteCollectionObject: caught " + e.getMessage());
                        return;
                }
-               verbose("Calling deleteCollectionObject:" + knownResourceId);
+               if(logger.isDebugEnabled()){
+            logger.debug("Calling deleteCollectionObject:" + knownResourceId);
+        }
                ClientResponse<Response> res = collectionObjectClient
                                .delete(knownResourceId);
-               verbose("deleteCollectionObject: status = " + res.getStatus());
+               if(logger.isDebugEnabled()){
+            logger.debug("deleteCollectionObject: status = " + res.getStatus());
+        }
                Assert.assertEquals(res.getStatus(),
                                Response.Status.OK.getStatusCode(), "expected "
                                                + Response.Status.OK.getStatusCode());
@@ -343,8 +360,10 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
                                MediaType.APPLICATION_XML_TYPE);
                commonPart.getHeaders().add("label", commonPartName);
 
-               verbose("to be created, collectionobject common ", collectionObject,
-                               CollectionobjectsCommon.class);
+               if(logger.isDebugEnabled()){
+            logger.debug("to be created, collectionobject common ",
+                collectionObject, CollectionobjectsCommon.class);
+        }
                return multipart;
        }
 
@@ -352,90 +371,90 @@ public class AuthenticationServiceTest extends AbstractServiceTest {
         * @see org.collectionspace.services.client.test.AbstractServiceTest#createList()
         */
        @Override
-       public void createList() {
+       public void createList() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithEmptyEntityBody()
         */
        @Override
-       public void createWithEmptyEntityBody() {
+       public void createWithEmptyEntityBody() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithMalformedXml()
         */
        @Override
-       public void createWithMalformedXml() {
+       public void createWithMalformedXml() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#createWithWrongXmlSchema()
         */
        @Override
-       public void createWithWrongXmlSchema() {
+       public void createWithWrongXmlSchema() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#read()
         */
        @Override
-       public void read() {
+       public void read() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#readNonExistent()
         */
        @Override
-       public void readNonExistent() {
+       public void readNonExistent() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#readList()
         */
        @Override
-       public void readList() {
+       public void readList() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#update()
         */
        @Override
-       public void update() {
+       public void update() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithEmptyEntityBody()
         */
        @Override
-       public void updateWithEmptyEntityBody() {
+       public void updateWithEmptyEntityBody() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithMalformedXml()
         */
        @Override
-       public void updateWithMalformedXml() {
+       public void updateWithMalformedXml() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#updateWithWrongXmlSchema()
         */
        @Override
-       public void updateWithWrongXmlSchema() {
+       public void updateWithWrongXmlSchema() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#updateNonExistent()
         */
        @Override
-       public void updateNonExistent() {
+       public void updateNonExistent() throws Exception {
        }
 
        /* (non-Javadoc)
         * @see org.collectionspace.services.client.test.AbstractServiceTest#deleteNonExistent()
         */
        @Override
-       public void deleteNonExistent() {
+       public void deleteNonExistent() throws Exception {
        }
 }
index b8faae103cc591388d16487c44be75e9ce3fdb58..4bdfe0463866ebbec6a67836772c9cbfd01fa79a 100644 (file)
@@ -33,7 +33,6 @@ import javax.xml.bind.Marshaller;
 
 import javax.xml.bind.Unmarshaller;
 import org.collectionspace.services.client.TestServiceClient;
-import org.collectionspace.services.common.context.ServiceContext;
 
 import org.jboss.resteasy.client.ClientRequest;
 import org.jboss.resteasy.client.ClientResponse;
@@ -51,16 +50,19 @@ import org.slf4j.LoggerFactory;
  */
 public abstract class AbstractServiceTest implements ServiceTest {
 
-    final Logger logger = LoggerFactory.getLogger(AbstractServiceTest.class);
+    private final Logger logger =
+         LoggerFactory.getLogger(AbstractServiceTest.class);
     // A base-level client, used (only) to obtain the base service URL.
-    protected static final TestServiceClient serviceClient = new TestServiceClient();
+    protected static final TestServiceClient serviceClient =
+        new TestServiceClient();
     // A resource identifier believed to be non-existent in actual use,
     // used when testing service calls that reference non-existent resources.
     protected final String NON_EXISTENT_ID = createNonExistentIdentifier();
     // The HTTP status code expected to be returned in the response,
     // from a request made to a service (where relevant).
     int EXPECTED_STATUS_CODE = 0;
-    // The generic type of service request being tested (e.g. CREATE, UPDATE, DELETE).
+    // The generic type of service request being tested
+    // (e.g. CREATE, UPDATE, DELETE).
     //
     // This makes it possible to check behavior specific to that type of request,
     // such as the set of valid status codes that may be returned.
@@ -81,10 +83,10 @@ public abstract class AbstractServiceTest implements ServiceTest {
     // ---------------------------------------------------------------
     // CRUD tests : CREATE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
-    public void create() {
-        
+    public void create() throws Exception {
     }
 
     protected void setupCreate() {
@@ -92,217 +94,269 @@ public abstract class AbstractServiceTest implements ServiceTest {
     }
     
     protected void setupCreate(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 201 Created
         EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
         // Type of service request being tested
         REQUEST_TYPE = ServiceRequestType.CREATE;
+        // Print a banner identifying the test that will be run.
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     @Override
-    public abstract void createList();
+    public abstract void createList() throws Exception;
 
     // No setup required for createList()
+
     // Failure outcomes
+
     @Override
-    public abstract void createWithEmptyEntityBody();
+    public abstract void createWithEmptyEntityBody()
+        throws Exception;
 
     protected void setupCreateWithEmptyEntityBody() {
        setupCreateWithEmptyEntityBody("CreateWithEmptyEntityBody");
     }
     
     protected void setupCreateWithEmptyEntityBody(String label) {
-        clearSetup(label);
+        clearSetup();
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.CREATE;
-    }
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
+   }
 
     @Override
-    public abstract void createWithMalformedXml();
+    public abstract void createWithMalformedXml() throws Exception;
 
     protected void setupCreateWithMalformedXml() {
        setupCreateWithMalformedXml("CreateWithMalformedXml");
     }
     
     protected void setupCreateWithMalformedXml(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 400 Bad Request
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.CREATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     @Override
-    public abstract void createWithWrongXmlSchema();
+    public abstract void createWithWrongXmlSchema() throws Exception;
 
     protected void setupCreateWithWrongXmlSchema() {
        setupCreateWithWrongXmlSchema("CreateWithWrongXmlSchema");
     }
     
     protected void setupCreateWithWrongXmlSchema(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 400 Bad Request
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.CREATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
-    public abstract void read();
+    public abstract void read() throws Exception;
 
     protected void setupRead() {
        setupRead("Read");
     }
     
     protected void setupRead(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 200 OK
         EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.READ;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // Failure outcomes
     @Override
-    public abstract void readNonExistent();
+    public abstract void readNonExistent() throws Exception;
 
     protected void setupReadNonExistent() {
        setupReadNonExistent("ReadNonExistent");
     }
+
     protected void setupReadNonExistent(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 404 Not Found
         EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.READ;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // ---------------------------------------------------------------
     // CRUD tests : READ (list, or multiple) tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
-    public abstract void readList();
+    public abstract void readList() throws Exception;
 
     protected void setupReadList() {
        setupReadList("ReadList");
     }
     
     protected void setupReadList(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 200 OK
         EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.READ_LIST;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // Failure outcomes
     // None tested at present.
+
     // ---------------------------------------------------------------
     // CRUD tests : UPDATE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
-    // ----------------
     @Override
-    public abstract void update();
+    public abstract void update() throws Exception;
 
     protected void setupUpdate() {
        setupUpdate("Update");
     }
     
     protected void setupUpdate(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 200 OK
         EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.UPDATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // Failure outcomes
     @Override
-    public abstract void updateWithEmptyEntityBody();
+    public abstract void updateWithEmptyEntityBody() throws Exception;
 
     protected void setupUpdateWithEmptyEntityBody() {
        setupUpdateWithEmptyEntityBody("UpdateWithEmptyEntityBody");
     }
     
     protected void setupUpdateWithEmptyEntityBody(String label) {
-        clearSetup(label);
+        clearSetup();
+        // Expected status code: 400 Bad Request
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.UPDATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     @Override
-    public abstract void updateWithMalformedXml();
+    public abstract void updateWithMalformedXml() throws Exception;
 
     protected void setupUpdateWithMalformedXml() {
        setupUpdateWithMalformedXml("UpdateWithMalformedXml");
     }
     
     protected void setupUpdateWithMalformedXml(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 400 Bad Request
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.UPDATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     @Override
-    public abstract void updateWithWrongXmlSchema();
+    public abstract void updateWithWrongXmlSchema() throws Exception;
 
     protected void setupUpdateWithWrongXmlSchema() {
        setupUpdateWithWrongXmlSchema("UpdateWithWrongXmlSchema");
     }
     
     protected void setupUpdateWithWrongXmlSchema(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 400 Bad Request
         EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.UPDATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     @Override
-    public abstract void updateNonExistent();
+    public abstract void updateNonExistent() throws Exception;
 
     protected void setupUpdateNonExistent() {
        setupUpdateNonExistent("UpdateNonExistent");
     }
     
     protected void setupUpdateNonExistent(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 404 Not Found
         EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.UPDATE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // ---------------------------------------------------------------
     // CRUD tests : DELETE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
-    public abstract void delete();
+    public abstract void delete() throws Exception;
 
     protected void setupDelete() {
        setupDelete("Delete");
     }
     
     protected void setupDelete(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 200 OK
         EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.DELETE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // Failure outcomes
     @Override
-    public abstract void deleteNonExistent();
+    public abstract void deleteNonExistent() throws Exception;
 
     protected void setupDeleteNonExistent() {
        setupDeleteNonExistent("DeleteNonExistent");
     }
     
     protected void setupDeleteNonExistent(String label) {
-        clearSetup(label);
+        clearSetup();
         // Expected status code: 404 Not Found
         EXPECTED_STATUS_CODE = Response.Status.NOT_FOUND.getStatusCode();
         REQUEST_TYPE = ServiceRequestType.DELETE;
+        if (logger.isDebugEnabled()) {
+            printBanner(label);
+        }
     }
 
     // ---------------------------------------------------------------
@@ -326,12 +380,9 @@ public abstract class AbstractServiceTest implements ServiceTest {
      * Reinitializes setup values, to help expose any unintended reuse
      * of those values between tests.
      */
-    protected void clearSetup(String testName) {
+    protected void clearSetup() {
         EXPECTED_STATUS_CODE = 0;
         REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;
-        logger.debug("========================================================");
-        logger.debug(" Test = " + testName);
-        logger.debug("========================================================");
     }
 
     /**
@@ -401,8 +452,8 @@ public abstract class AbstractServiceTest implements ServiceTest {
             }
         }catch(Exception e){
             logger.error(
-                    "Exception during HTTP " + method + " request to " + url + ":",
-                    e);
+                "Exception during HTTP " + method + " request to " +
+                url + ":", e);
         }
         return statusCode;
     }
@@ -439,8 +490,8 @@ public abstract class AbstractServiceTest implements ServiceTest {
             }
         }catch(Exception e){
             logger.error(
-                    "Exception during HTTP " + method + " request to " + url + ":",
-                    e);
+                "Exception during HTTP " + method + " request to " +
+                url + ":", e);
         }
         return statusCode;
     }
@@ -456,33 +507,7 @@ public abstract class AbstractServiceTest implements ServiceTest {
         return id;
     }
 
-    protected void verbose(String msg) {
-        if(logger.isDebugEnabled()){
-            logger.debug(msg);
-        }
-    }
-
-    protected 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();
-        }
-    }
-
-    protected void verboseMap(MultivaluedMap map) {
-        for(Object entry : map.entrySet()){
-            MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
-            verbose("    name=" + mentry.getKey() + " value=" + mentry.getValue());
-        }
-    }
-
-    protected String createIdentifier() {
+     protected String createIdentifier() {
         long identifier = System.currentTimeMillis();
         return Long.toString(identifier);
     }
@@ -491,7 +516,8 @@ public abstract class AbstractServiceTest implements ServiceTest {
         return Long.toString(Long.MAX_VALUE);
     }
 
-    protected Object extractPart(MultipartInput input, String label, Class clazz) throws Exception {
+    protected Object extractPart(MultipartInput input, String label,
+        Class clazz) throws Exception {
         Object obj = null;
         for(InputPart part : input.getParts()){
             String partLabel = part.getHeaders().getFirst("label");
@@ -506,7 +532,8 @@ public abstract class AbstractServiceTest implements ServiceTest {
         return obj;
     }
 
-    protected Object getPartObject(String partStr, Class clazz) throws JAXBException {
+    protected Object getPartObject(String partStr, Class clazz)
+        throws JAXBException {
         JAXBContext jc = JAXBContext.newInstance(clazz);
         ByteArrayInputStream bais = null;
         Object obj = null;
@@ -524,6 +551,44 @@ public abstract class AbstractServiceTest implements ServiceTest {
         }
         return obj;
     }
+
+    // @TODO Some of the methods below may be candidates
+    // to be moved to a utilities module, suitable for use
+    // by both client-side and server-side code.
+
+    protected void verbose(String msg) {
+        if(logger.isDebugEnabled()){
+            logger.debug(msg);
+        }
+    }
+
+    protected 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();
+        }
+    }
+
+    protected void verboseMap(MultivaluedMap map) {
+        for(Object entry : map.entrySet()){
+            MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
+            verbose("    name=" + mentry.getKey() + " value=" + mentry.getValue());
+        }
+    }
+
+    private void printBanner(String label) {
+        if(logger.isDebugEnabled()){
+            logger.debug("===================================================");
+            logger.debug(" Test = " + label);
+            logger.debug("===================================================");
+        }
+    }
 }
 
 
index 2b94b032cec772e12fe854477aaa857f75cd4d6d..d878c8432adb1c3c00ee7662264b45057dbaead5 100644 (file)
@@ -55,7 +55,7 @@ public interface ServiceTest {
      *
      * Relied upon by 'read', 'update' and 'delete' tests, below.
      */
-    public void create();
+    public void create() throws Exception;
 
     /**
      * Tests creation of a list of two or more new resources by repeatedly
@@ -63,7 +63,7 @@ public interface ServiceTest {
      *
      * Relied upon by 'read list' tests, below.
      */
-    public void createList();
+    public void createList() throws Exception;
 
     // Failure outcomes
 
@@ -71,20 +71,20 @@ public interface ServiceTest {
      * Tests creation of a resource by submitting
      * an empty entity body (aka empty payload).
      */
-    public void createWithEmptyEntityBody();
+    public void createWithEmptyEntityBody() throws Exception;
 
     /**
      * Tests creation of a resource by submitting
      * a representation with malformed XML data.
      */
-    public void createWithMalformedXml();
+    public void createWithMalformedXml() throws Exception;
 
     /**
      * Tests creation of a resource by submitting
      * a representation in the wrong XML schema
      * (e.g. not matching the object's schema).
      */
-    public void createWithWrongXmlSchema();
+    public void createWithWrongXmlSchema() throws Exception;
 
     // @TODO If feasible, implement a negative (failure)
     // test for creation of duplicate resources.
@@ -99,7 +99,7 @@ public interface ServiceTest {
     /**
      * Tests reading (i.e. retrieval) of a resource.
      */
-    public void read();
+    public void read() throws Exception;
 
     // Failure outcomes
 
@@ -108,7 +108,7 @@ public interface ServiceTest {
      * resource, whose resource identifier does not exist
      * at the specified URL.
      */
-    public void readNonExistent();
+    public void readNonExistent() throws Exception;
 
 
     // ---------------------------------------------------------------
@@ -121,7 +121,7 @@ public interface ServiceTest {
      * Tests reading (i.e. retrieval) of a list of
      * multiple resources.
      */
-    public void readList();
+    public void readList() throws Exception;
 
     // If feasible, implement a test for reading
     // an empty list returned by the service.
@@ -143,7 +143,7 @@ public interface ServiceTest {
     /**
      * Tests updating the content of a resource.
      */
-    public void update();
+    public void update() throws Exception;
 
     // Failure outcomes
 
@@ -151,27 +151,27 @@ public interface ServiceTest {
      * Tests updating the content of a resource
      * by submitting an empty entity body (aka empty payload).
      */
-    public void updateWithEmptyEntityBody();
+    public void updateWithEmptyEntityBody() throws Exception;
 
     /**
      * Tests updating the content of a resource
      * by submitting a representation with malformed
      * XML data.
      */
-    public void updateWithMalformedXml();
+    public void updateWithMalformedXml() throws Exception;
 
     /**
      * Tests updating the content of a resource
      * by submitting a representation in the wrong
      * XML schema (e.g. not matching the object's schema).
      */
-    public void updateWithWrongXmlSchema();
+    public void updateWithWrongXmlSchema() throws Exception;
 
     /**
      * Tests updating the content of a non-existent
      * resource, whose resource identifier does not exist.
      */
-    public void updateNonExistent();
+    public void updateNonExistent() throws Exception;
 
 
     // ---------------------------------------------------------------
@@ -183,7 +183,7 @@ public interface ServiceTest {
     /**
      * Tests deleting a resource.
      */
-    public void delete();
+    public void delete() throws Exception;
 
     // Failure outcomes
 
@@ -191,7 +191,7 @@ public interface ServiceTest {
      * Tests deleting a non-existent resource, whose resource
      * identifier does not exist at the specified URL.
      */
-    public void deleteNonExistent();
+    public void deleteNonExistent() throws Exception;
 
 }
 
index fb04ecc5b43d62495f1b14eaf26787b77cdee62f..19746a564cead89d65b9b2893d2153ddb6d04941 100644 (file)
@@ -39,6 +39,9 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * CollectionObjectServiceTest, carries out tests against a
  * deployed and running CollectionObject Service.
@@ -48,6 +51,9 @@ import org.testng.annotations.Test;
  */
 public class CollectionObjectServiceTest extends AbstractServiceTest {
 
+    private final Logger logger =
+        LoggerFactory.getLogger(CollectionObjectServiceTest.class);
+
     // Instance variables specific to this test.
     private CollectionObjectClient client = new CollectionObjectClient();
     private String knownResourceId = null; 
@@ -63,10 +69,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // ---------------------------------------------------------------
     // CRUD tests : CREATE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
     @Test
-    public void create() {
+    public void create() throws Exception {
 
         // Perform setup, such as initializing the type of service request
         // (e.g. CREATE, DELETE), its valid and expected status codes, and
@@ -87,7 +94,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         // Specifically:
         // Does it fall within the set of valid status codes?
         // Does it exactly match the expected status code?
-        verbose("create: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -95,28 +104,38 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         // Store the ID returned from this create operation
         // for additional tests below.
         knownResourceId = extractId(res);
-        verbose("create: knownResourceId=" + knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: knownResourceId=" + knownResourceId);
+        }
     }
 
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.client.test.AbstractServiceTest#createList()
+        */
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void createList() {
+    public void createList() throws Exception {
         for(int i = 0; i < 3; i++){
             create();
         }
     }
 
     // Failure outcomes
+
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void createWithEmptyEntityBody() {}
-    public void createWithMalformedXml() {}
-    public void createWithWrongXmlSchema() {}
+    @Override
+    public void createWithEmptyEntityBody() throws Exception {}
+    @Override
+    public void createWithMalformedXml() throws Exception {}
+    @Override
+    public void createWithWrongXmlSchema() throws Exception {}
+
 
 /*
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithEmptyEntityBody() {
+    public void createWithEmptyEntityBody() throwsException {
     
         // Perform setup.
         setupCreateWithEmptyEntityBody();
@@ -130,7 +149,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("createWithEmptyEntityBody url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -138,7 +160,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithMalformedXml() {
+    public void createWithMalformedXml() throws Exception {
     
         // Perform setup.
         setupCreateWithMalformedXml();
@@ -152,7 +174,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("createWithMalformedXml url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -160,7 +185,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithWrongXmlSchema() {
+    public void createWithWrongXmlSchema() throws Exception {
     
         // Perform setup.
         setupCreateWithWrongXmlSchema();
@@ -174,7 +199,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("createWithWrongXmlSchema url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -184,10 +212,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void read() {
+    public void read() throws Exception {
 
         // Perform setup.
         setupRead();
@@ -198,26 +227,25 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("read: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("read: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-        //FIXME: remove the following try catch once Aron fixes signatures
-        try{
-            MultipartInput input = (MultipartInput) res.getEntity();
-            CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input,
-                    client.getCommonPartName(), CollectionobjectsCommon.class);
-            Assert.assertNotNull(collectionObject);
-        }catch(Exception e){
-            throw new RuntimeException(e);
-        }
+        
+        MultipartInput input = (MultipartInput) res.getEntity();
+        CollectionobjectsCommon collectionObject =
+            (CollectionobjectsCommon) extractPart(input,
+            client.getCommonPartName(), CollectionobjectsCommon.class);
+        Assert.assertNotNull(collectionObject);
     }
     
     // Failure outcomes
 
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void readNonExistent() {
+    public void readNonExistent() throws Exception {
 
         // Perform setup.
         setupReadNonExistent();
@@ -228,7 +256,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -240,7 +270,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"createList", "read"})
-    public void readList() {
+    public void readList() throws Exception {
         // Perform setup.
         setupReadList();
 
@@ -252,7 +282,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readList: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readList: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -265,13 +297,14 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
             int i = 0;
 
             for(CollectionobjectsCommonList.CollectionObjectListItem item : items){
-                verbose("readList: list-item[" + i + "] csid=" +
+                logger.debug("readList: list-item[" + i + "] csid=" +
                     item.getCsid());
-                verbose("readList: list-item[" + i + "] objectNumber=" +
+                logger.debug("readList: list-item[" + i + "] objectNumber=" +
                     item.getObjectNumber());
-                verbose("readList: list-item[" + i + "] URI=" +
+                logger.debug("readList: list-item[" + i + "] URI=" +
                     item.getUri());
                 i++;
+
             }
         }
     }
@@ -284,68 +317,78 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void update() {
+    public void update() throws Exception {
 
         // Perform setup.
         setupUpdate();
-        try{ //ideally, just remove try-catch and let the exception bubble up
-            // Retrieve an existing resource that we can update.
-            ClientResponse<MultipartInput> res =
-                    client.read(knownResourceId);
-            verbose("update: read status = " + res.getStatus());
-            Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
-            verbose("got object to update with ID: " + knownResourceId);
-            MultipartInput input = (MultipartInput) res.getEntity();
-            CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input,
-                       client.getCommonPartName(), CollectionobjectsCommon.class);
-            Assert.assertNotNull(collectionObject);
-
-            // Update the content of this resource.
-            collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
-            collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
-            verbose("updated object", collectionObject, CollectionobjectsCommon.class);
-            // 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", 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)?
-            verbose("update: status = " + res.getStatus());
-            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
-
-            input = (MultipartInput) res.getEntity();
-            CollectionobjectsCommon updatedCollectionObject =
-                    (CollectionobjectsCommon) extractPart(input,
-                               client.getCommonPartName(), CollectionobjectsCommon.class);
-            Assert.assertNotNull(updatedCollectionObject);
-
-            Assert.assertEquals(updatedCollectionObject.getObjectName(),
-                    collectionObject.getObjectName(),
-                    "Data in updated object did not match submitted data.");
-        }catch(Exception e){
-            e.printStackTrace();
+
+        ClientResponse<MultipartInput> res =
+                client.read(knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("update: read status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+        if(logger.isDebugEnabled()){
+            logger.debug("got object to update with ID: " + knownResourceId);
+        }
+        MultipartInput input = (MultipartInput) res.getEntity();
+        CollectionobjectsCommon collectionObject =
+            (CollectionobjectsCommon) extractPart(input,
+                client.getCommonPartName(), CollectionobjectsCommon.class);
+        Assert.assertNotNull(collectionObject);
+
+        // Update the content of this resource.
+        collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber());
+        collectionObject.setObjectName("updated-" + collectionObject.getObjectName());
+        if(logger.isDebugEnabled()){
+            verbose("updated object", collectionObject,
+                CollectionobjectsCommon.class);
         }
+        // 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", 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)?
+        if(logger.isDebugEnabled()){
+            logger.debug("update: status = " + res.getStatus());
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+        input = (MultipartInput) res.getEntity();
+        CollectionobjectsCommon updatedCollectionObject =
+                (CollectionobjectsCommon) extractPart(input,
+                        client.getCommonPartName(), CollectionobjectsCommon.class);
+        Assert.assertNotNull(updatedCollectionObject);
+
+        Assert.assertEquals(updatedCollectionObject.getObjectName(),
+                collectionObject.getObjectName(),
+                "Data in updated object did not match submitted data.");
+
     }
     
     // Failure outcomes
 
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void updateWithEmptyEntityBody() {}
-    public void updateWithMalformedXml() {}
-    public void updateWithWrongXmlSchema() {}
+    @Override
+    public void updateWithEmptyEntityBody() throws Exception {}
+    @Override
+    public void updateWithMalformedXml() throws Exception {}
+    @Override
+    public void updateWithWrongXmlSchema() throws Exception {}
 
 /*
     @Override
 
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
     
         // Perform setup.
         setupUpdateWithEmptyEntityBody();
@@ -359,7 +402,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("updateWithEmptyEntityBody url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -367,7 +413,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
 
         // Perform setup.
         setupUpdateWithMalformedXml();
@@ -381,7 +427,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("updateWithMalformedXml: url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -389,7 +438,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithWrongXmlSchema() {
+    public void updateWithWrongXmlSchema() throws Exception {
     
         // Perform setup.
         setupUpdateWithWrongXmlSchema();
@@ -403,7 +452,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("updateWithWrongXmlSchema: url=" + url +
+                " status=" + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
             invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -412,7 +464,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"update", "testSubmitRequest"})
-    public void updateNonExistent() {
+    public void updateNonExistent() throws Exception {
 
         // Perform setup.
         setupUpdateNonExistent();
@@ -421,15 +473,19 @@ 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(client.getCommonPartName(), NON_EXISTENT_ID);
+        MultipartOutput multipart =
+            createCollectionObjectInstance(client.getCommonPartName(),
+                NON_EXISTENT_ID);
         ClientResponse<MultipartInput> res =
-                client.update(NON_EXISTENT_ID, multipart);
+            client.update(NON_EXISTENT_ID, multipart);
 
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("updateNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -441,7 +497,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
-    public void delete() {
+    public void delete() throws Exception {
 
         // Perform setup.
         setupDelete();
@@ -452,7 +508,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("delete: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("delete: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -461,7 +519,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"delete"})
-    public void deleteNonExistent() {
+    public void deleteNonExistent() throws Exception {
 
         // Perform setup.
         setupDeleteNonExistent();
@@ -472,7 +530,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("deleteNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("deleteNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -486,10 +546,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
      * of the methods above.
      */
     @Test(dependsOnMethods = {"create", "read"})
-    public void testSubmitRequest() {
+    public void testSubmitRequest() throws Exception {
 
         // Expected status code: 200 OK
-        final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+        final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
 
         // Submit the request to the service and store the response.
         String method = ServiceRequestType.READ.httpMethodName();
@@ -498,8 +558,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        if(logger.isDebugEnabled()){
+            logger.debug("testSubmitRequest: url=" + url +
+                " status=" + statusCode);
+        }
+        Assert.assertEquals(statusCode, EXPECTED_STATUS);
 
     }          
 
@@ -507,21 +570,28 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     // Utility methods used by tests above
     // ---------------------------------------------------------------
 
-    private MultipartOutput createCollectionObjectInstance(String commonPartName, String identifier) {
-        return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier,
-                "objectName-" + identifier);
+    private MultipartOutput createCollectionObjectInstance(String commonPartName,
+        String identifier) {
+        return createCollectionObjectInstance(commonPartName,
+            "objectNumber-" + identifier,
+            "objectName-" + identifier);
     }
 
-    private MultipartOutput createCollectionObjectInstance(String commonPartName, 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);
+        OutputPart commonPart = multipart.addPart(collectionObject,
+            MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", commonPartName);
 
-        verbose("to be created, collectionobject common ", collectionObject, CollectionobjectsCommon.class);
+        if(logger.isDebugEnabled()){
+            verbose("to be created, collectionobject common ",
+               collectionObject, CollectionobjectsCommon.class);
+        }
 
         CollectionObjectNaturalhistory conh = new CollectionObjectNaturalhistory();
         conh.setNhString("test-string");
@@ -530,7 +600,10 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
         OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE);
         nhPart.getHeaders().add("label", getNHPartName());
 
-        verbose("to be created, collectionobject nhistory", conh, CollectionObjectNaturalhistory.class);
+        if(logger.isDebugEnabled()){
+            verbose("to be created, collectionobject nhistory",
+                conh, CollectionObjectNaturalhistory.class);
+        }
         return multipart;
 
     }
index ed6fc894112979d529cc03177a5e5493fba57c35..be6a4bcff567a640b1d60f54556701315d1bafdf 100644 (file)
@@ -38,6 +38,9 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * IntakeServiceTest, carries out tests against a
  * deployed and running Intake Service.
@@ -47,6 +50,9 @@ import org.testng.annotations.Test;
  */
 public class IntakeServiceTest extends AbstractServiceTest {
 
+   private final Logger logger =
+       LoggerFactory.getLogger(IntakeServiceTest.class);
+
     // Instance variables specific to this test.
     private IntakeClient client = new IntakeClient();
     final String SERVICE_PATH_COMPONENT = "intakes";
@@ -58,7 +64,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test
-    public void create() {
+    public void create() throws Exception {
 
         // Perform setup, such as initializing the type of service request
         // (e.g. CREATE, DELETE), its valid and expected status codes, and
@@ -79,7 +85,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
         // Specifically:
         // Does it fall within the set of valid status codes?
         // Does it exactly match the expected status code?
-        verbose("create: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -87,12 +95,14 @@ public class IntakeServiceTest extends AbstractServiceTest {
         // Store the ID returned from this create operation
         // for additional tests below.
         knownResourceId = extractId(res);
-        verbose("create: knownResourceId=" + knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: knownResourceId=" + knownResourceId);
+        }
     }
 
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void createList() {
+    public void createList() throws Exception {
         for(int i = 0; i < 3; i++){
             create();
         }
@@ -101,19 +111,22 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void createWithEmptyEntityBody() {
+    @Override
+    public void createWithEmptyEntityBody() throws Exception {
     }
 
-    public void createWithMalformedXml() {
+    @Override
+    public void createWithMalformedXml() throws Exception {
     }
 
-    public void createWithWrongXmlSchema() {
+    @Override
+    public void createWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithEmptyEntityBody() {
+    public void createWithEmptyEntityBody() throws Exception {
 
     // Perform setup.
     setupCreateWithEmptyEntityBody();
@@ -127,7 +140,10 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithEmptyEntityBody url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -135,7 +151,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithMalformedXml() {
+    public void createWithMalformedXml() throws Exception {
 
     // Perform setup.
     setupCreateWithMalformedXml();
@@ -149,7 +165,10 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithMalformedXml url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -157,7 +176,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithWrongXmlSchema() {
+    public void createWithWrongXmlSchema() throws Exception {
 
     // Perform setup.
     setupCreateWithWrongXmlSchema();
@@ -171,19 +190,23 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithWrongSchema url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void read() {
+    public void read() throws Exception {
 
         // Perform setup.
         setupRead();
@@ -194,25 +217,23 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("read: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("read: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-        //FIXME: remove the following try catch once Aron fixes signatures
-        try{
-            MultipartInput input = (MultipartInput) res.getEntity();
-            IntakesCommon intake = (IntakesCommon) extractPart(input,
-                    client.getCommonPartName(), IntakesCommon.class);
-            Assert.assertNotNull(intake);
-        }catch(Exception e){
-            throw new RuntimeException(e);
-        }
+
+        MultipartInput input = (MultipartInput) res.getEntity();
+        IntakesCommon intake = (IntakesCommon) extractPart(input,
+                client.getCommonPartName(), IntakesCommon.class);
+        Assert.assertNotNull(intake);
     }
 
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void readNonExistent() {
+    public void readNonExistent() throws Exception {
 
         // Perform setup.
         setupReadNonExistent();
@@ -223,7 +244,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -235,7 +258,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void readList() {
+    public void readList() throws Exception {
 
         // Perform setup.
         setupReadList();
@@ -247,7 +270,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readList: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readList: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -259,11 +284,11 @@ public class IntakeServiceTest extends AbstractServiceTest {
                     list.getIntakeListItem();
             int i = 0;
             for(IntakesCommonList.IntakeListItem item : items){
-                verbose("readList: list-item[" + i + "] csid=" +
+                logger.debug("readList: list-item[" + i + "] csid=" +
                         item.getCsid());
-                verbose("readList: list-item[" + i + "] objectNumber=" +
+                logger.debug("readList: list-item[" + i + "] objectNumber=" +
                         item.getEntryNumber());
-                verbose("readList: list-item[" + i + "] URI=" +
+                logger.debug("readList: list-item[" + i + "] URI=" +
                         item.getUri());
                 i++;
             }
@@ -279,73 +304,78 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void update() {
+    public void update() throws Exception {
 
         // Perform setup.
         setupUpdate();
 
-        try{ //ideally, just remove try-catch and let the exception bubble up
-            // Retrieve an existing resource that we can update.
-            ClientResponse<MultipartInput> res =
-                    client.read(knownResourceId);
-            verbose("update: read status = " + res.getStatus());
-            Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-
-            verbose("got object to update with ID: " + knownResourceId);
-            MultipartInput input = (MultipartInput) res.getEntity();
-            IntakesCommon intake = (IntakesCommon) extractPart(input,
-                       client.getCommonPartName(), IntakesCommon.class);
-            Assert.assertNotNull(intake);
-
-            // Update the content of this resource.
-            // Update the content of this resource.
-            intake.setEntryNumber("updated-" + intake.getEntryNumber());
-            intake.setEntryDate("updated-" + intake.getEntryDate());
+        ClientResponse<MultipartInput> res =
+                client.read(knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("update: read status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+        if(logger.isDebugEnabled()){
+            logger.debug("got object to update with ID: " + knownResourceId);
+        }
+        MultipartInput input = (MultipartInput) res.getEntity();
+        IntakesCommon intake = (IntakesCommon) extractPart(input,
+                client.getCommonPartName(), IntakesCommon.class);
+        Assert.assertNotNull(intake);
+
+        // Update the content of this resource.
+        // Update the content of this resource.
+        intake.setEntryNumber("updated-" + intake.getEntryNumber());
+        intake.setEntryDate("updated-" + intake.getEntryDate());
+        if(logger.isDebugEnabled()){
             verbose("to be updated object", intake, IntakesCommon.class);
-            // 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", 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)?
-            verbose("update: status = " + res.getStatus());
-            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
-
-            input = (MultipartInput) res.getEntity();
-            IntakesCommon updatedIntake =
-                    (IntakesCommon) extractPart(input,
-                               client.getCommonPartName(), IntakesCommon.class);
-            Assert.assertNotNull(updatedIntake);
-
-            Assert.assertEquals(updatedIntake.getEntryDate(),
-                    intake.getEntryDate(),
-                    "Data in updated object did not match submitted data.");
-        }catch(Exception e){
-            e.printStackTrace();
         }
+        // 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", 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)?
+        if(logger.isDebugEnabled()){
+            logger.debug("update: status = " + res.getStatus());
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+        input = (MultipartInput) res.getEntity();
+        IntakesCommon updatedIntake =
+                (IntakesCommon) extractPart(input,
+                        client.getCommonPartName(), IntakesCommon.class);
+        Assert.assertNotNull(updatedIntake);
+
+        Assert.assertEquals(updatedIntake.getEntryDate(),
+                intake.getEntryDate(),
+                "Data in updated object did not match submitted data.");
+
     }
 
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void updateWithEmptyEntityBody() {
+    @Override
+    public void updateWithEmptyEntityBody() throws Exception{
     }
-
-    public void updateWithMalformedXml() {
+    @Override
+    public void updateWithMalformedXml() throws Exception {
     }
-
-    public void updateWithWrongXmlSchema() {
+    @Override
+    public void updateWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
 
     // Perform setup.
     setupUpdateWithEmptyEntityBody();
@@ -359,7 +389,10 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithEmptyEntityBody url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -367,7 +400,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
 
     // Perform setup.
     setupUpdateWithMalformedXml();
@@ -381,7 +414,10 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithMalformedXml: url=" + url +
+         " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -389,7 +425,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithWrongXmlSchema() {
+    public void updateWithWrongXmlSchema() throws Exception {
 
     // Perform setup.
     setupUpdateWithWrongXmlSchema();
@@ -403,15 +439,19 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithWrongXmlSchema: url=" + url +
+        " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+
     @Override
     @Test(dependsOnMethods = {"update", "testSubmitRequest"})
-    public void updateNonExistent() {
+    public void updateNonExistent() throws Exception {
 
         // Perform setup.
         setupUpdateNonExistent();
@@ -428,7 +468,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("updateNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -440,7 +482,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
-    public void delete() {
+    public void delete() throws Exception {
 
         // Perform setup.
         setupDelete();
@@ -451,7 +493,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("delete: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("delete: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -460,7 +504,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"delete"})
-    public void deleteNonExistent() {
+    public void deleteNonExistent() throws Exception {
 
         // Perform setup.
         setupDeleteNonExistent();
@@ -471,7 +515,9 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("deleteNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("deleteNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -488,7 +534,7 @@ public class IntakeServiceTest extends AbstractServiceTest {
     public void testSubmitRequest() {
 
         // Expected status code: 200 OK
-        final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+        final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
 
         // Submit the request to the service and store the response.
         String method = ServiceRequestType.READ.httpMethodName();
@@ -497,8 +543,11 @@ public class IntakeServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        if(logger.isDebugEnabled()){
+            logger.debug("testSubmitRequest: url=" + url +
+                " status=" + statusCode);
+        }
+        Assert.assertEquals(statusCode, EXPECTED_STATUS);
 
     }
 
@@ -521,10 +570,13 @@ public class IntakeServiceTest extends AbstractServiceTest {
         intake.setEntryNumber(entryNumber);
         intake.setEntryDate(entryDate);
         MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
+        OutputPart commonPart =
+            multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", client.getCommonPartName());
 
-        verbose("to be created, intake common ", intake, IntakesCommon.class);
+        if(logger.isDebugEnabled()){
+            verbose("to be created, intake common ", intake, IntakesCommon.class);
+        }
 
         return multipart;
     }
index 903634d33f351c56a59235bdc48edcb9af559733..56bb2e5e59027ae69b3f86c174ea466d6f2aa21a 100644 (file)
@@ -39,6 +39,9 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * RelationServiceTest, carries out tests against a
  * deployed and running Relation Service.
@@ -48,6 +51,9 @@ import org.testng.annotations.Test;
  */
 public class RelationServiceTest extends AbstractServiceTest {
 
+   private final Logger logger =
+        LoggerFactory.getLogger(RelationServiceTest.class);
+
     private RelationClient client = new RelationClient();
     final String SERVICE_PATH_COMPONENT = "relations";
     private String knownResourceId = null;
@@ -58,7 +64,7 @@ public class RelationServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test
-    public void create() {
+    public void create() throws Exception {
 
         // Perform setup, such as initializing the type of service request
         // (e.g. CREATE, DELETE), its valid and expected status codes, and
@@ -76,7 +82,9 @@ public class RelationServiceTest extends AbstractServiceTest {
         //
         // Does it fall within the set of valid status codes?
         // Does it exactly match the expected status code?
-        verbose("create: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -84,12 +92,14 @@ public class RelationServiceTest extends AbstractServiceTest {
         // Store the ID returned from this create operation for
         // additional tests below.
         knownResourceId = extractId(res);
-        verbose("create: knownResourceId=" + knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("create: knownResourceId=" + knownResourceId);
+        }
     }
 
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void createList() {
+    public void createList() throws Exception {
         for(int i = 0; i < 3; i++){
             create();
         }
@@ -98,19 +108,19 @@ public class RelationServiceTest extends AbstractServiceTest {
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void createWithEmptyEntityBody() {
+    public void createWithEmptyEntityBody() throws Exception {
     }
 
-    public void createWithMalformedXml() {
+    public void createWithMalformedXml() throws Exception {
     }
 
-    public void createWithWrongXmlSchema() {
+    public void createWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithEmptyEntityBody() {
+    public void createWithEmptyEntityBody() throws Exception {
     
     // Perform setup.
     setupCreateWithEmptyEntityBody();
@@ -124,7 +134,10 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithEmptyEntityBody url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -132,7 +145,7 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithMalformedXml() {
+    public void createWithMalformedXml() throws Exception {
     
     // Perform setup.
     setupCreateWithMalformedXml();
@@ -146,7 +159,10 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("createWithMalformedXml url=" + url +
+            " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -154,7 +170,7 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
-    public void createWithWrongXmlSchema() {
+    public void createWithWrongXmlSchema()n throws Exception {
     
     // Perform setup.
     setupCreateWithWrongXmlSchema();
@@ -168,19 +184,23 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+      logger.debug("createWithWrongSchema url=" + url +
+          " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create"})
-    public void read() {
+    public void read() throws Exception {
 
         // Perform setup.
         setupRead();
@@ -191,28 +211,25 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("read: status = " + statusCode);
+        if(logger.isDebugEnabled()){
+            logger.debug("read: status = " + statusCode);
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
-        // Verify that the resource identifier 
-        //FIXME: remove the following try catch once Aron fixes signatures
-        try{
-            MultipartInput input = (MultipartInput) res.getEntity();
-            RelationsCommon relation = (RelationsCommon) extractPart(input,
-                    client.getCommonPartName(), RelationsCommon.class);
-            Assert.assertNotNull(relation);
-        } catch(Exception e){
-            throw new RuntimeException(e);
-        }
+        // Verify that the resource identifier ...
+        MultipartInput input = (MultipartInput) res.getEntity();
+        RelationsCommon relation = (RelationsCommon) extractPart(input,
+                client.getCommonPartName(), RelationsCommon.class);
+        Assert.assertNotNull(relation);
 
     }
 
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void readNonExistent() {
+    public void readNonExistent() throws Exception {
 
         // Perform setup.
         setupReadNonExistent();
@@ -223,7 +240,9 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -235,7 +254,7 @@ public class RelationServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"createList", "read"})
-    public void readList() {
+    public void readList() throws Exception {
 
         // Perform setup.
         setupReadList();
@@ -247,7 +266,9 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("readList: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("readList: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -259,9 +280,9 @@ public class RelationServiceTest extends AbstractServiceTest {
                     list.getRelationListItem();
             int i = 0;
             for(RelationsCommonList.RelationListItem item : items){
-                verbose("readList: list-item[" + i + "] csid=" +
+                logger.debug("readList: list-item[" + i + "] csid=" +
                         item.getCsid());
-                verbose("readList: list-item[" + i + "] URI=" +
+                logger.debug("readList: list-item[" + i + "] URI=" +
                         item.getUri());
                 i++;
             }
@@ -271,85 +292,92 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Failure outcomes
     // None at present.
+
     // ---------------------------------------------------------------
     // CRUD tests : UPDATE tests
     // ---------------------------------------------------------------
+
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"read"})
-    public void update() {
+    public void update() throws Exception {
 
         // Perform setup.
         setupUpdate();
-        try{
-            // Retrieve an existing resource that we can update.
-            ClientResponse<MultipartInput> res =
-                    client.read(knownResourceId);
-            verbose("update: read status = " + res.getStatus());
-            Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-            verbose("Got object to update with ID: " + knownResourceId);
-            MultipartInput input = (MultipartInput) res.getEntity();
-            RelationsCommon relation = (RelationsCommon) extractPart(input,
-                       client.getCommonPartName(), RelationsCommon.class);
-            Assert.assertNotNull(relation);
-
-            // Update the content of this resource.
-            relation.setDocumentId1("updated-" + relation.getDocumentId1());
-            relation.setDocumentType1("updated-" + relation.getDocumentType1());
-            relation.setDocumentId2("updated-" + relation.getDocumentId2());
-            relation.setDocumentType2("updated-" + relation.getDocumentType2());
+
+        // Retrieve an existing resource that we can update.
+        ClientResponse<MultipartInput> res =
+                client.read(knownResourceId);
+        if(logger.isDebugEnabled()){
+            logger.debug("update: read status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+        if(logger.isDebugEnabled()){
+            logger.debug("Got object to update with ID: " + knownResourceId);
+        }
+        MultipartInput input = (MultipartInput) res.getEntity();
+        RelationsCommon relation = (RelationsCommon) extractPart(input,
+                client.getCommonPartName(), RelationsCommon.class);
+        Assert.assertNotNull(relation);
+
+        // Update the content of this resource.
+        relation.setDocumentId1("updated-" + relation.getDocumentId1());
+        relation.setDocumentType1("updated-" + relation.getDocumentType1());
+        relation.setDocumentId2("updated-" + relation.getDocumentId2());
+        relation.setDocumentType2("updated-" + relation.getDocumentType2());
+        if(logger.isDebugEnabled()){
             verbose("updated object", relation, RelationsCommon.class);
+        }
 
-            // 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", 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)?
-            verbose("update: status = " + res.getStatus());
-            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
-                       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.";
-            Assert.assertEquals(
-                    updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
-            Assert.assertEquals(
-                    updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
-            Assert.assertEquals(
-                    updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
-            Assert.assertEquals(
-                    updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
-        }catch(Exception e){
-            e.printStackTrace();
+        // 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", 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)?
+        if(logger.isDebugEnabled()){
+            logger.debug("update: status = " + res.getStatus());
         }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+        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.";
+        Assert.assertEquals(
+                updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
+        Assert.assertEquals(
+                updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
+        Assert.assertEquals(
+                updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
+        Assert.assertEquals(
+                updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
 
     }
 
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
     }
 
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
     }
 
-    public void updateWithWrongXmlSchema() {
+    public void updateWithWrongXmlSchema() throws Exception {
     }
 
     /*
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithEmptyEntityBody() {
+    public void updateWithEmptyEntityBody() throws Exception {
     
     // Perform setup.
     setupUpdateWithEmptyEntityBody();
@@ -363,7 +391,10 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+       logger.debug("updateWithEmptyEntityBody url=" + url +
+           " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -371,7 +402,7 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithMalformedXml() {
+    public void updateWithMalformedXml() throws Exception {
 
     // Perform setup.
     setupUpdateWithMalformedXml();
@@ -385,7 +416,10 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithMalformedXml: url=" + url +
+        " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -393,7 +427,7 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
-    public void updateWithWrongXmlSchema() {
+    public void updateWithWrongXmlSchema() throws Exception {
     
     // Perform setup.
     setupUpdateWithWrongXmlSchema();
@@ -407,15 +441,19 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     // Check the status code of the response: does it match
     // the expected response(s)?
-    verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
+    if(logger.isDebugEnabled()){
+        logger.debug("updateWithWrongXmlSchema: url=" + url +
+        " status=" + statusCode);
+     }
     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
      */
+
     @Override
     @Test(dependsOnMethods = {"update", "testSubmitRequest"})
-    public void updateNonExistent() {
+    public void updateNonExistent() throws Exception {
 
         // Perform setup.
         setupUpdateNonExistent();
@@ -430,7 +468,9 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("updateNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("updateNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -442,7 +482,7 @@ public class RelationServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
-    public void delete() {
+    public void delete() throws Exception {
 
         // Perform setup.
         setupDelete();
@@ -453,7 +493,9 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("delete: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("delete: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -462,7 +504,7 @@ public class RelationServiceTest extends AbstractServiceTest {
     // Failure outcomes
     @Override
     @Test(dependsOnMethods = {"delete"})
-    public void deleteNonExistent() {
+    public void deleteNonExistent() throws Exception {
 
         // Perform setup.
         setupDeleteNonExistent();
@@ -473,7 +515,9 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("deleteNonExistent: status = " + res.getStatus());
+        if(logger.isDebugEnabled()){
+            logger.debug("deleteNonExistent: status = " + res.getStatus());
+        }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@@ -497,7 +541,7 @@ public class RelationServiceTest extends AbstractServiceTest {
     public void testSubmitRequest() {
 
         // Expected status code: 200 OK
-        final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
+        final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
 
         // Submit the request to the service and store the response.
         String method = ServiceRequestType.READ.httpMethodName();
@@ -506,8 +550,11 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Check the status code of the response: does it match
         // the expected response(s)?
-        verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        if(logger.isDebugEnabled()){
+            logger.debug("testSubmitRequest: url=" + url +
+                " status=" + statusCode);
+        }
+        Assert.assertEquals(statusCode, EXPECTED_STATUS);
 
     }
 
@@ -524,10 +571,13 @@ public class RelationServiceTest extends AbstractServiceTest {
         fillRelation(relation, identifier);
 
         MultipartOutput multipart = new MultipartOutput();
-        OutputPart commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
+        OutputPart commonPart =
+                multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
         commonPart.getHeaders().add("label", client.getCommonPartName());
-        verbose("to be created, relation common ", relation, RelationsCommon.class);
-
+        if(logger.isDebugEnabled()){
+          verbose("to be created, relation common ", relation,
+              RelationsCommon.class);
+        }
         return multipart;
     }