From 962ffa9bc0f2f6955fe4abcb6c51f908c37e8420 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 27 Aug 2009 00:11:09 +0000 Subject: [PATCH] CSPACE-360,CSPACE-384: More minor code cleanup, including adding missing annotations and removing superfluous super calls. --- .../client/test/AbstractServiceTest.java | 23 +++++---- .../test/CollectionObjectServiceTest.java | 48 ++++++++++--------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/AbstractServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/AbstractServiceTest.java index dd9d18cf2..ed763da47 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/AbstractServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/AbstractServiceTest.java @@ -62,15 +62,21 @@ public abstract class AbstractServiceTest implements ServiceTest { final Logger logger = LoggerFactory.getLogger(AbstractServiceTest.class); - // Currently used for performing several negative (failure) tests. + // An HTTP client, used for performing several negative (failure) tests. // - // @TODO To be replaced with RESTeasy's ClientRequest, per Issue CSPACE-386. + // @TODO To be replaced with RESTeasy's ClientRequest (a higher-level API + // that is based on HttpClient), per Issue CSPACE-386. protected HttpClient httpClient = new HttpClient(); - // Used (only) to obtain the base service URL. - private final TestServiceClient serviceClient = new TestServiceClient(); + // A base-level client, used (only) to obtain the base service URL. + private static final TestServiceClient serviceClient = new TestServiceClient(); - // The status code expected to be returned by a test method (where relevant). + // 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). @@ -79,7 +85,6 @@ public abstract class AbstractServiceTest implements ServiceTest { // such as the set of valid status codes that may be returned. ServiceRequestType REQUEST_TYPE = ServiceRequestType.NON_EXISTENT; - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -345,12 +350,14 @@ public abstract class AbstractServiceTest implements ServiceTest { contents = ""; } StringRequestEntity entity = null; - final String XML_DECLARATION = ""; + final String XML_DECLARATION = + ""; final String XML_CONTENT_TYPE=MediaType.APPLICATION_XML; final String UTF8_CHARSET_NAME = "UTF-8"; try { entity = - new StringRequestEntity(XML_DECLARATION + contents, XML_CONTENT_TYPE, UTF8_CHARSET_NAME); + new StringRequestEntity( + XML_DECLARATION + contents, XML_CONTENT_TYPE, UTF8_CHARSET_NAME); } catch (UnsupportedEncodingException e) { logger.error("Unsupported character encoding error: ", e); } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index b690bce97..a96b7b55b 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -53,9 +53,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Instance variables specific to this test. private CollectionObjectClient client = new CollectionObjectClient(); - - // Instance variables common to all entity service test classes. - private final String NON_EXISTENT_ID = createNonExistentIdentifier(); + final String SERVICE_PATH_COMPONENT = "collectionobjects"; private String knownObjectId = null; // --------------------------------------------------------------- @@ -70,7 +68,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Perform setup, such as initializing the type of service request // and its valid and expected status codes. - super.setupCreate(); + setupCreate(); // Submit the request to the service and store the response. String identifier = createIdentifier(); @@ -112,7 +110,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void createWithMalformedXml() { // Perform setup. - super.setupCreateWithMalformedXml(); + setupCreateWithMalformedXml(); // Submit the request to the service and store the response. String url = getServiceRootURL(); @@ -134,7 +132,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void createWithWrongXmlSchema() { // Perform setup. - super.setupCreateWithWrongXmlSchema(); + setupCreateWithWrongXmlSchema(); // Submit the request to the service and store the response. String url = getServiceRootURL(); @@ -161,7 +159,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void read() { // Perform setup. - super.setupRead(); + setupRead(); // Submit the request to the service and store the response. ClientResponse res = @@ -180,7 +178,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void readNonExistent() { // Perform setup. - super.setupReadNonExistent(); + setupReadNonExistent(); // Submit the request to the service and store the response. ClientResponse res = @@ -206,7 +204,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void readList() { // Perform setup. - super.setupReadList(); + setupReadList(); // Submit the request to the service and store the response. ClientResponse res = client.getCollectionObjectList(); @@ -251,7 +249,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void update() { // Perform setup. - super.setupUpdate(); + setupUpdate(); // Retrieve an existing resource that we can update. ClientResponse res = @@ -289,7 +287,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { public void updateWithMalformedXml() { // Perform setup. - super.setupUpdateWithMalformedXml(); + setupUpdateWithMalformedXml(); // Submit the request to the service and store the response. String url = getResourceURL(knownObjectId); @@ -306,11 +304,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + @Override @Test(dependsOnMethods = {"create", "testSubmitRequest"}) // , "createWithMalformedXml"}) public void updateWithWrongXmlSchema() { // Perform setup. - super.setupUpdateWithWrongXmlSchema(); + setupUpdateWithWrongXmlSchema(); // Submit the request to the service and store the response. String url = getResourceURL(knownObjectId); @@ -326,11 +325,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + @Override @Test(dependsOnMethods = {"update"}) public void updateNonExistent() { // Perform setup. - super.setupUpdateNonExistent(); + setupUpdateNonExistent(); // Submit the request to the service and store the response. // Note: The ID used in this 'create' call may be arbitrary. @@ -354,12 +354,13 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Success outcomes + @Override @Test(dependsOnMethods = {"create", "read", "testSubmitRequest", "update"}) public void delete() { // Perform setup. - super.setupDelete(); + setupDelete(); // Submit the request to the service and store the response. ClientResponse res = client.deleteCollectionObject(knownObjectId); @@ -374,11 +375,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes + @Override @Test(dependsOnMethods = {"delete"}) public void deleteNonExistent() { // Perform setup. - super.setupDeleteNonExistent(); + setupDeleteNonExistent(); // Submit the request to the service and store the response. ClientResponse res = @@ -421,6 +423,14 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + + @Override + public String getServicePathComponent() { + // @TODO Determine if it is possible to obtain this value programmatically. + // We set this in an annotation in the CollectionObjectProxy interface, for instance. + // We also set service-specific constants in each service module. + return SERVICE_PATH_COMPONENT; + } private CollectionObject createCollectionObject(String identifier) { CollectionObject collectionObject = createCollectionObject("objectNumber-" + identifier, @@ -435,13 +445,5 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { return collectionObject; } - @Override - public String getServicePathComponent() { - // @TODO Determine if it is possible to obtain this value programmatically. - // We set this in an annotation in the CollectionObjectProxy interface, for instance. - // We also set service-specific constants in each service module. - final String SERVICE_PATH_COMPONENT = "collectionobjects"; - return SERVICE_PATH_COMPONENT; - } } -- 2.47.3