From: Aron Roberts Date: Wed, 2 Sep 2009 23:49:01 +0000 (+0000) Subject: CSPACE-360: Minor code cleanup within, and for consistency among, CollectionObject... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=95aa4c98badd9de2c702c97f03af2b7550c0e8ce;p=tmp%2Fjakarta-migration.git CSPACE-360: Minor code cleanup within, and for consistency among, CollectionObject, Intake and Relation service tests. --- 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 e590e6504..bfaef0dc3 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 @@ -49,7 +49,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Instance variables specific to this test. private CollectionObjectClient client = new CollectionObjectClient(); final String SERVICE_PATH_COMPONENT = "collectionobjects"; - private String knownObjectId = null; + private String knownResourceId = null; // --------------------------------------------------------------- // CRUD tests : CREATE tests @@ -68,12 +68,15 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String identifier = createIdentifier(); - CollectionObject collectionObject = createCollectionObject(identifier); + CollectionObject collectionObject = + createCollectionObjectInstance(identifier); ClientResponse res = client.create(collectionObject); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? // + // Specifically: // Does it fall within the set of valid status codes? // Does it exactly match the expected status code? verbose("create: status = " + statusCode); @@ -81,8 +84,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the ID returned from this create operation for additional tests below. - knownObjectId = extractId(res); + // Store the ID returned from this create operation + // for additional tests below. + knownResourceId = extractId(res); } @Override @@ -96,12 +100,14 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes @Override - @Test(dependsOnMethods = {"create"}, expectedExceptions = IllegalArgumentException.class) + @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. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} @@ -116,10 +122,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. + final String entity = MALFORMED_XML_DATA; // Constant from base class. int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithMalformedXml url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -139,7 +146,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { final String entity = WRONG_XML_SCHEMA_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithWrongSchema url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -161,10 +169,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { setupRead(); // Submit the request to the service and store the response. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("read: status = " + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -184,7 +193,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { ClientResponse res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -210,7 +220,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { CollectionObjectList list = res.getEntity(); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readList: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -223,9 +234,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { list.getCollectionObjectListItem(); int i = 0; for(CollectionObjectList.CollectionObjectListItem item : items){ - verbose("readList: list-item[" + i + "] csid=" + item.getCsid()); - verbose("readList: list-item[" + i + "] objectNumber=" + item.getObjectNumber()); - verbose("readList: list-item[" + i + "] URI=" + item.getUri()); + verbose("readList: list-item[" + i + "] csid=" + + item.getCsid()); + verbose("readList: list-item[" + i + "] objectNumber=" + + item.getObjectNumber()); + verbose("readList: list-item[" + i + "] URI=" + + item.getUri()); i++; } } @@ -251,30 +265,33 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { setupUpdate(); // Retrieve an existing resource that we can update. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); verbose("read: status = " + res.getStatus()); Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); CollectionObject collectionObject = res.getEntity(); - verbose("Got object to update with ID: " + knownObjectId, + verbose("Got object to update with ID: " + knownResourceId, collectionObject, CollectionObject.class); // Update the content of this resource. - //collectionObject.setCsid("updated-" + knownObjectId); - collectionObject.setObjectNumber("updated-" + collectionObject.getObjectNumber()); - collectionObject.setObjectName("updated-" + collectionObject.getObjectName()); + collectionObject.setObjectNumber("updated-" + + collectionObject.getObjectNumber()); + collectionObject.setObjectName("updated-" + + collectionObject.getObjectName()); // Submit the request to the service and store the response. - res = client.update(knownObjectId, collectionObject); + res = client.update(knownResourceId, collectionObject); int statusCode = res.getStatus(); - CollectionObject updatedObject = res.getEntity(); - // Check the status code of the response: does it match the expected response(s)? + // 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); - // Check the contents of the response: does it match what was submitted? + // Check the contents of the response: does it match + // what was submitted? + CollectionObject updatedObject = res.getEntity(); verbose("update: ", updatedObject, CollectionObject.class); Assert.assertEquals(updatedObject.getObjectName(), collectionObject.getObjectName(), @@ -283,7 +300,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. See Issue CSPACE-401. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} @@ -297,11 +315,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. + String url = getResourceURL(knownResourceId); + final String entity = MALFORMED_XML_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -317,11 +336,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); - final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class. + String url = getResourceURL(knownResourceId); + final String entity = WRONG_XML_SCHEMA_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -339,12 +359,13 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. - CollectionObject collectionObject = createCollectionObject(NON_EXISTENT_ID); + CollectionObject collectionObject = createCollectionObjectInstance(NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, collectionObject); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -366,10 +387,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { setupDelete(); // Submit the request to the service and store the response. - ClientResponse res = client.delete(knownObjectId); + ClientResponse res = client.delete(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("delete: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -389,7 +411,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { ClientResponse res = client.delete(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("deleteNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -413,10 +436,11 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownObjectId); + String url = getResourceURL(knownResourceId); int statusCode = submitRequest(method, url); - // Check the status code of the response: does it match the expected response(s)? + // 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); @@ -438,15 +462,16 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { return SERVICE_PATH_COMPONENT; } - private CollectionObject createCollectionObject(String identifier) { + private CollectionObject createCollectionObjectInstance(String identifier) { CollectionObject collectionObject = - createCollectionObject( + createCollectionObjectInstance( "objectNumber-" + identifier, "objectName-" + identifier); return collectionObject; } - private CollectionObject createCollectionObject(String objectNumber, String objectName) { + private CollectionObject createCollectionObjectInstance( + String objectNumber, String objectName) { CollectionObject collectionObject = new CollectionObject(); collectionObject.setObjectNumber(objectNumber); collectionObject.setObjectName(objectName); 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 b57b18564..24e28c8d9 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 @@ -41,15 +41,15 @@ import org.testng.annotations.Test; * IntakeServiceTest, carries out tests against a * deployed and running Intake Service. * - * $LastChangedRevision: 511 $ - * $LastChangedDate: 2009-08-06 20:16:16 +0000 (Thu, 06 Aug 2009) $ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class IntakeServiceTest extends AbstractServiceTest { // Instance variables specific to this test. private IntakeClient client = new IntakeClient(); final String SERVICE_PATH_COMPONENT = "intakes"; - private String knownObjectId = null; + private String knownResourceId = null; // --------------------------------------------------------------- @@ -69,12 +69,14 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String identifier = createIdentifier(); - Intake intake = createIntake(identifier); + Intake intake = createIntakeInstance(identifier); ClientResponse res = client.create(intake); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? // + // Specifically: // Does it fall within the set of valid status codes? // Does it exactly match the expected status code? verbose("create: status = " + statusCode); @@ -82,8 +84,9 @@ public class IntakeServiceTest extends AbstractServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the ID returned from this create operation for additional tests below. - knownObjectId = extractId(res); + // Store the ID returned from this create operation for + // additional tests below. + knownResourceId = extractId(res); } @Override @@ -97,12 +100,14 @@ public class IntakeServiceTest extends AbstractServiceTest { // Failure outcomes @Override - @Test(dependsOnMethods = {"create"}, expectedExceptions = IllegalArgumentException.class) + @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. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} @@ -117,10 +122,11 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. + final String entity = MALFORMED_XML_DATA; // Constant from base class. int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithMalformedXml url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -140,7 +146,8 @@ public class IntakeServiceTest extends AbstractServiceTest { final String entity = WRONG_XML_SCHEMA_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithWrongSchema url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -162,10 +169,11 @@ public class IntakeServiceTest extends AbstractServiceTest { setupRead(); // Submit the request to the service and store the response. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("read: status = " + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -185,7 +193,8 @@ public class IntakeServiceTest extends AbstractServiceTest { ClientResponse res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -211,7 +220,8 @@ public class IntakeServiceTest extends AbstractServiceTest { IntakeList list = res.getEntity(); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readList: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -224,9 +234,12 @@ public class IntakeServiceTest extends AbstractServiceTest { list.getIntakeListItem(); int i = 0; for(IntakeList.IntakeListItem item : items){ - verbose("readList: list-item[" + i + "] csid=" + item.getCsid()); - verbose("readList: list-item[" + i + "] objectNumber=" + item.getEntryNumber()); - verbose("readList: list-item[" + i + "] URI=" + item.getUri()); + verbose("readList: list-item[" + i + "] csid=" + + item.getCsid()); + verbose("readList: list-item[" + i + "] objectNumber=" + + item.getEntryNumber()); + verbose("readList: list-item[" + i + "] URI=" + + item.getUri()); i++; } } @@ -252,11 +265,11 @@ public class IntakeServiceTest extends AbstractServiceTest { setupUpdate(); // Retrieve an existing resource that we can update. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); verbose("read: status = " + res.getStatus()); Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); Intake intake = res.getEntity(); - verbose("Got object to update with ID: " + knownObjectId, + verbose("Got object to update with ID: " + knownResourceId, intake, Intake.class); // Update the content of this resource. @@ -264,17 +277,19 @@ public class IntakeServiceTest extends AbstractServiceTest { intake.setEntryDate("updated-" + intake.getEntryDate()); // Submit the request to the service and store the response. - res = client.update(knownObjectId, intake); + res = client.update(knownResourceId, intake); int statusCode = res.getStatus(); Intake updatedObject = res.getEntity(); - // Check the status code of the response: does it match the expected response(s)? + // 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); - // Check the contents of the response: does it match what was submitted? + // Check the contents of the response: does it match + // what was submitted? verbose("update: ", updatedObject, Intake.class); Assert.assertEquals(updatedObject.getEntryDate(), intake.getEntryDate(), @@ -283,7 +298,8 @@ public class IntakeServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. See Issue CSPACE-401. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} @@ -297,11 +313,12 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. + String url = getResourceURL(knownResourceId); + final String entity = MALFORMED_XML_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -317,11 +334,12 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); - final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class. + String url = getResourceURL(knownResourceId); + final String entity = WRONG_XML_SCHEMA_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -339,12 +357,13 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. - Intake intake = createIntake(NON_EXISTENT_ID); + Intake intake = createIntakeInstance(NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, intake); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -366,10 +385,11 @@ public class IntakeServiceTest extends AbstractServiceTest { setupDelete(); // Submit the request to the service and store the response. - ClientResponse res = client.delete(knownObjectId); + ClientResponse res = client.delete(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("delete: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -389,7 +409,8 @@ public class IntakeServiceTest extends AbstractServiceTest { ClientResponse res = client.delete(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("deleteNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -413,10 +434,11 @@ public class IntakeServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownObjectId); + String url = getResourceURL(knownResourceId); int statusCode = submitRequest(method, url); - // Check the status code of the response: does it match the expected response(s)? + // 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); @@ -428,25 +450,18 @@ public class IntakeServiceTest extends AbstractServiceTest { @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, which might also - // return this value. return SERVICE_PATH_COMPONENT; } - private Intake createIntake(String identifier) { + private Intake createIntakeInstance(String identifier) { Intake intake = - createIntake( + createIntakeInstance( "entryNumber-" + identifier, "entryDate-" + identifier); return intake; } - private Intake createIntake(String entryNumber, String entryDate) { + private Intake createIntakeInstance(String entryNumber, String entryDate) { Intake intake = new Intake(); intake.setEntryNumber(entryNumber); intake.setEntryDate(entryDate); 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 e0d9fde1b..37502c389 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 @@ -1,3 +1,26 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.collectionspace.services.client.test; import java.util.List; @@ -15,18 +38,18 @@ import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; -import org.collectionspace.services.common.relation.RelationJAXBSchema; - /** - * A RelationNuxeoServiceTest. + * RelationServiceTest, carries out tests against a + * deployed and running Relation Service. * - * @version $Revision:$ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class RelationServiceTest extends AbstractServiceTest { private RelationClient client = new RelationClient(); final String SERVICE_PATH_COMPONENT = "relations"; - private String knownObjectId = null; + private String knownResourceId = null; // --------------------------------------------------------------- // CRUD tests : CREATE tests @@ -44,13 +67,13 @@ public class RelationServiceTest extends AbstractServiceTest { setupCreate(); // Submit the request to the service and store the response. - Relation relation = new Relation(); String identifier = createIdentifier(); - fillRelation(relation, identifier); + Relation relation = createRelationInstance(identifier); ClientResponse res = client.create(relation); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? // // Does it fall within the set of valid status codes? // Does it exactly match the expected status code? @@ -59,8 +82,9 @@ public class RelationServiceTest extends AbstractServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the ID returned from this create operation for additional tests below. - knownObjectId = extractId(res); + // Store the ID returned from this create operation for + // additional tests below. + knownResourceId = extractId(res); } @Override @@ -74,12 +98,14 @@ public class RelationServiceTest extends AbstractServiceTest { // Failure outcomes @Override - @Test(dependsOnMethods = {"create"}, expectedExceptions = IllegalArgumentException.class) + @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. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void createWithMalformedXml() {} public void createWithWrongXmlSchema() {} @@ -94,10 +120,11 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); String url = getServiceRootURL(); - final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. + final String entity = MALFORMED_XML_DATA; // Constant from base class. int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithMalformedXml url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -117,7 +144,8 @@ public class RelationServiceTest extends AbstractServiceTest { final String entity = WRONG_XML_SCHEMA_DATA; int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("createWithWrongSchema url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -140,17 +168,19 @@ public class RelationServiceTest extends AbstractServiceTest { setupRead(); // Submit the request to the service and store the response. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("read: status = " + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + // Verify that the resource identifier Relation returnedRelation = res.getEntity(); - Assert.assertEquals(returnedRelation.getCsid(), knownObjectId); + Assert.assertEquals(returnedRelation.getCsid(), knownResourceId); } @@ -167,7 +197,8 @@ public class RelationServiceTest extends AbstractServiceTest { ClientResponse res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -193,7 +224,8 @@ public class RelationServiceTest extends AbstractServiceTest { RelationList list = res.getEntity(); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("readList: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -206,8 +238,10 @@ public class RelationServiceTest extends AbstractServiceTest { list.getRelationListItem(); int i = 0; for(RelationList.RelationListItem item : items){ - verbose("readList: list-item[" + i + "] csid=" + item.getCsid()); - verbose("readList: list-item[" + i + "] URI=" + item.getUri()); + verbose("readList: list-item[" + i + "] csid=" + + item.getCsid()); + verbose("readList: list-item[" + i + "] URI=" + + item.getUri()); i++; } } @@ -233,11 +267,11 @@ public class RelationServiceTest extends AbstractServiceTest { setupUpdate(); // Retrieve an existing resource that we can update. - ClientResponse res = client.read(knownObjectId); + ClientResponse res = client.read(knownResourceId); verbose("read: status = " + res.getStatus()); Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); Relation relation = res.getEntity(); - verbose("Got object to update with ID: " + knownObjectId, + verbose("Got object to update with ID: " + knownResourceId, relation, Relation.class); // Update the content of this resource. @@ -247,19 +281,22 @@ public class RelationServiceTest extends AbstractServiceTest { relation.setDocumentType2("updated-" + relation.getDocumentType2()); // Submit the request to the service and store the response. - res = client.update(knownObjectId, relation); + res = client.update(knownResourceId, relation); int statusCode = res.getStatus(); Relation updatedObject = res.getEntity(); - // Check the status code of the response: does it match the expected response(s)? + // 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); - // Check the contents of the response: does it match what was submitted? + // Check the contents of the response: does it match + // what was submitted? verbose("update: ", updatedObject, Relation.class); - final String msg = "Data in updated object did not match submitted data."; + final String msg = + "Data in updated object did not match submitted data."; Assert.assertEquals( updatedObject.getDocumentId1(), relation.getDocumentId1(), msg); Assert.assertEquals( @@ -273,7 +310,8 @@ public class RelationServiceTest extends AbstractServiceTest { // Failure outcomes - // Placeholders until the two tests below can be uncommented. See Issue CSPACE-401. + // Placeholders until the two tests below can be uncommented. + // See Issue CSPACE-401. public void updateWithMalformedXml() {} public void updateWithWrongXmlSchema() {} @@ -287,11 +325,12 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); + String url = getResourceURL(knownResourceId); final String entity = MALFORMED_XML_DATA; // Constant from abstract base class. int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -307,11 +346,12 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = REQUEST_TYPE.httpMethodName(); - String url = getResourceURL(knownObjectId); + String url = getResourceURL(knownResourceId); final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class. int statusCode = submitRequest(method, url, entity); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -328,15 +368,15 @@ public class RelationServiceTest extends AbstractServiceTest { setupUpdateNonExistent(); // Submit the request to the service and store the response. - // Note: The ID used in this 'fill' call may be arbitrary. + // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. - Relation relation = new Relation(); - fillRelation(relation, NON_EXISTENT_ID); + Relation relation = createRelationInstance(NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, relation); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("updateNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -358,13 +398,12 @@ public class RelationServiceTest extends AbstractServiceTest { setupDelete(); // Submit the request to the service and store the response. - String relationID = this.createEntity("0"); - Assert.assertNotNull(relationID, "Could not create a new object to delete."); - ClientResponse res = client.delete(relationID); + ClientResponse res = client.delete(knownResourceId); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? - verbose("delete: status = " + res.getStatus() + " csid = " + relationID); + // Check the status code of the response: does it match + // the expected response(s)? + verbose("delete: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); @@ -383,7 +422,8 @@ public class RelationServiceTest extends AbstractServiceTest { ClientResponse res = client.delete(NON_EXISTENT_ID); int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? + // Check the status code of the response: does it match + // the expected response(s)? verbose("deleteNonExistent: status = " + res.getStatus()); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); @@ -416,10 +456,11 @@ public class RelationServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String method = ServiceRequestType.READ.httpMethodName(); - String url = getResourceURL(knownObjectId); + String url = getResourceURL(knownResourceId); int statusCode = submitRequest(method, url); - // Check the status code of the response: does it match the expected response(s)? + // 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); @@ -435,20 +476,11 @@ public class RelationServiceTest extends AbstractServiceTest { return SERVICE_PATH_COMPONENT; } - private String createEntity(String identifier) { - + private Relation createRelationInstance(String identifier) { String result = null; - Relation relation = new Relation(); fillRelation(relation, identifier); - ClientResponse res = client.create(relation); - Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode()); - - result = extractId(res); - String responseString = res.toString(); - System.out.println(responseString); - - return result; + return relation; } /** @@ -467,7 +499,7 @@ public class RelationServiceTest extends AbstractServiceTest { } /** - * Creates the relation. + * Fills the relation. * * @param documentId1 the document id1 * @param documentType1 the document type1