From 5ae498cf817bee224d726149a264aabba92a82ed Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 9 Sep 2009 23:58:04 +0000 Subject: [PATCH] CSPACE-424,CSPACE-401: Added (currently commented-out) negative tests of create and update with empty payload to client test framework, three service tests. --- .../client/test/AbstractServiceTest.java | 18 +++++++ .../services/client/test/ServiceTest.java | 12 +++++ .../test/CollectionObjectServiceTest.java | 50 ++++++++++++++++++- .../client/test/IntakeServiceTest.java | 50 ++++++++++++++++++- .../client/test/RelationServiceTest.java | 50 ++++++++++++++++++- 5 files changed, 174 insertions(+), 6 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 e4e42d5d3..63dea9bde 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 @@ -107,6 +107,15 @@ public abstract class AbstractServiceTest implements ServiceTest { // Failure outcomes + @Override + public abstract void createWithEmptyEntityBody(); + + protected void setupCreateWithEmptyEntityBody() { + clearSetup(); + EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); + REQUEST_TYPE = ServiceRequestType.CREATE; + } + @Override public abstract void createWithMalformedXml(); @@ -197,6 +206,15 @@ public abstract class AbstractServiceTest implements ServiceTest { // Failure outcomes + @Override + public abstract void updateWithEmptyEntityBody(); + + protected void setupUpdateWithEmptyEntityBody() { + clearSetup(); + EXPECTED_STATUS_CODE = Response.Status.BAD_REQUEST.getStatusCode(); + REQUEST_TYPE = ServiceRequestType.UPDATE; + } + @Override public abstract void updateWithMalformedXml(); 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 beebd5bff..8305cae34 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,6 +52,12 @@ public interface ServiceTest { // Failure outcomes + /** + * Tests creation of a resource by submitting + * an empty entity body (aka empty payload). + */ + public void createWithEmptyEntityBody(); + /** * Tests creation of a resource by submitting * a representation with malformed XML data. @@ -126,6 +132,12 @@ public interface ServiceTest { // Failure outcomes + /** + * Tests updating the content of a resource + * by submitting an empty entity body (aka empty payload). + */ + public void updateWithEmptyEntityBody(); + /** * Tests updating the content of a resource * by submitting a representation with malformed 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 dae79c9d1..8ea4c8488 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 @@ -100,12 +100,35 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void createWithEmptyEntityBody() {} public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody() { + + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml() { @@ -296,12 +319,35 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void updateWithEmptyEntityBody() {} public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody() { + + // Perform setup. + setupUpdateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithMalformedXml() { 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 d0cf49e0b..28c937a9a 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 @@ -100,12 +100,35 @@ public class IntakeServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void createWithEmptyEntityBody() {} public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody() { + + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml() { @@ -294,12 +317,35 @@ public class IntakeServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void updateWithEmptyEntityBody() {} public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody() { + + // Perform setup. + setupUpdateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithMalformedXml() { 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 d8fb8ce48..43fa7d9e0 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 @@ -98,12 +98,35 @@ public class RelationServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void createWithEmptyEntityBody() {} public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody() { + + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "testSubmitRequest"}) public void createWithMalformedXml() { @@ -306,12 +329,35 @@ public class RelationServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. + // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + public void updateWithEmptyEntityBody() {} public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} /* + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody() { + + // Perform setup. + setupUpdateWithEmptyEntityBody(); + + // 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 = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + @Override @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) public void updateWithMalformedXml() { -- 2.47.3