From a8343b61559c1e34de7b80a532b4e0e9d1dba632 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 9 Sep 2009 23:13:46 +0000 Subject: [PATCH] CSPACE-424: Remove unneeded, now failing createNull() test from client test framework, three service tests. --- .../client/test/AbstractServiceTest.java | 49 +++++++++++++------ .../services/client/test/ServiceTest.java | 6 --- .../test/CollectionObjectServiceTest.java | 20 ++++---- .../client/test/IntakeServiceTest.java | 20 ++++---- .../client/test/RelationServiceTest.java | 20 ++++---- 5 files changed, 62 insertions(+), 53 deletions(-) diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java index 1e379820f..e4e42d5d3 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTest.java @@ -83,7 +83,6 @@ public abstract class AbstractServiceTest implements ServiceTest { XML_DECLARATION + "wrong schema contents"; - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -108,12 +107,6 @@ public abstract class AbstractServiceTest implements ServiceTest { // Failure outcomes - @Override - public void createNull() { - } - - // No setup required for createNull() - @Override public abstract void createWithMalformedXml(); @@ -335,8 +328,17 @@ public abstract class AbstractServiceTest implements ServiceTest { return getServiceRootURL() + "/" + resourceIdentifier; } - // @TODO Add Javadoc comments to all methods requiring them, below. - + /** + * Submits an HTTP request to a specified URL, and returns the + * status code of the response. Currently accepts GET and DELETE + * requests. + * + * @param method An HTTP method. + * + * @param url A String representation of a URL. + * + * @return The status code received in the HTTP response. + */ protected int submitRequest(String method, String url) { int statusCode = 0; try { @@ -358,28 +360,47 @@ public abstract class AbstractServiceTest implements ServiceTest { return statusCode; } - protected int submitRequest(String method, String url, String entityStr) { + /** + * Submits an HTTP request to a specified URL, with the submitted + * entity body, and returns the status code of the response. + * Currently accepts POST and PUT requests. + * + * @param method An HTTP method. + * + * @param url A String representation of a URL. + * + * @param mediaType The media type of the entity body to be submitted. + * + * @param entity The contents of the entity body to be submitted. + * + * @return The status code received in the HTTP response. + */ + protected int submitRequest(String method, String url, + String mediaType, String entityStr) { int statusCode = 0; try { ClientRequest request = new ClientRequest(url); - request.body(MediaType.APPLICATION_XML, entityStr); + request.body(mediaType, entityStr); if (method.equals(javax.ws.rs.HttpMethod.POST)) { - ClientResponse res = request.post(); + ClientResponse res = request.post(java.lang.String.class); statusCode = res.getStatus(); } else if (method.equals(javax.ws.rs.HttpMethod.PUT)) { - ClientResponse res = request.put(); + ClientResponse res = request.put(java.lang.String.class); statusCode = res.getStatus(); } else { // Do nothing - leave status code at default value. } } catch (Exception e) { logger.error( - "Exception during HTTP " + method + " request to " + url + " :", + "Exception during HTTP " + method + " request to " + url + ":", e); } return statusCode; } + // @TODO Add Javadoc comments to all methods requiring them, below. + + protected String extractId(ClientResponse res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java index 751fbf520..beebd5bff 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/ServiceTest.java @@ -52,12 +52,6 @@ public interface ServiceTest { // Failure outcomes - /** - * Tests creation of a null resource via the - * Java Client Library. - */ - public void createNull(); - /** * Tests creation of a resource by submitting * a representation with malformed XML data. 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 bfaef0dc3..dae79c9d1 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 @@ -24,6 +24,7 @@ package org.collectionspace.services.client.test; import java.util.List; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -99,13 +100,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes - @Override - @Test(dependsOnMethods = {"create"}, - expectedExceptions = IllegalArgumentException.class) - public void createNull() { - ClientResponse res = client.create(null); - } - // Placeholders until the two tests below can be uncommented. // See Issue CSPACE-401. public void createWithMalformedXml() {} @@ -122,8 +116,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -143,8 +138,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -317,7 +313,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, entity); + String mediaType = MediaType.APPLICATION_XML; + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -337,8 +334,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java index 24e28c8d9..d0cf49e0b 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java @@ -24,6 +24,7 @@ package org.collectionspace.services.client.test; import java.util.List; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -99,13 +100,6 @@ public class IntakeServiceTest extends AbstractServiceTest { // Failure outcomes - @Override - @Test(dependsOnMethods = {"create"}, - expectedExceptions = IllegalArgumentException.class) - public void createNull() { - ClientResponse res = client.create(null); - } - // Placeholders until the two tests below can be uncommented. // See Issue CSPACE-401. public void createWithMalformedXml() {} @@ -122,8 +116,9 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -143,8 +138,9 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -314,8 +310,9 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; final String entity = MALFORMED_XML_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -335,8 +332,9 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 37502c389..d8fb8ce48 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -24,6 +24,7 @@ package org.collectionspace.services.client.test; import java.util.List; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -97,13 +98,6 @@ public class RelationServiceTest extends AbstractServiceTest { // Failure outcomes - @Override - @Test(dependsOnMethods = {"create"}, - expectedExceptions = IllegalArgumentException.class) - public void createNull() { - ClientResponse res = client.create(null); - } - // Placeholders until the two tests below can be uncommented. // See Issue CSPACE-401. public void createWithMalformedXml() {} @@ -120,8 +114,9 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = MALFORMED_XML_DATA; // Constant from base class. - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -141,8 +136,9 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -326,8 +322,9 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? @@ -347,8 +344,9 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class. - int statusCode = submitRequest(method, url, entity); + int statusCode = submitRequest(method, url, mediaType, entity); // Check the status code of the response: does it match // the expected response(s)? -- 2.47.3