From: Richard Millet Date: Tue, 11 May 2010 05:54:09 +0000 (+0000) Subject: CSPACE-1792, CSPACE-1781: Fixing pagination problem in Person, Org, and Vocab service... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=4dc2081befe0a64908546090c15d2b79fdfa0ade;p=tmp%2Fjakarta-migration.git CSPACE-1792, CSPACE-1781: Fixing pagination problem in Person, Org, and Vocab services. Also, add releaseConnection() method to JAX-RS most of ClientResponse calls -still some cleanup needed. --- diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java index 57d0e277b..99f2e2c2b 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java @@ -22,32 +22,14 @@ */ package org.collectionspace.services.ItegrationTests.test; -import java.io.IOException; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; import org.testng.Assert; import org.testng.annotations.Test; -import org.testng.Assert; -import org.testng.annotations.Test; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.methods.OptionsMethod; -import org.apache.commons.httpclient.methods.TraceMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,19 +38,12 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; -import org.collectionspace.services.client.TestServiceClient; - -import org.collectionspace.services.CollectionObjectJAXBSchema; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; -import org.collectionspace.services.IntakeJAXBSchema; import org.collectionspace.services.client.IntakeClient; import org.collectionspace.services.intake.IntakesCommon; -import org.collectionspace.services.intake.IntakesCommonList; -import org.collectionspace.services.common.relation.RelationJAXBSchema; import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationsCommonList; @@ -103,11 +78,17 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName()); + // Make the create call and check the response ClientResponse response = collectionObjectClient.create(multipart); - Assert.assertEquals(response.getStatus(), Response.Status.CREATED - .getStatusCode()); - String collectionObjectCsid = extractId(response); + String collectionObjectCsid = null; + try { + Assert.assertEquals(response.getStatus(), Response.Status.CREATED + .getStatusCode()); + collectionObjectCsid = extractId(response); + } finally { + response.releaseConnection(); + } // Next, create an Intake object @@ -117,10 +98,16 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { multipart = new MultipartOutput(); commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", intakeClient.getCommonPartName()); + // Make the call to create and check the response response = intakeClient.create(multipart); - Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); - String intakeCsid = extractId(response); + String intakeCsid = null; + try { + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + intakeCsid = extractId(response); + } finally { + response.releaseConnection(); + } // Lastly, relate the two entities, by creating a new relation object RelationsCommon relation = new RelationsCommon(); @@ -131,10 +118,16 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { multipart = new MultipartOutput(); commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", relationClient.getCommonPartName()); + // Make the call to crate - response = relationClient.create(multipart); - Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); - String relationCsid = extractId(response); + response = relationClient.create(multipart); + String relationCsid = null; + try { + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + relationCsid = extractId(response); + } finally { + response.releaseConnection(); + } // // Now try to retrieve the Intake record of the CollectionObject. @@ -143,24 +136,29 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { ClientResponse resultResponse = relationClient.readList_SPO(collectionObjectCsid, predicate, intakeCsid); - Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode()); + RelationsCommonList relationList = null; + try { + Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode()); + relationList = resultResponse.getEntity(); + } finally { + resultResponse.releaseConnection(); + } // // Each relation returned in the list needs to match what we // requested. // - RelationsCommonList relationList = resultResponse.getEntity(); List relationListItems = relationList.getRelationListItem(); Assert.assertFalse(relationListItems.isEmpty()); - ClientResponse resultRelationResponse; - RelationsCommon resultRelation = null; int i = 0; + RelationsCommon resultRelation = null; for(RelationsCommonList.RelationListItem listItem : relationListItems){ String foundCsid = listItem.getCsid(); + ClientResponse multiPartResponse = null; try { - ClientResponse multiPartResponse = relationClient.read(foundCsid); + multiPartResponse = relationClient.read(foundCsid); int responseStatus = multiPartResponse.getStatus(); Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); MultipartInput input = (MultipartInput) multiPartResponse.getEntity(); @@ -169,7 +167,10 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { RelationsCommon.class); } catch (Exception e) { e.printStackTrace(); + } finally { + multiPartResponse.releaseConnection(); } + Assert.assertEquals(resultRelation.getDocumentId1(), collectionObjectCsid); Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE); Assert.assertEquals(resultRelation.getDocumentId2(), intakeCsid); diff --git a/services/PerformanceTests/pom.xml b/services/PerformanceTests/pom.xml index bad8ee026..427f276ce 100644 --- a/services/PerformanceTests/pom.xml +++ b/services/PerformanceTests/pom.xml @@ -24,6 +24,11 @@ test + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + org.collectionspace.services org.collectionspace.services.client diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java index 03632f4a6..3e01d21e2 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java @@ -22,61 +22,29 @@ */ package org.collectionspace.services.PerformanceTests.test; -import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.Date; import java.util.Random; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import org.testng.Assert; -import org.testng.annotations.Test; import org.testng.Assert; import org.testng.annotations.Test; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.methods.OptionsMethod; -import org.apache.commons.httpclient.methods.TraceMethod; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; -import org.collectionspace.services.client.TestServiceClient; - -import org.collectionspace.services.CollectionObjectJAXBSchema; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem; -import org.collectionspace.services.IntakeJAXBSchema; -import org.collectionspace.services.client.IntakeClient; -import org.collectionspace.services.intake.IntakesCommon; -import org.collectionspace.services.intake.IntakesCommonList; - -import org.collectionspace.services.common.relation.RelationJAXBSchema; -import org.collectionspace.services.client.RelationClient; -import org.collectionspace.services.relation.RelationsCommon; -import org.collectionspace.services.relation.RelationsCommonList; -import org.collectionspace.services.relation.RelationshipType; - /** * A ServiceTest. * @@ -84,25 +52,40 @@ import org.collectionspace.services.relation.RelationshipType; */ public class PerformanceTest extends CollectionSpacePerformanceTest { + /** The Constant MAX_KEYWORDS. */ private static final int MAX_KEYWORDS = 10; + + /** The Constant MAX_SEARCHES. */ private static final int MAX_SEARCHES = 10; + + /** The logger. */ final Logger logger = LoggerFactory .getLogger(PerformanceTest.class); // // Get clients for the CollectionSpace services // - private static int MAX_RECORDS = 1000; + /** The MA x_ records. */ + private static int MAX_RECORDS = 100; + /** + * Performance test. + */ @Test public void performanceTest() { roundTripOverhead(10); deleteCollectionObjects(); String[] coList = this.createCollectionObjects(MAX_RECORDS); this.searchCollectionObjects(MAX_RECORDS); -// this.deleteCollectionObjects(coList); + this.deleteCollectionObjects(coList); roundTripOverhead(10); } + /** + * Round trip overhead. + * + * @param numOfCalls the num of calls + * @return the long + */ private long roundTripOverhead(int numOfCalls) { long result = 0; CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); @@ -110,7 +93,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { long totalTime = 0; for (int i = 0; i < numOfCalls; i++) { Date startTime = new Date(); - collectionObjectClient.roundtrip(); + collectionObjectClient.roundtrip().releaseConnection(); Date stopTime = new Date(); totalTime = totalTime + (stopTime.getTime() - startTime.getTime()); System.out.println("Overhead roundtrip time is: " + (stopTime.getTime() - startTime.getTime())); @@ -124,6 +107,11 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { return result; } + /** + * Search collection objects. + * + * @param numberOfObjects the number of objects + */ private void searchCollectionObjects(int numberOfObjects) { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Random randomGenerator = new Random(System.currentTimeMillis()); @@ -137,14 +125,24 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { numOfKeywords++, totalTime = 0, totalSearchResults = 0, times = "") { keywords = keywords + " " + OBJECT_NAME + randomGenerator.nextInt(numberOfObjects); for (int i = 0; i < MAX_SEARCHES; i++) { + //sandwich the call with timestamps Date startTime = new Date(); - searchResults = collectionObjectClient.keywordSearch(keywords); + searchResults = collectionObjectClient.keywordSearch(keywords); Date stopTime = new Date(); + + //extract the result list and release the ClientResponse + CollectionobjectsCommonList coListItem = null; + try { + coListItem = searchResults.getEntity(); + } finally { + searchResults.releaseConnection(); + } + long time = stopTime.getTime() - startTime.getTime(); times = times + " " + ((float)time / 1000); totalTime = totalTime + time; - totalSearchResults = totalSearchResults + - searchResults.getEntity().getCollectionObjectListItem().size(); + totalSearchResults = totalSearchResults + + coListItem.getCollectionObjectListItem().size(); } if (logger.isDebugEnabled()) { System.out.println("------------------------------------------------------------------------------"); @@ -160,6 +158,13 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { return; } + /** + * Creates the collection object. + * + * @param collectionObjectClient the collection object client + * @param identifier the identifier + * @return the string + */ private String createCollectionObject(CollectionObjectClient collectionObjectClient, int identifier) { String result = null; @@ -175,20 +180,29 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName()); // Make the create call and check the response ClientResponse response = collectionObjectClient.create(multipart); - - int responseStatus = response.getStatus(); - if (logger.isDebugEnabled() == true) { - if (responseStatus != Response.Status.CREATED.getStatusCode()) - logger.debug("Status of call to create CollectionObject was: " + - responseStatus); + try { + int responseStatus = response.getStatus(); + if (logger.isDebugEnabled() == true) { + if (responseStatus != Response.Status.CREATED.getStatusCode()) + logger.debug("Status of call to create CollectionObject was: " + + responseStatus); + } + + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + result = extractId(response); + } finally { + response.releaseConnection(); } - Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); - result = extractId(response); - return result; } + /** + * Creates the collection objects. + * + * @param numberOfObjects the number of objects + * @return the string[] + */ public String[] createCollectionObjects(int numberOfObjects) { Random randomGenerator = new Random(System.currentTimeMillis()); CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); @@ -199,6 +213,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { Date startTime = new Date(); for (int i = 0; i < numberOfObjects; i++, createdObjects++) { coList[i] = createCollectionObject(collectionObjectClient, i + 1); + if (logger.isDebugEnabled() == true) { + logger.debug("Created CollectionObject #: " + i); + } } Date stopTime = new Date(); if (logger.isDebugEnabled()) { @@ -214,42 +231,69 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { return coList; } + /** + * Delete collection object. + * + * @param collectionObjectClient the collection object client + * @param resourceId the resource id + */ private void deleteCollectionObject(CollectionObjectClient collectionObjectClient, String resourceId) { - ClientResponse res = collectionObjectClient.delete(resourceId); + ClientResponse res = collectionObjectClient.delete(resourceId); + res.releaseConnection(); } + /** + * Delete collection objects. + * + * @param arrayOfObjects the array of objects + */ public void deleteCollectionObjects(String[] arrayOfObjects) { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Date startTime = new Date(); for (int i = 0; i < arrayOfObjects.length; i++) { deleteCollectionObject(collectionObjectClient, arrayOfObjects[i]); - } - + } Date stopTime = new Date(); + if (logger.isDebugEnabled()) { System.out.println("Deleted " + arrayOfObjects.length + " CollectionObjects" + " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); } } + /** + * Delete collection objects. + * FIXME: Deletes a page at a time until there are no more CollectionObjects. + */ public void deleteCollectionObjects() { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - ClientResponse commonsList; - commonsList = collectionObjectClient.readList(); - List coListItems = commonsList.getEntity().getCollectionObjectListItem(); - - Date startTime = new Date(); - for (CollectionObjectListItem i:coListItems) { - deleteCollectionObject(collectionObjectClient, i.getCsid()); - } - Date stopTime = new Date(); + ClientResponse response; - if (logger.isDebugEnabled()) { - System.out.println("Deleted " + coListItems.size() + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } + List coListItems = null; + do { + response = collectionObjectClient.readList(Integer.toString(MAX_RECORDS), + Integer.toString(0)); + try { + CollectionobjectsCommonList commonListElement = + (CollectionobjectsCommonList)response.getEntity(CollectionobjectsCommonList.class); + coListItems = commonListElement.getCollectionObjectListItem(); + } finally { + response.releaseConnection(); + } + + Date startTime = new Date(); + for (CollectionObjectListItem i:coListItems) { + deleteCollectionObject(collectionObjectClient, i.getCsid()); + } + Date stopTime = new Date(); + + if (logger.isDebugEnabled()) { + System.out.println("Deleted " + coListItems.size() + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); + } + } while (coListItems.size() > 0); } } diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java index 129c89d94..ade53c128 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java @@ -51,6 +51,7 @@ public class AccountClient extends AbstractServiceClientImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() */ + @Override public String getServicePathComponent() { return "accounts"; } @@ -85,7 +86,7 @@ public class AccountClient extends AbstractServiceClientImpl { } /** - * @return + * @return response * @see org.collectionspace.hello.client.AccountProxy#readList() */ public ClientResponse readList() { @@ -100,7 +101,7 @@ public class AccountClient extends AbstractServiceClientImpl { /** * @param csid - * @return + * @return response * @see org.collectionspace.hello.client.AccountProxy#getAccount(java.lang.String) */ public ClientResponse read(String csid) { @@ -108,8 +109,9 @@ public class AccountClient extends AbstractServiceClientImpl { } /** + * @param multipart * @param account - * @return + * @return response * @see org.collectionspace.hello.client.AccountProxy#create(org.collectionspace.services.account.AccountsCommon) */ public ClientResponse create(AccountsCommon multipart) { @@ -118,8 +120,9 @@ public class AccountClient extends AbstractServiceClientImpl { /** * @param csid + * @param multipart * @param account - * @return + * @return response * @see org.collectionspace.hello.client.AccountProxy#updateAccount(java.lang.Long, org.collectionspace.services.account.AccountsCommon) */ public ClientResponse update(String csid, AccountsCommon multipart) { @@ -128,10 +131,11 @@ public class AccountClient extends AbstractServiceClientImpl { /** * @param csid - * @return + * @return response * @see org.collectionspace.hello.client.AccountProxy#deleteAccount(java.lang.Long) */ - public ClientResponse delete(String csid) { + @Override + public ClientResponse delete(String csid) { return accountProxy.delete(csid); } } diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java index d2f9d65b0..a64c61ee2 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java @@ -63,22 +63,36 @@ import org.testng.annotations.BeforeClass; */ public class AccountRoleServiceTest extends AbstractServiceTestImpl { + /** The Constant logger. */ static private final Logger logger = LoggerFactory.getLogger(AccountRoleServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; + + /** The all resource ids created. */ private List allResourceIdsCreated = new ArrayList(); + + /** The acc values. */ private Hashtable accValues = new Hashtable(); + + /** The role values. */ private Hashtable roleValues = new Hashtable(); /* * This method is called only by the parent class, AbstractServiceTestImpl */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override protected String getServicePathComponent() { return new AccountRoleClient().getServicePathComponent(); } + /** + * Seed data. + */ @BeforeClass(alwaysRun = true) public void seedData() { String userId = "acc-role-user1"; @@ -125,29 +139,35 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { */ @Override protected CollectionSpaceClient getClientInstance() { - return new AccountRoleClient(); + return new AccountRoleClient(); } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + throw new UnsupportedOperationException(); } - - @Test(dataProvider = "testName") - @Override + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) + */ + @Test(dataProvider = "testName") + @Override public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } - + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + } + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -163,55 +183,73 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { roleValues.values(), true, true); AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.create(pv.getAccountId(), accRole); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from this create operation - // for additional tests below. - //this is is not important in case of this relationship - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); + try { + int statusCode = res.getStatus(); + + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from this create operation + // for additional tests below. + //this is is not important in case of this relationship + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } finally { + res.releaseConnection(); } - res.releaseConnection(); } //to not cause uniqueness violation for accRole, createList is removed + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @Override public void createList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // --------------------------------------------------------------- // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -225,22 +263,27 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.read( accValues.get("acc-role-user1").getAccountId(), "123"); int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + AccountRole output = (AccountRole) res.getEntity(); + Assert.assertNotNull(output); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - AccountRole output = (AccountRole) res.getEntity(); - Assert.assertNotNull(output); - res.releaseConnection(); } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void readNonExistent(String testName) throws Exception { @@ -252,27 +295,32 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { AccountRoleClient client = new AccountRoleClient(); ClientResponse res = client.read(this.NON_EXISTENT_ID, "123"); int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } // --------------------------------------------------------------- // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes @@ -281,47 +329,64 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) public void delete(String testName) throws Exception { - // Perform setup. setupDelete(testName); @@ -330,16 +395,18 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.delete( accValues.get("acc-role-user1").getAccountId(), "123"); int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } // Failure outcomes @@ -359,6 +426,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create"}) public void testSubmitRequest() throws Exception { @@ -408,32 +476,40 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { return accRole; } + /** + * Clean up. + */ @AfterClass(alwaysRun = true) + @Override public void cleanUp() { setupDelete("delete"); + String noTest = System.getProperty("noTestCleanup"); - if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } + AccountRoleClient client = new AccountRoleClient(); for (String resourceId : allResourceIdsCreated) { - ClientResponse res = client.delete(resourceId, "123"); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("clenaup: delete relationships for accission id=" - + resourceId + " status=" + statusCode); + try { + int statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug("clenaup: delete relationships for accission id=" + + resourceId + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } for (AccountValue pv : accValues.values()) { @@ -445,6 +521,13 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the account. + * + * @param userName the user name + * @param email the email + * @return the string + */ private String createAccount(String userName, String email) { setupCreate(); AccountClient accClient = new AccountClient(); @@ -464,21 +547,35 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { return extractId(res); } + /** + * Delete account. + * + * @param accId the acc id + */ private void deleteAccount(String accId) { setupDelete(); AccountClient accClient = new AccountClient(); ClientResponse res = accClient.delete(accId); int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteAccount: delete account id=" - + accId + " status=" + statusCode); + try { + if (logger.isDebugEnabled()) { + logger.debug("deleteAccount: delete account id=" + + accId + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } + /** + * Creates the role. + * + * @param roleName the role name + * @return the string + */ private String createRole(String roleName) { setupCreate(); RoleClient roleClient = new RoleClient(); @@ -498,18 +595,26 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { return extractId(res); } + /** + * Delete role. + * + * @param roleId the role id + */ private void deleteRole(String roleId) { setupDelete(); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteRole: delete role id=" + roleId - + " status=" + statusCode); + try { + if (logger.isDebugEnabled()) { + logger.debug("deleteRole: delete role id=" + roleId + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - res.releaseConnection(); } } diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java index 3d00c9e6d..91268ad99 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java @@ -53,16 +53,22 @@ import org.testng.annotations.AfterClass; */ public class AccountServiceTest extends AbstractServiceTestImpl { + /** The Constant logger. */ static private final Logger logger = LoggerFactory.getLogger(AccountServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); + + /** The add tenant. */ static boolean addTenant = true; /* * This method is called only by the parent class, AbstractServiceTestImpl */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override protected String getServicePathComponent() { return new AccountClient().getServicePathComponent(); @@ -99,6 +105,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -137,6 +146,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the for unique user. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createForUniqueUser(String testName) throws Exception { @@ -158,6 +173,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + /** + * Creates the with invalid tenant. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithInvalidTenant(String testName) throws Exception { @@ -181,6 +202,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } + /** + * Creates the without user. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithoutUser(String testName) throws Exception { @@ -203,6 +230,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + /** + * Creates the with invalid email. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithInvalidEmail(String testName) throws Exception { @@ -225,6 +258,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + /** + * Creates the without screen name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithoutScreenName(String testName) throws Exception { @@ -247,6 +286,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + /** + * Creates the with invalid password. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithInvalidPassword(String testName) throws Exception { @@ -269,6 +314,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + /** + * Creates the with most invalid. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithMostInvalid(String testName) throws Exception { @@ -292,6 +343,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } //to not cause uniqueness violation for account, createList is removed + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -336,16 +390,25 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. @@ -355,6 +418,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -382,6 +448,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -409,6 +478,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) @@ -439,6 +511,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } } + /** + * Search screen name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchScreenName(String testName) throws Exception { @@ -469,6 +547,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } } + /** + * Search user id. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchUserId(String testName) throws Exception { @@ -499,6 +583,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } } + /** + * Search email. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchEmail(String testName) throws Exception { @@ -529,6 +619,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } } + /** + * Search screen name email. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchScreenNameEmail(String testName) throws Exception { @@ -565,6 +661,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) @@ -618,6 +717,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { "Data in updated object did not match submitted data."); } + /** + * Update password. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) public void updatePassword(String testName) throws Exception { @@ -671,6 +776,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // "Data in updated object did not match submitted data."); } + /** + * Update password without user. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) public void updatePasswordWithoutUser(String testName) throws Exception { @@ -703,6 +814,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } + /** + * Update invalid password. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) public void updateInvalidPassword(String testName) throws Exception { @@ -747,6 +864,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } + /** + * Deactivate. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"updatePasswordWithoutUser"}) public void deactivate(String testName) throws Exception { @@ -802,21 +925,33 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"}) @@ -847,6 +982,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Update wrong user. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"}) public void updateWrongUser(String testName) throws Exception { @@ -895,6 +1036,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"testSubmitRequest", "updateWrongUser"}) @@ -919,6 +1063,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) @@ -948,6 +1095,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() throws Exception { @@ -1002,30 +1150,12 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } - @AfterClass(alwaysRun = true) - public void cleanUp() { - setupDelete("delete"); - String noTest = System.getProperty("noTestCleanup"); - if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - AccountClient client = new AccountClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - } - + /** + * Prints the list. + * + * @param testName the test name + * @param list the list + */ private void printList(String testName, AccountsCommonList list) { List items = list.getAccountListItem(); diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java index 0b18663d8..883911e32 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountTest.java @@ -17,7 +17,7 @@ import javax.persistence.Persistence; import javax.persistence.Query; import org.collectionspace.services.account.AccountTenant; import org.collectionspace.services.account.AccountsCommon; -import org.collectionspace.services.account.Tenant; +//import org.collectionspace.services.account.Tenant; import org.collectionspace.services.account.Status; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java index d58348b69..d89c2630a 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java @@ -38,7 +38,7 @@ import org.collectionspace.services.client.PersonAuthorityClientUtils; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.acquisition.AcquisitionsCommon; -import org.collectionspace.services.acquisition.AcquisitionsCommonList; +//import org.collectionspace.services.acquisition.AcquisitionsCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -68,8 +68,8 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { final String SERVICE_PATH_COMPONENT = "acquisitions"; final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private String knownResourceId = null; - private List acquisitionIdsCreated = new ArrayList(); - private List personIdsCreated = new ArrayList(); + private List acquisitionIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); private int OK_STATUS = Response.Status.OK.getStatusCode(); private String personAuthCSID = null; @@ -288,15 +288,18 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { for (String resourceId : acquisitionIdsCreated) { // Note: Any non-success responses are ignored and not reported. ClientResponse res = acquisitionClient.delete(resourceId); + res.releaseConnection(); } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete persons before PersonAuth for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + res.releaseConnection(); } // Note: Any non-success response is ignored and not reported. ClientResponse res = personAuthClient.delete(personAuthCSID); + res.releaseConnection(); } // --------------------------------------------------------------- diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java index c15786e08..d00cead9f 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -40,7 +39,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -55,12 +53,13 @@ import org.slf4j.LoggerFactory; */ public class AcquisitionServiceTest extends AbstractServiceTestImpl { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(AcquisitionServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -83,6 +82,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -128,6 +130,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { allResourceIdsCreated.add(extractId(res)); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -140,16 +145,28 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -208,6 +225,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -239,6 +259,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -266,6 +289,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) @@ -321,6 +347,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -383,16 +412,28 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -497,6 +538,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { } */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) @@ -528,6 +572,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create", "read", "update"}) @@ -552,6 +599,9 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) @@ -581,6 +631,7 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() throws Exception { @@ -603,46 +654,24 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - AcquisitionClient client = new AcquisitionClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return new AcquisitionClient().getServicePathComponent(); } + /** + * Creates the acquisition instance. + * + * @param identifier the identifier + * @return the multipart output + */ private MultipartOutput createAcquisitionInstance(String identifier) { AcquisitionsCommon acquisition = new AcquisitionsCommon(); acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier); diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java index 1406a7ee5..f323ad90e 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleClient.java @@ -42,9 +42,7 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; */ public class PermissionRoleClient extends AbstractServiceClientImpl { - /** - * - */ + /** The permission role proxy. */ private PermissionRoleProxy permissionRoleProxy; /* (non-Javadoc) @@ -65,13 +63,16 @@ public class PermissionRoleClient extends AbstractServiceClientImpl { setProxy(); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy() + */ @Override public CollectionSpaceProxy getProxy() { return this.permissionRoleProxy; } /** - * allow to reset proxy as per security needs + * allow to reset proxy as per security needs. */ public void setProxy() { if (useAuth()) { @@ -85,32 +86,39 @@ public class PermissionRoleClient extends AbstractServiceClientImpl { /** - * @param csid + * Read. + * + * @param csid the csid * @param prcsid relationship does not have an id, junk is fine - * @return - * @see + * @return the client response + * @see */ public ClientResponse read(String csid, String prcsid) { return permissionRoleProxy.read(csid, prcsid); } /** - * @param permRole - * @return - * @see + * Creates the. + * + * @param csid the csid + * @param permRole the perm role + * @return the client response + * @see */ public ClientResponse create(String csid, PermissionRole permRole) { return permissionRoleProxy.create(csid, permRole); } - /** - * @param csid + * Delete. + * + * @param csid the csid * @param prcsid relationship does not have an id, junk is fine - * @return - * @see + * @return response + * @see */ public ClientResponse delete(String csid, String prcsid) { return permissionRoleProxy.delete(csid, prcsid); } + } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java index d280004b0..2471d408e 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java @@ -64,22 +64,36 @@ import org.testng.annotations.BeforeClass; */ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { + /** The Constant logger. */ static private final Logger logger = LoggerFactory.getLogger(PermissionRoleServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); + + /** The all resource ids created. */ + private List allResourceIdsCreated = new ArrayList(); + + /** The perm values. */ private Hashtable permValues = new Hashtable(); + + /** The role values. */ private Hashtable roleValues = new Hashtable(); /* * This method is called only by the parent class, AbstractServiceTestImpl */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override protected String getServicePathComponent() { return new PermissionRoleClient().getServicePathComponent(); } + /** + * Seed data. + */ @BeforeClass(alwaysRun = true) public void seedData() { String ra = "accounts"; @@ -123,29 +137,34 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { */ @Override protected CollectionSpaceClient getClientInstance() { - return new PermissionRoleClient(); + return new PermissionRoleClient(); } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + throw new UnsupportedOperationException(); } - - @Test(dataProvider = "testName") - @Override + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) + */ + @Test(dataProvider = "testName") + @Override public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + } // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -180,31 +199,50 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } //to not cause uniqueness violation for permRole, createList is removed + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createList(String testName) throws Exception { + //Should this really be empty? } // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } // --------------------------------------------------------------- // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -234,6 +272,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void readNonExistent(String testName) throws Exception { @@ -261,10 +302,14 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { + //Should this really be empty? } // Failure outcomes @@ -273,37 +318,60 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { + //Should this really be empty? } // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { + //Should this really be empty? } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -330,6 +398,9 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void deleteNonExistent(String testName) throws Exception { @@ -343,6 +414,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create"}) public void testSubmitRequest() throws Exception { @@ -371,11 +443,14 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- /** * create permRolerole instance + * @param pv + * @param rvs + * @param usePermId * @param permId * @param roleValues array of role ids * @param userPermId * @param useRoleId - * @return + * @return PermissionRole */ public static PermissionRole createPermissionRoleInstance(PermissionValue pv, Collection rvs, @@ -391,19 +466,42 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { return permRole; } + /** + * Clean up. + */ @AfterClass(alwaysRun = true) + @Override public void cleanUp() { setupDelete("cleanup"); String noTest = System.getProperty("noTestCleanup"); - if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } + + PermissionRoleClient client = new PermissionRoleClient(); + for (String resourceId : allResourceIdsCreated) { + + ClientResponse res = client.delete(resourceId, "123"); + int statusCode = res.getStatus(); + try { + if (logger.isDebugEnabled()) { + logger.debug("cleanup: delete relationships for permission id=" + + resourceId + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } + } + for (PermissionValue pv : permValues.values()) { deletePermission(pv.getPermissionId()); } @@ -412,6 +510,13 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the permission. + * + * @param resName the res name + * @param effect the effect + * @return the string + */ private String createPermission(String resName, EffectType effect) { setupCreate(); PermissionClient permClient = new PermissionClient(); @@ -432,21 +537,36 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { return extractId(res); } + /** + * Delete permission. + * + * @param permId the perm id + */ private void deletePermission(String permId) { setupDelete(); PermissionClient permClient = new PermissionClient(); ClientResponse res = permClient.delete(permId); int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deletePermission: delete permission id=" - + permId + " status=" + statusCode); + try { + if (logger.isDebugEnabled()) { + logger.debug("deletePermission: delete permission id=" + + permId + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); res.releaseConnection(); } + /** + * Creates the role. + * + * @param roleName the role name + * @return the string + */ private String createRole(String roleName) { setupCreate(); RoleClient roleClient = new RoleClient(); @@ -466,18 +586,27 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { return extractId(res); } + /** + * Delete role. + * + * @param roleId the role id + */ private void deleteRole(String roleId) { setupDelete(); RoleClient roleClient = new RoleClient(); ClientResponse res = roleClient.delete(roleId); int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug("deleteRole: delete role id=" + roleId - + " status=" + statusCode); + try { + if (logger.isDebugEnabled()) { + logger.debug("deleteRole: delete role id=" + roleId + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); res.releaseConnection(); } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java index 2ced44926..06cafd955 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java @@ -22,7 +22,7 @@ */ package org.collectionspace.services.authorization.client.test; -import java.util.ArrayList; +//import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.Response; //import org.collectionspace.services.authorization.ActionType; @@ -44,7 +44,6 @@ import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; /** * PermissionServiceTest, carries out tests against a @@ -55,16 +54,22 @@ import org.testng.annotations.AfterClass; */ public class PermissionServiceTest extends AbstractServiceTestImpl { + /** The Constant logger. */ static private final Logger logger = LoggerFactory.getLogger(PermissionServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); + + /** The add tenant. */ boolean addTenant = true; /* * This method is called only by the parent class, AbstractServiceTestImpl */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override protected String getServicePathComponent() { return new PermissionClient().getServicePathComponent(); @@ -88,6 +93,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { throw new UnsupportedOperationException(); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) + */ @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { @@ -98,7 +106,10 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes - @Override + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ + @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -141,6 +152,12 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the without resource name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithoutResourceName(String testName) throws Exception { @@ -169,6 +186,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { } //to not cause uniqueness violation for permission, createList is removed + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -224,16 +244,25 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. @@ -243,6 +272,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -270,6 +302,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -297,6 +332,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) @@ -327,6 +365,12 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { } } + /** + * Search resource name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchResourceName(String testName) throws Exception { @@ -366,6 +410,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) @@ -404,6 +451,12 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { "Data in updated object did not match submitted data."); } + /** + * Update actions. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) public void updateActions(String testName) throws Exception { @@ -455,21 +508,33 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) @@ -509,6 +574,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"updateActions"}) @@ -533,6 +601,9 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) @@ -562,6 +633,7 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() throws Exception { @@ -596,7 +668,7 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { * @param useResourceName * @param useAction * @param useEffect - * @return + * @return permission */ public static Permission createPermissionInstance(String resourceName, String description, @@ -617,29 +689,13 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { return permission; } - @AfterClass(alwaysRun = true) - public void cleanUp() { - setupDelete("delete"); - String noTest = System.getProperty("noTestCleanup"); - if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - PermissionClient client = new PermissionClient(); - for (String resourceId : allResourceIdsCreated) { - ClientResponse res = client.delete(resourceId); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - } - + /** + * Prints the list. + * + * @param testName the test name + * @param list the list + * @return the int + */ private int printList(String testName, PermissionsList list) { int i = 0; diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java index 697faa1a8..507d6e7ce 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java @@ -22,8 +22,8 @@ */ package org.collectionspace.services.authorization.client.test; -import java.util.ArrayList; -import java.util.List; +//import java.util.ArrayList; +//import java.util.List; import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; @@ -41,7 +41,6 @@ import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; /** * RoleServiceTest, carries out tests against a @@ -52,16 +51,22 @@ import org.testng.annotations.AfterClass; */ public class RoleServiceTest extends AbstractServiceTestImpl { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(RoleServiceTest.class); // Instance variables specific to this test. + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); - boolean addTenant = true; +// private List allResourceIdsCreated = new ArrayList(); + /** The add tenant. */ +boolean addTenant = true; /* * This method is called only by the parent class, AbstractServiceTestImpl */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override protected String getServicePathComponent() { return new RoleClient().getServicePathComponent(); @@ -85,6 +90,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { throw new UnsupportedOperationException(); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) + */ @Test(dataProvider = "testName") @Override public void readPaginatedList(String testName) throws Exception { @@ -95,6 +103,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -133,6 +144,12 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the for unique role. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createForUniqueRole(String testName) throws Exception { @@ -155,6 +172,12 @@ public class RoleServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } + /** + * Creates the without role name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithoutRoleName(String testName) throws Exception { @@ -178,6 +201,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } //to not cause uniqueness violation for role, createList is removed + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -223,16 +249,25 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. @@ -242,6 +277,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -269,6 +307,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -296,6 +337,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) @@ -326,6 +370,12 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } } + /** + * Search role name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void searchRoleName(String testName) throws Exception { @@ -365,6 +415,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) @@ -407,21 +460,33 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { //FIXME: Should this test really be empty? If so, please comment accordingly. } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) @@ -456,6 +521,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"}) @@ -480,6 +548,9 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) @@ -509,6 +580,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl { /** * Tests the code for manually submitting data that is used by several * of the methods above. + * @throws Exception */ @Test(dependsOnMethods = {"create", "read"}) public void testSubmitRequest() throws Exception { @@ -539,7 +611,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl { * @param roleName * @param description * @param useRoleName - * @return + * @return role */ public Role createRoleInstance(String roleName, String description, @@ -555,29 +627,13 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } - @AfterClass(alwaysRun = true) - public void cleanUp() { - setupDelete("delete"); - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - RoleClient client = new RoleClient(); - for (String resourceId : allResourceIdsCreated) { - ClientResponse res = client.delete(resourceId); - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - } - } - + /** + * Prints the list. + * + * @param testName the test name + * @param list the list + * @return the int + */ private int printList(String testName, RolesList list) { int i = 0; diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index 7755b48aa..1aa2f0380 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -26,45 +26,52 @@ package org.collectionspace.services.client; import java.io.InputStream; import java.net.URL; import java.util.Properties; + +import javax.ws.rs.core.Response; + +//import javax.ws.rs.core.Response; + import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -//import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; +import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; -//import org.collectionspace.services.common.context.ServiceContext; +import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * BaseServiceClient is an abstract base client of all service clients - * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 + * BaseServiceClient is an abstract base client of all service clients FIXME: + * http://issues.collectionspace.org/browse/CSPACE-1684 + * @param + * @param */ -public abstract class AbstractServiceClientImpl implements CollectionSpaceClient { - - /** The logger. */ - protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class); - - /** - * The character used to separate the words in a part label - */ - public static final String PART_LABEL_SEPERATOR = "_"; - - /** The Constant PART_COMMON_LABEL. */ - public static final String PART_COMMON_LABEL = "common"; - - /** The properties. */ - private Properties properties = new Properties(); - - /** The url. */ - private URL url; - - /** The http client. */ - private HttpClient httpClient; +public abstract class AbstractServiceClientImpl implements + CollectionSpaceClient { + + /** The logger. */ + protected final Logger logger = LoggerFactory + .getLogger(AbstractServiceClientImpl.class); + + /** + * The character used to separate the words in a part label + */ + public static final String PART_LABEL_SEPERATOR = "_"; + + /** The Constant PART_COMMON_LABEL. */ + public static final String PART_COMMON_LABEL = "common"; + + /** The properties. */ + private Properties properties = new Properties(); + + /** The url. */ + private URL url; + + /** The http client. */ + private HttpClient httpClient; /** * Gets the common part name. - * + * * @return the common part name */ public String getCommonPartName() { @@ -73,207 +80,246 @@ public abstract class AbstractServiceClientImpl implements CollectionSpaceClient /** * Gets the common part name. - * - * @param servicePathComponent the service path component + * + * @param servicePathComponent + * the service path component * @return the common part name */ public String getCommonPartName(String servicePathComponent) { - return servicePathComponent - + PART_LABEL_SEPERATOR - + PART_COMMON_LABEL; + return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL; } /** * Gets the service path component. - * + * * @return the service path component */ abstract public String getServicePathComponent(); - - /** - * Instantiates a new abstract service client impl. - */ - protected AbstractServiceClientImpl() { - readProperties(); - setupHttpClient(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#getProperty(java.lang.String) - */ - @Override - public String getProperty(String propName) { - return properties.getProperty(propName); - } - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#setProperty(java.lang.String, java.lang.String) - */ - @Override - public void setProperty(String propName, String value) { - properties.setProperty(propName, value); - } + /** + * Instantiates a new abstract service client impl. + */ + protected AbstractServiceClientImpl() { + readProperties(); + setupHttpClient(); + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#removeProperty(java.lang.String) - */ - @Override - public Object removeProperty(String propName) { - return properties.remove(propName); - } - - /** - * Prints the properties. - */ - public void printProperties() { - for(Object kobj : properties.keySet()){ - String key = (String) kobj; - logger.trace("begin property name=" + key + " value=" + properties.get(key)); - } - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#getBaseURL() - */ - @Override - public String getBaseURL() { - return properties.getProperty(URL_PROPERTY); - } + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#getProperty + * (java.lang.String) + */ + @Override + public String getProperty(String propName) { + return properties.getProperty(propName); + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#getHttpClient() - */ - @Override - public HttpClient getHttpClient() { - return httpClient; - } + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#setProperty + * (java.lang.String, java.lang.String) + */ + @Override + public void setProperty(String propName, String value) { + properties.setProperty(propName, value); + } - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth() - */ - @Override - public boolean useAuth() { - String auth = properties.getProperty(AUTH_PROPERTY); - return Boolean.valueOf(auth); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL() - */ - @Override - public boolean useSSL() { - String ssl = properties.getProperty(SSL_PROPERTY); - return Boolean.valueOf(ssl); - } - - /** - * readProperties reads properties from system class path as well - * as it overrides properties made available using command line - * @exception RuntimeException - */ - private void readProperties() { - - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - InputStream is = null; - try{ - is = cl.getResourceAsStream("collectionspace-client.properties"); - properties.load(is); - if(logger.isDebugEnabled()){ - printProperties(); - } - String spec = System.getProperty(URL_PROPERTY); - if(spec != null && !"".equals(spec)){ - properties.setProperty(URL_PROPERTY, spec); - } - - spec = properties.getProperty(URL_PROPERTY); - url = new URL(spec); - if(logger.isInfoEnabled()){ - logger.info("readProperties() using url=" + url); - } - - String auth = System.getProperty(AUTH_PROPERTY); - if(auth != null && !"".equals(auth)){ - properties.setProperty(AUTH_PROPERTY, auth); - } - String ssl = System.getProperty(SSL_PROPERTY); - if(ssl != null && !"".equals(ssl)){ - properties.setProperty(AUTH_PROPERTY, ssl); - } - String user = System.getProperty(USER_PROPERTY); - if(user != null && !"".equals(user)){ - properties.setProperty(USER_PROPERTY, user); - } - String password = System.getProperty(PASSWORD_PROPERTY); - if(password != null && !"".equals(password)){ - properties.setProperty(PASSWORD_PROPERTY, password); - } - if(logger.isDebugEnabled()){ - printProperties(); - } - }catch(Exception e){ - logger.debug("Caught exception while reading properties", e); - throw new RuntimeException(e); - }finally{ - if(is != null){ - try{ - is.close(); - }catch(Exception e){ - } - } - } - } - - /** - * setupHttpClient sets up HTTP client for the service client - * the setup process relies on the following properties - * URL_PROPERTY - * USER_PROPERTY - * PASSWORD_PROPERTY - * AUTH_PROPERTY - * SSL_PROPERTY - */ - @Override - public void setupHttpClient() { - this.httpClient = new HttpClient(); - if(useAuth()){ - String user = properties.getProperty(USER_PROPERTY); - String password = properties.getProperty(PASSWORD_PROPERTY); - if(logger.isInfoEnabled()){ - logger.info("setupHttpClient() using url=" + url + - " user=" + user + " password=" + password); - } - - httpClient.getState().setCredentials( - new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), - new UsernamePasswordCredentials(user, password)); - //JAXRS client library requires HTTP preemptive authentication - httpClient.getParams().setAuthenticationPreemptive(true); - if(logger.isInfoEnabled()){ - logger.info("setupHttpClient: set preemptive authentication"); - } - } else { - if(logger.isInfoEnabled()){ - logger.info("setupHttpClient() : no auth mode!"); - } - } - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#isServerSecure() - */ - @Override - public boolean isServerSecure() { - return Boolean.getBoolean("cspace.server.secure"); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.client.CollectionSpaceClient#readList(java.lang.String, java.lang.String) - */ + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#removeProperty + * (java.lang.String) + */ + @Override + public Object removeProperty(String propName) { + return properties.remove(propName); + } + + /** + * Prints the properties. + */ + public void printProperties() { + for (Object kobj : properties.keySet()) { + String key = (String) kobj; + logger.trace("begin property name=" + key + " value=" + + properties.get(key)); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL() + */ + @Override + public String getBaseURL() { + return properties.getProperty(URL_PROPERTY); + } + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient() + */ + @Override + public HttpClient getHttpClient() { + return httpClient; + } + + /* + * (non-Javadoc) + * + * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth() + */ + @Override + public boolean useAuth() { + String auth = properties.getProperty(AUTH_PROPERTY); + return Boolean.valueOf(auth); + } + + /* + * (non-Javadoc) + * + * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL() + */ + @Override + public boolean useSSL() { + String ssl = properties.getProperty(SSL_PROPERTY); + return Boolean.valueOf(ssl); + } + + /** + * readProperties reads properties from system class path as well as it + * overrides properties made available using command line + * + * @exception RuntimeException + */ + private void readProperties() { + + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + InputStream is = null; + try { + is = cl.getResourceAsStream("collectionspace-client.properties"); + properties.load(is); + if (logger.isDebugEnabled()) { + printProperties(); + } + String spec = System.getProperty(URL_PROPERTY); + if (spec != null && !"".equals(spec)) { + properties.setProperty(URL_PROPERTY, spec); + } + + spec = properties.getProperty(URL_PROPERTY); + url = new URL(spec); + if (logger.isInfoEnabled()) { + logger.info("readProperties() using url=" + url); + } + + String auth = System.getProperty(AUTH_PROPERTY); + if (auth != null && !"".equals(auth)) { + properties.setProperty(AUTH_PROPERTY, auth); + } + String ssl = System.getProperty(SSL_PROPERTY); + if (ssl != null && !"".equals(ssl)) { + properties.setProperty(AUTH_PROPERTY, ssl); + } + String user = System.getProperty(USER_PROPERTY); + if (user != null && !"".equals(user)) { + properties.setProperty(USER_PROPERTY, user); + } + String password = System.getProperty(PASSWORD_PROPERTY); + if (password != null && !"".equals(password)) { + properties.setProperty(PASSWORD_PROPERTY, password); + } + if (logger.isDebugEnabled()) { + printProperties(); + } + } catch (Exception e) { + logger.debug("Caught exception while reading properties", e); + throw new RuntimeException(e); + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + if (logger.isDebugEnabled() == true) { + e.printStackTrace(); + } + } + } + } + } + + /** + * setupHttpClient sets up HTTP client for the service client the setup + * process relies on the following properties URL_PROPERTY USER_PROPERTY + * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY + */ + @Override + public void setupHttpClient() { + this.httpClient = new HttpClient(); + if (useAuth()) { + String user = properties.getProperty(USER_PROPERTY); + String password = properties.getProperty(PASSWORD_PROPERTY); + if (logger.isInfoEnabled()) { + logger.info("setupHttpClient() using url=" + url + " user=" + + user + " password=" + password); + } + + httpClient.getState().setCredentials( + new AuthScope(url.getHost(), url.getPort(), + AuthScope.ANY_REALM), + new UsernamePasswordCredentials(user, password)); + // JAXRS client library requires HTTP preemptive authentication + httpClient.getParams().setAuthenticationPreemptive(true); + if (logger.isInfoEnabled()) { + logger.info("setupHttpClient: set preemptive authentication"); + } + } else { + if (logger.isInfoEnabled()) { + logger.info("setupHttpClient() : no auth mode!"); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure + * () + */ + @Override + public boolean isServerSecure() { + return Boolean.getBoolean("cspace.server.secure"); + } + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.CollectionSpaceClient#readList(java + * .lang.String, java.lang.String) + */ + @Override + public ClientResponse readList(String pageSize, + String pageNumber) { + return getProxy().readList(pageSize, pageNumber); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String) + */ @Override - public ClientResponse readList(String pageSize, - String pageNumber) { - return getProxy().readList(pageSize, pageNumber); - } - + public ClientResponse delete(String csid) { + // must override in children if you want behavior + throw new UnsupportedOperationException(); + } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java index 59c19888f..82adaede4 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java @@ -22,6 +22,8 @@ * limitations under the License. */ package org.collectionspace.services.client; +import javax.ws.rs.core.Response; + import org.apache.commons.httpclient.HttpClient; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -118,7 +120,7 @@ public interface CollectionSpaceClient { /** * checks System property cspace.server.secure - * @return + * @return boolean */ boolean isServerSecure(); @@ -130,6 +132,14 @@ public interface CollectionSpaceClient { * @return the client response */ public ClientResponse readList(String pageSize, - String pageNumber); + String pageNumber); + + /** + * Delete. + * + * @param csid the csid + * @return the client response + */ + public ClientResponse delete(String csid); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java index 379a35497..8374ff208 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java @@ -23,6 +23,10 @@ package org.collectionspace.services.client; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.client.ClientResponse; + /** * A CollectionObjectClient. @@ -43,5 +47,9 @@ public class TestServiceClient extends AbstractServiceClientImpl { @Override public CollectionSpaceProxy getProxy() { throw new UnsupportedOperationException(); - } + } + + public ClientResponse delete(String csid) { + throw new UnsupportedOperationException(); + } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index 8d2dc3eb1..7f2e8860a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -25,6 +25,9 @@ package org.collectionspace.services.client.test; //import java.util.List; +import java.util.ArrayList; +import java.util.List; + import javax.ws.rs.core.Response; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -34,6 +37,7 @@ import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; /** @@ -51,6 +55,9 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements /** The Constant DEFAULT_LIST_SIZE. */ static protected final int DEFAULT_LIST_SIZE = 10; static protected final int DEFAULT_PAGINATEDLIST_SIZE = 10; + + /* Use this to keep track of resources to delete */ + protected List allResourceIdsCreated = new ArrayList(); // // Success outcomes // /* (non-Javadoc) @@ -242,21 +249,26 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements CollectionSpaceClient client, long pageSize, long pageNumber) throws Exception { ClientResponse response = - (ClientResponse)client.readList(Long.toString(pageSize), - Long.toString(pageNumber)); - int statusCode = response.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (getLogger().isDebugEnabled()) { - getLogger().debug(testName + ": status = " + statusCode); + client.readList(Long.toString(pageSize), Long.toString(pageNumber)); + AbstractCommonList result = null; + try { + int statusCode = response.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (getLogger().isDebugEnabled()) { + getLogger().debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + result = this.getAbstractCommonList(response); + } finally { + response.releaseConnection(); } - Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - - AbstractCommonList list = this.getAbstractCommonList(response); - return list; + + return result; } /** @@ -325,10 +337,10 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // Get the current total number of items. // If there are no items then create some - AbstractCommonList list = this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/); + AbstractCommonList list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/); if (list == null || list.getTotalItems() == 0) { this.createPaginatedList(testName, DEFAULT_PAGINATEDLIST_SIZE); - list = this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/); + list = (AbstractCommonList) this.readList(testName, client, 1 /*pgSz*/, 0 /*pgNum*/); } // Print out the current list size to be paginated @@ -343,7 +355,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements long pageSize = totalItems / 3; //create up to 3 pages to iterate over long pagesTotal = pageSize > 0 ? (totalItems / pageSize) : 0; for (int i = 0; i < pagesTotal; i++) { - list = this.readList(testName, client, pageSize, i); + list = (AbstractCommonList) this.readList(testName, client, pageSize, i); assertPaginationInfo(testName, list, i, //expected page number @@ -355,7 +367,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // if there are any remainders be sure to paginate them as well long mod = totalItems % pageSize; if (mod != 0) { - list = this.readList(testName, client, pageSize, pagesTotal); + list = (AbstractCommonList) this.readList(testName, client, pageSize, pagesTotal); assertPaginationInfo(testName, list, pagesTotal, //expected page number @@ -489,6 +501,33 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements // Expected status code: 400 Bad Request testSetup(Response.Status.BAD_REQUEST.getStatusCode(), ServiceRequestType.UPDATE, label); } + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + @AfterClass(alwaysRun=true) + public void cleanUp() { + String noTest = System.getProperty("noTestCleanup"); + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + CollectionSpaceClient client = this.getClientInstance(); + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + client.delete(resourceId).releaseConnection(); + } + } /* (non-Javadoc) * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String) diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java index 0f2f42ac0..be29719c4 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java @@ -31,7 +31,7 @@ import java.io.File; import java.io.InputStream; import java.io.StringWriter; import java.lang.reflect.Method; -import java.util.ArrayList; +//import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MultivaluedMap; @@ -42,6 +42,8 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.methods.EntityEnclosingMethod; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; @@ -63,6 +65,7 @@ import org.collectionspace.services.jaxb.AbstractCommonList; /** * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685 * The Class BaseServiceTest. + * @param */ public abstract class BaseServiceTest { @@ -228,21 +231,23 @@ public abstract class BaseServiceTest { */ protected int submitRequest(String method, String url) { int statusCode = 0; + HttpMethodBase httpMethod = null; try { TestServiceClient client = new TestServiceClient(); if (method.equals(javax.ws.rs.HttpMethod.DELETE)) { - DeleteMethod deleteMethod = new DeleteMethod(url); - statusCode = client.getHttpClient().executeMethod(deleteMethod); + httpMethod = new DeleteMethod(url); } else if (method.equals(javax.ws.rs.HttpMethod.GET)) { - GetMethod getMethod = new GetMethod(url); - statusCode = client.getHttpClient().executeMethod(getMethod); - } else { - // Do nothing - leave status code at default value. + httpMethod = new GetMethod(url); + } + if (httpMethod != null) { + statusCode = client.getHttpClient().executeMethod(httpMethod); } } catch (Exception e) { logger.error( "Exception during HTTP " + method + " request to " + url + ":", e); + } finally { + httpMethod.releaseConnection(); } return statusCode; } @@ -265,27 +270,26 @@ public abstract class BaseServiceTest { protected int submitRequest(String method, String url, String mediaType, String entityStr) { int statusCode = 0; + EntityEnclosingMethod httpMethod = null; try { TestServiceClient client = new TestServiceClient(); if (method.equals(javax.ws.rs.HttpMethod.POST)) { - StringRequestEntity entityBody = - new StringRequestEntity(mediaType, entityStr, NULL_CHARSET); - PostMethod postMethod = new PostMethod(url); - postMethod.setRequestEntity(entityBody); - statusCode = client.getHttpClient().executeMethod(postMethod); + httpMethod = new PostMethod(url); } else if (method.equals(javax.ws.rs.HttpMethod.PUT)) { + httpMethod = new PutMethod(url); + } + if (httpMethod != null) { StringRequestEntity entityBody = - new StringRequestEntity(mediaType, entityStr, NULL_CHARSET); - PutMethod putMethod = new PutMethod(url); - putMethod.setRequestEntity(entityBody); - statusCode = client.getHttpClient().executeMethod(putMethod); - } else { - // Do nothing - leave status code at default value. + new StringRequestEntity(mediaType, entityStr, NULL_CHARSET); + httpMethod.setRequestEntity(entityBody); + statusCode = client.getHttpClient().executeMethod(httpMethod); } } catch (Exception e) { logger.error( "Exception during HTTP " + method + " request to " + url + ":", e); + } finally { + httpMethod.releaseConnection(); } return statusCode; } @@ -297,8 +301,8 @@ public abstract class BaseServiceTest { * @return the string */ static protected String extractId(ClientResponse res) { - MultivaluedMap mvm = res.getMetadata(); - String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((List) mvm.get("Location")).get(0); if (logger.isDebugEnabled()) { logger.debug("extractId:uri=" + uri); } @@ -338,7 +342,7 @@ public abstract class BaseServiceTest { * @return the object * @throws Exception the exception */ - static protected Object extractPart(MultipartInput input, String label, Class clazz) + static protected Object extractPart(MultipartInput input, String label, Class clazz) throws Exception { Object obj = null; String partLabel = ""; @@ -397,7 +401,7 @@ public abstract class BaseServiceTest { * @return the part object * @throws JAXBException the jAXB exception */ - static protected Object getPartObject(String partStr, Class clazz) + static protected Object getPartObject(String partStr, Class clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); ByteArrayInputStream bais = null; @@ -411,6 +415,9 @@ public abstract class BaseServiceTest { try { bais.close(); } catch (Exception e) { + if (logger.isDebugEnabled() == true) { + e.printStackTrace(); + } } } } @@ -424,7 +431,7 @@ public abstract class BaseServiceTest { * @param clazz the clazz * @return the string */ - static protected String objectAsXmlString(Object o, Class clazz) { + static protected String objectAsXmlString(Object o, Class clazz) { StringWriter sw = new StringWriter(); try { JAXBContext jc = JAXBContext.newInstance(clazz); @@ -445,7 +452,7 @@ public abstract class BaseServiceTest { * @return * @throws Exception */ - static protected Object getObjectFromFile(Class jaxbClass, String fileName) + static protected Object getObjectFromFile(Class jaxbClass, String fileName) throws Exception { JAXBContext context = JAXBContext.newInstance(jaxbClass); @@ -493,7 +500,7 @@ public abstract class BaseServiceTest { * @return * @throws Exception */ - static protected Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception { + static protected Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception { JAXBContext context = JAXBContext.newInstance(jaxbClass); Unmarshaller unmarshaller = context.createUnmarshaller(); //note: setting schema to null will turn validator off @@ -507,10 +514,10 @@ public abstract class BaseServiceTest { * @param map the map * @return the string */ - protected String mapAsString(MultivaluedMap map) { + protected String mapAsString(MultivaluedMap map) { StringBuffer sb = new StringBuffer(); for (Object entry : map.entrySet()) { - MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; + MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; sb.append(" name=" + mentry.getKey()); sb.append(" value=" + mentry.getValue() + "\n"); } 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 e778414a6..2958bca3d 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 @@ -45,6 +45,8 @@ public interface ServiceTest { * Tests creation of a new resource. * * Relied upon by 'read', 'update' and 'delete' tests, below. + * @param testName + * @throws Exception */ public void create(String testName) throws Exception; @@ -53,6 +55,8 @@ public interface ServiceTest { * calling create(), and relies on the latter's test assertion(s). * * Relied upon by 'read list' tests, below. + * @param testName + * @throws Exception */ public void createList(String testName) throws Exception; @@ -61,12 +65,16 @@ public interface ServiceTest { /** * Tests creation of a resource by submitting * an empty entity body (aka empty payload). + * @param testName + * @throws Exception */ public void createWithEmptyEntityBody(String testName) throws Exception; /** * Tests creation of a resource by submitting * a representation with malformed XML data. + * @param testName + * @throws Exception */ public void createWithMalformedXml(String testName) throws Exception; @@ -74,6 +82,8 @@ public interface ServiceTest { * Tests creation of a resource by submitting * a representation in the wrong XML schema * (e.g. not matching the object's schema). + * @param testName + * @throws Exception */ public void createWithWrongXmlSchema(String testName) throws Exception; @@ -89,6 +99,8 @@ public interface ServiceTest { /** * Tests reading (i.e. retrieval) of a resource. + * @param testName + * @throws Exception */ public void read(String testName) throws Exception; @@ -98,6 +110,8 @@ public interface ServiceTest { * Tests reading (i.e. retrieval) of a non-existent * resource, whose resource identifier does not exist * at the specified URL. + * @param testName + * @throws Exception */ public void readNonExistent(String testName) throws Exception; @@ -111,6 +125,8 @@ public interface ServiceTest { /** * Tests reading (i.e. retrieval) of a list of * multiple resources. + * @param testName + * @throws Exception */ public void readList(String testName) throws Exception; @@ -133,6 +149,8 @@ public interface ServiceTest { /** * Tests updating the content of a resource. + * @param testName + * @throws Exception */ public void update(String testName) throws Exception; @@ -141,6 +159,8 @@ public interface ServiceTest { /** * Tests updating the content of a resource * by submitting an empty entity body (aka empty payload). + * @param testName + * @throws Exception */ public void updateWithEmptyEntityBody(String testName) throws Exception; @@ -148,6 +168,8 @@ public interface ServiceTest { * Tests updating the content of a resource * by submitting a representation with malformed * XML data. + * @param testName + * @throws Exception */ public void updateWithMalformedXml(String testName) throws Exception; @@ -155,12 +177,16 @@ public interface ServiceTest { * Tests updating the content of a resource * by submitting a representation in the wrong * XML schema (e.g. not matching the object's schema). + * @param testName + * @throws Exception */ public void updateWithWrongXmlSchema(String testName) throws Exception; /** * Tests updating the content of a non-existent * resource, whose resource identifier does not exist. + * @param testName + * @throws Exception */ public void updateNonExistent(String testName) throws Exception; @@ -173,6 +199,8 @@ public interface ServiceTest { /** * Tests deleting a resource. + * @param testName + * @throws Exception */ public void delete(String testName) throws Exception; @@ -181,6 +209,8 @@ public interface ServiceTest { /** * Tests deleting a non-existent resource, whose resource * identifier does not exist at the specified URL. + * @param testName + * @throws Exception */ public void deleteNonExistent(String testName) throws Exception; diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index f83f37aa2..1869975e5 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -26,14 +26,8 @@ */ package org.collectionspace.services.client; -import javax.ws.rs.GET; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.common.authorityref.AuthorityRefList; //import org.collectionspace.services.common.context.ServiceContext; @@ -100,12 +94,11 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { } - @Override - public ClientResponse readList(String pageSize, - String pageNumber) { - return collectionObjectProxy.readList(pageSize, pageNumber); - - } +// @Override +// public ClientResponse readList(String pageSize, +// String pageNumber) { +// return collectionObjectProxy.readList(pageSize, pageNumber); +// } /** * Roundtrip. @@ -147,7 +140,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { /** * @param csid - * @return + * @return response * @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String) */ public ClientResponse getAuthorityRefs(String csid) { @@ -188,6 +181,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * @see org.collectionspace.services.client.CollectionObjectProxy#delete() * @return the client response< response> */ + @Override public ClientResponse delete(String csid) { return collectionObjectProxy.delete(csid); } diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java index a454f2279..b6e2941b0 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java @@ -35,15 +35,15 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; +//import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; +//import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.client.IClientQueryParams; +//import org.collectionspace.services.client.IClientQueryParams; import org.collectionspace.services.client.CollectionSpaceProxy; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.jaxb.AbstractCommonList; +//import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -68,6 +68,21 @@ public interface CollectionObjectProxy extends CollectionSpaceProxy { @GET @Produces({"application/xml"}) ClientResponse readList(); + +// /** +// * Read list. +// * +// * @param pageSize the page size +// * @param pageNumber the page number +// * @return the client response +// */ +// @GET +// @Produces({"application/xml"}) +// @Override +// ClientResponse readList( +// @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) String pageSize, +// @QueryParam(IClientQueryParams.START_PAGE_PARAM) String pageNumber); + /** * Roundtrip. diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java index ac23ec854..f0f9737e8 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java @@ -61,22 +61,48 @@ import org.slf4j.LoggerFactory; */ public class CollectionObjectAuthRefsTest extends BaseServiceTest { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(CollectionObjectAuthRefsTest.class); // Instance variables specific to this test. + /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "collectionobjects"; + + /** The PERSO n_ authorit y_ name. */ final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + + /** The known resource id. */ private String knownResourceId = null; - private List collectionObjectIdsCreated = new ArrayList(); - private List personIdsCreated = new ArrayList(); + + /** The collection object ids created. */ + private List collectionObjectIdsCreated = new ArrayList(); + + /** The person ids created. */ + private List personIdsCreated = new ArrayList(); + + /** The CREATE d_ status. */ private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + + /** The O k_ status. */ private int OK_STATUS = Response.Status.OK.getStatusCode(); + + /** The person auth csid. */ private String personAuthCSID = null; + + /** The content organization ref name. */ private String contentOrganizationRefName = null; + + /** The content people ref name. */ private String contentPeopleRefName = null; + + /** The content person ref name. */ private String contentPersonRefName = null; + + /** The inscriber ref name. */ private String inscriberRefName = null; + + /** The NU m_ aut h_ ref s_ expected. */ private final int NUM_AUTH_REFS_EXPECTED = 4; /* (non-Javadoc) @@ -100,6 +126,12 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /** + * Creates the with auth refs. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { @@ -151,6 +183,9 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { collectionObjectIdsCreated.add(extractId(res)); } + /** + * Creates the person refs. + */ protected void createPersonRefs(){ String authRefName = PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); @@ -182,6 +217,14 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { personIdsCreated.add(createPerson("Ingrid", "Inscriber", inscriberRefName)); } + /** + * Creates the person. + * + * @param firstName the first name + * @param surName the sur name + * @param refName the ref name + * @return the string + */ protected String createPerson(String firstName, String surName, String refName ) { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -200,6 +243,12 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { } // Success outcomes + /** + * Read and check auth refs. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { @@ -290,26 +339,40 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); for (String resourceId : collectionObjectIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse res = collectionObjectClient.delete(resourceId); + collectionObjectClient.delete(resourceId).releaseConnection(); } // Note: Any non-success response is ignored and not reported. PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete persons before PersonAuth for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection(); } - ClientResponse res = personAuthClient.delete(personAuthCSID); + personAuthClient.delete(personAuthCSID).releaseConnection(); } // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + /** + * Creates the collection object instance. + * + * @param title the title + * @param objNum the obj num + * @param contentOrganization the content organization + * @param contentPeople the content people + * @param contentPerson the content person + * @param inscriber the inscriber + * @return the multipart output + */ private MultipartOutput createCollectionObjectInstance( String title, String objNum, 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 5b645d0e1..7ed609f17 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 @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -42,7 +41,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -64,21 +62,9 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { /** The known resource id. */ private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /** The multivalue. */ private boolean multivalue; //toggle - /** - * Gets the logger. - * - * @return the logger - */ - private Logger getLogger() { - return this.logger; - } - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() */ @@ -984,36 +970,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun = true) - public void cleanUp() { - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - CollectionObjectClient client = new CollectionObjectClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 1c4862f89..7eb0247be 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -128,7 +128,7 @@ public class DocumentFilter { // Set the page size // String pageSizeStr = null; - List list = queryParams.remove(IClientQueryParams.PAGE_SIZE_PARAM); + List list = queryParams.remove(IClientQueryParams.PAGE_SIZE_PARAM); //REM: Should we really be removing this param? if (list != null) { pageSizeStr = list.get(0); } @@ -138,7 +138,7 @@ public class DocumentFilter { // Set the start page // String startPageStr = null; - list = queryParams.remove(IClientQueryParams.START_PAGE_PARAM); + list = queryParams.remove(IClientQueryParams.START_PAGE_PARAM); //REM: Should we really be removing this param? if (list != null) { startPageStr = list.get(0); } diff --git a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java index eed72b171..b3456559d 100644 --- a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java +++ b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java @@ -61,7 +61,6 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Instance variables specific to this test. final String SERVICE_PATH_COMPONENT = "contacts"; private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -143,14 +142,17 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // See Issue CSPACE-401. @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty?? } @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty?? } /* @@ -406,13 +408,21 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. @Override - public void updateWithEmptyEntityBody(String testName) throws Exception{ + public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty?? } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty?? } + @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty?? } /* @@ -602,30 +612,6 @@ public class ContactServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - ContactClient client = new ContactClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- @@ -633,5 +619,4 @@ public class ContactServiceTest extends AbstractServiceTestImpl { public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - } diff --git a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java index 9d42e934f..ac6b92fc6 100644 --- a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java +++ b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionClient.java @@ -73,6 +73,9 @@ public class DimensionClient extends AbstractServiceClientImpl { setProxy(); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy() + */ @Override public CollectionSpaceProxy getProxy() { return this.dimensionProxy; @@ -140,9 +143,10 @@ public class DimensionClient extends AbstractServiceClientImpl { /** * @param csid - * @return + * @return response * @see org.collectionspace.services.client.DimensionProxy#deleteDimension(java.lang.Long) */ + @Override public ClientResponse delete(String csid) { return dimensionProxy.delete(csid); } diff --git a/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java b/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java index 2f195dcb6..32310fba8 100644 --- a/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java +++ b/services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java @@ -22,7 +22,7 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; +//import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -39,7 +39,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; +//import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -54,13 +54,16 @@ import org.slf4j.LoggerFactory; */ public class DimensionServiceTest extends AbstractServiceTestImpl { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(DimensionServiceTest.class); // Instance variables specific to this test. + /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "dimensions"; + + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -83,6 +86,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -127,6 +133,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { allResourceIdsCreated.add(extractId(res)); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -139,16 +148,28 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -235,6 +256,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -264,6 +288,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -291,6 +318,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -339,6 +369,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -402,14 +435,28 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception{ + //Should this really be empty? } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -492,6 +539,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { } */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) @@ -523,6 +573,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) @@ -547,6 +600,9 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) @@ -598,45 +654,23 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - DimensionClient client = new DimensionClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + /** + * Creates the dimension instance. + * + * @param identifier the identifier + * @return the multipart output + */ private MultipartOutput createDimensionInstance(String identifier) { return createDimensionInstance( "dimensionType-" + identifier, @@ -644,6 +678,14 @@ public class DimensionServiceTest extends AbstractServiceTestImpl { "entryDate-" + identifier); } + /** + * Creates the dimension instance. + * + * @param dimensionType the dimension type + * @param entryNumber the entry number + * @param entryDate the entry date + * @return the multipart output + */ private MultipartOutput createDimensionInstance(String dimensionType, String entryNumber, String entryDate) { DimensionsCommon dimension = new DimensionsCommon(); dimension.setDimension(dimensionType); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java index 557706a0e..a65370056 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java @@ -67,8 +67,8 @@ public class IntakeAuthRefsTest extends BaseServiceTest { final String SERVICE_PATH_COMPONENT = "intakes"; final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private String knownResourceId = null; - private List intakeIdsCreated = new ArrayList(); - private List personIdsCreated = new ArrayList(); + private List intakeIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); private int OK_STATUS = Response.Status.OK.getStatusCode(); private String personAuthCSID = null; @@ -303,14 +303,14 @@ public class IntakeAuthRefsTest extends BaseServiceTest { IntakeClient intakeClient = new IntakeClient(); // Note: Any non-success responses are ignored and not reported. for (String resourceId : intakeIdsCreated) { - ClientResponse res = intakeClient.delete(resourceId); + intakeClient.delete(resourceId).releaseConnection(); } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete persons before PersonAuth for (String resourceId : personIdsCreated) { - ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection(); } - ClientResponse res = personAuthClient.delete(personAuthCSID); + personAuthClient.delete(personAuthCSID).releaseConnection(); } // --------------------------------------------------------------- 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 11433935a..51c7cbcf9 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 @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -38,7 +37,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; +//import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -65,9 +64,6 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { /** The known resource id. */ private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -156,6 +152,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -163,6 +160,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -170,6 +168,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -440,7 +439,8 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) */ @Override - public void updateWithEmptyEntityBody(String testName) throws Exception{ + public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -448,6 +448,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -455,6 +456,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -652,37 +654,6 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - IntakeClient client = new IntakeClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java index 5ccf8709b..d23707081 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java @@ -124,34 +124,37 @@ public class LoaninAuthRefsTest extends BaseServiceTest { lendersAuthorizerRefName, lendersContactRefName, loanInContactRefName); - ClientResponse res = loaninClient.create(multipart); - int statusCode = res.getStatus(); - - // 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? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the ID returned from the first resource created - // for additional tests below. - if (knownResourceId == null){ - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); - } + ClientResponse response = loaninClient.create(multipart); + int statusCode = response.getStatus(); + try { + // 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? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(response); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + loaninIdsCreated.add(extractId(response)); + } finally { + response.releaseConnection(); } - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - loaninIdsCreated.add(extractId(res)); } protected void createPersonRefs(){ @@ -307,7 +310,9 @@ public class LoaninAuthRefsTest extends BaseServiceTest { for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. - personAuthClient.deleteItem(personAuthCSID, resourceId); + ClientResponse response = + personAuthClient.deleteItem(personAuthCSID, resourceId); // alternative to personAuthClient.deleteItem().releaseConnection(); + response.releaseConnection(); } // Delete PersonAuthority resource(s). @@ -315,10 +320,12 @@ public class LoaninAuthRefsTest extends BaseServiceTest { if (personAuthCSID != null) { personAuthClient.delete(personAuthCSID); // Delete Loans In resource(s). - LoaninClient loaninClient = new LoaninClient(); + LoaninClient loaninClient = new LoaninClient(); + ClientResponse response = null; for (String resourceId : loaninIdsCreated) { // Note: Any non-success responses are ignored and not reported. - loaninClient.delete(resourceId); + response = loaninClient.delete(resourceId); // alternative to loaninClient.delete(resourceId).releaseConnection(); + response.releaseConnection(); } } } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index 4b977b6fb..97ec963ed 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -22,7 +22,7 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; +//import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -39,7 +39,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; +//import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -54,13 +54,16 @@ import org.slf4j.LoggerFactory; */ public class LoaninServiceTest extends AbstractServiceTestImpl { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(LoaninServiceTest.class); // Instance variables specific to this test. + /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "loansin"; + + /** The known resource id. */ private String knownResourceId = null; - private List allResourceIdsCreated = new ArrayList(); /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -83,6 +86,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void create(String testName) throws Exception { @@ -96,27 +102,33 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { LoaninClient client = new LoaninClient(); String identifier = createIdentifier(); MultipartOutput multipart = createLoaninInstance(identifier); + String newID = null; ClientResponse res = client.create(multipart); - - int statusCode = res.getStatus(); - - // 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? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // 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? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + newID = extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = extractId(res); + knownResourceId = newID; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -124,9 +136,12 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Store the IDs from every resource created by tests, // so they can be deleted after tests have been run. - allResourceIdsCreated.add(extractId(res)); + allResourceIdsCreated.add(newID); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) @@ -139,16 +154,28 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -235,35 +262,46 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void read(String testName) throws Exception { - // Perform setup. setupRead(testName); // Submit the request to the service and store the response. + MultipartInput input = null; LoaninClient client = new LoaninClient(); ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + input = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - MultipartInput input = (MultipartInput) res.getEntity(); + LoansinCommon loanin = (LoansinCommon) extractPart(input, client.getCommonPartName(), LoansinCommon.class); Assert.assertNotNull(loanin); } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -275,48 +313,60 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); 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)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- // CRUD tests : READ_LIST tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - // Perform setup. setupReadList(testName); // Submit the request to the service and store the response. + LoansinCommonList list = null; LoaninClient client = new LoaninClient(); ClientResponse res = client.readList(); - LoansinCommonList list = res.getEntity(); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + list = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; - if(iterateThroughList && logger.isDebugEnabled()){ + if (iterateThroughList && logger.isDebugEnabled()){ List items = list.getLoaninListItem(); int i = 0; @@ -330,7 +380,6 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { i++; } } - } // Failure outcomes @@ -339,6 +388,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"read"}) @@ -348,18 +400,24 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { setupUpdate(testName); // Retrieve the contents of a resource to update. + MultipartInput input = null; LoaninClient client = new LoaninClient(); ClientResponse res = - client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got object to update with ID: " + knownResourceId); + client.read(knownResourceId); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got object to update with ID: " + knownResourceId); + } + input = res.getEntity(); + } finally { + res.releaseConnection(); } - MultipartInput input = (MultipartInput) res.getEntity(); + LoansinCommon loanin = (LoansinCommon) extractPart(input, client.getCommonPartName(), LoansinCommon.class); Assert.assertNotNull(loanin); @@ -377,17 +435,22 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { 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(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - - input = (MultipartInput) res.getEntity(); + LoansinCommon updatedLoanin = (LoansinCommon) extractPart(input, client.getCommonPartName(), LoansinCommon.class); @@ -396,20 +459,33 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(updatedLoanin.getLoanReturnDate(), loanin.getLoanReturnDate(), "Data in updated object did not match submitted data."); - } // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override - public void updateWithEmptyEntityBody(String testName) throws Exception{ + public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -492,6 +568,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { } */ + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"}) @@ -507,22 +586,29 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = createLoaninInstance(NON_EXISTENT_ID); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- // CRUD tests : DELETE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) @@ -534,40 +620,50 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); ClientResponse res = client.delete(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"delete"}) public void deleteNonExistent(String testName) throws Exception { - // Perform setup. setupDeleteNonExistent(testName); // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); 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)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- @@ -598,44 +694,36 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - LoaninClient client = new LoaninClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + /** + * Creates the loanin instance. + * + * @param identifier the identifier + * @return the multipart output + */ private MultipartOutput createLoaninInstance(String identifier) { return createLoaninInstance( "loaninNumber-" + identifier, "returnDate-" + identifier); } + /** + * Creates the loanin instance. + * + * @param loaninNumber the loanin number + * @param returnDate the return date + * @return the multipart output + */ private MultipartOutput createLoaninInstance(String loaninNumber, String returnDate) { LoansinCommon loanin = new LoansinCommon(); diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java index b19069700..212081a14 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -39,7 +38,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -65,9 +63,6 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { /** The known resource id. */ private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -156,6 +151,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -163,6 +159,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -170,6 +167,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -440,6 +438,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception{ + //Should this really be empty? } /* (non-Javadoc) @@ -447,6 +446,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -454,6 +454,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -651,37 +652,6 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { } - // --------------------------------------------------------------- - // Cleanup of resources created during testing - // --------------------------------------------------------------- - - /** - * Deletes all resources created by tests, after all tests have been run. - * - * This cleanup method will always be run, even if one or more tests fail. - * For this reason, it attempts to remove all resources created - * at any point during testing, even if some of those resources - * may be expected to be deleted by certain tests. - */ - @AfterClass(alwaysRun=true) - public void cleanUp() { - String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Cleanup phase ..."); - } - return; - } - if (logger.isDebugEnabled()) { - logger.debug("Cleaning up temporary resources created for testing ..."); - } - LoanoutClient client = new LoanoutClient(); - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } - } - // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java index 449697f9d..caccb3523 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java @@ -1,3 +1,29 @@ +/** + * OrgAuthorityClientUtils.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * 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 {Contributing Institution} + * + * 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 + */ package org.collectionspace.services.client; import java.util.ArrayList; @@ -17,10 +43,23 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * The Class OrgAuthorityClientUtils. + */ public class OrgAuthorityClientUtils { + + /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(OrgAuthorityClientUtils.class); + /** + * Creates the org authority instance. + * + * @param displayName the display name + * @param refName the ref name + * @param headerLabel the header label + * @return the multipart output + */ public static MultipartOutput createOrgAuthorityInstance( String displayName, String refName, String headerLabel ) { OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); @@ -39,6 +78,15 @@ public class OrgAuthorityClientUtils { return multipart; } + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param orgAuthorityRefName the org authority ref name + * @param orgInfo the org info + * @param client the client + * @return the string + */ public static String createItemInAuthority(String vcsid, String orgAuthorityRefName, Map orgInfo, OrgAuthorityClient client) { @@ -58,31 +106,46 @@ public class OrgAuthorityClientUtils { orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ), orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE )); } - String refName = createOrganizationRefName( orgAuthorityRefName, displayName, true); + String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true); if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+displayName +"\" in orgAuthority: \"" + orgAuthorityRefName +"\""); } MultipartOutput multipart = - createOrganizationInstance( vcsid, refName, orgInfo, client.getItemCommonPartName() ); + createOrganizationInstance(vcsid, refName, orgInfo, client.getItemCommonPartName()); ClientResponse res = client.createItem(vcsid, multipart); - - int statusCode = res.getStatus(); - - if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+displayName - +"\" in orgAuthority: \"" + orgAuthorityRefName - +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + String result; + try { + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+displayName + +"\" in orgAuthority: \"" + orgAuthorityRefName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+ displayName + +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode); + } + + result = extractId(res); + } finally { + res.releaseConnection(); } - if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+displayName - +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode); - } - - return extractId(res); + + return result; } + /** + * Creates the organization instance. + * + * @param inAuthority the in authority + * @param orgRefName the org ref name + * @param orgInfo the org info + * @param headerLabel the header label + * @return the multipart output + */ public static MultipartOutput createOrganizationInstance(String inAuthority, String orgRefName, Map orgInfo, String headerLabel){ OrganizationsCommon organization = new OrganizationsCommon(); @@ -147,6 +210,12 @@ public class OrgAuthorityClientUtils { requestType.validStatusCodesAsString(); } + /** + * Extract id. + * + * @param res the res + * @return the string + */ public static String extractId(ClientResponse res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); @@ -161,6 +230,13 @@ public class OrgAuthorityClientUtils { return id; } + /** + * Creates the org auth ref name. + * + * @param orgAuthorityName the org authority name + * @param withDisplaySuffix the with display suffix + * @return the string + */ public static String createOrgAuthRefName(String orgAuthorityName, boolean withDisplaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:orgauthority:name(" +orgAuthorityName+")"; @@ -169,6 +245,14 @@ public class OrgAuthorityClientUtils { return refName; } + /** + * Creates the organization ref name. + * + * @param orgAuthRefName the org auth ref name + * @param orgName the org name + * @param withDisplaySuffix the with display suffix + * @return the string + */ public static String createOrganizationRefName( String orgAuthRefName, String orgName, boolean withDisplaySuffix) { String refName = orgAuthRefName+":organization:name("+orgName+")"; diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java index 1a2ec608f..419339942 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java @@ -60,23 +60,49 @@ import org.slf4j.LoggerFactory; */ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(OrgAuthorityAuthRefsTest.class); // Instance variables specific to this test. + /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "orgauthorities"; + + /** The PERSO n_ authorit y_ name. */ final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + + /** The known resource ref name. */ private String knownResourceRefName = null; + + /** The known auth resource id. */ private String knownAuthResourceId = null; + + /** The known item id. */ private String knownItemId = null; + + /** The all resource ids created. */ private List allResourceIdsCreated = new ArrayList(); + + /** The all item resource ids created. */ private Map allItemResourceIdsCreated = new HashMap(); - private List personIdsCreated = new ArrayList(); + + /** The person ids created. */ + private List personIdsCreated = new ArrayList(); + + /** The CREATE d_ status. */ private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + + /** The O k_ status. */ private int OK_STATUS = Response.Status.OK.getStatusCode(); + + /** The person auth csid. */ private String personAuthCSID = null; + + /** The organization contact person ref name. */ private String organizationContactPersonRefName = null; + + /** The NU m_ aut h_ ref s_ expected. */ private final int NUM_AUTH_REFS_EXPECTED = 1; /* (non-Javadoc) @@ -100,6 +126,12 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /** + * Creates the with auth refs. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) public void createWithAuthRefs(String testName) throws Exception { @@ -114,28 +146,31 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { OrgAuthorityClientUtils.createOrgAuthRefName(displayName, createWithDisplayName); MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, knownResourceRefName, new OrgAuthorityClient().getCommonPartName()); + displayName, knownResourceRefName, orgAuthClient.getCommonPartName()); // Submit the request to the service and store the response. ClientResponse res = orgAuthClient.create(multipart); - int statusCode = res.getStatus(); - - // 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? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - knownAuthResourceId = extractId(res); + try { + int statusCode = res.getStatus(); + // 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? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + knownAuthResourceId = extractId(res); + } finally { + res.releaseConnection(); + } allResourceIdsCreated.add(knownAuthResourceId); // Create all the person refs and entities @@ -159,23 +194,15 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { knownItemId = OrgAuthorityClientUtils.createItemInAuthority( knownAuthResourceId, knownResourceRefName, testOrgMap, orgAuthClient); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the IDs from every item created by tests, // so they can be deleted after tests have been run. allItemResourceIdsCreated.put(knownItemId, knownAuthResourceId); - } - protected void createPersonRefs(){ - + /** + * Creates the person refs. + */ + protected void createPersonRefs() { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. @@ -183,13 +210,17 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); - ClientResponse res = personAuthClient.create(multipart); - int statusCode = res.getStatus(); - - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, CREATED_STATUS); - personAuthCSID = extractId(res); + + ClientResponse res = personAuthClient.create(multipart); + try { + int statusCode = res.getStatus(); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + personAuthCSID = extractId(res); + } finally { + res.releaseConnection(); + } // Create a temporary Person resource, and its corresponding refName // by which it can be identified. @@ -199,6 +230,14 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { } + /** + * Creates the person. + * + * @param firstName the first name + * @param surName the sur name + * @param refName the ref name + * @return the string + */ protected String createPerson(String firstName, String surName, String refName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); @@ -207,16 +246,30 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, refName, personInfo, personAuthClient.getItemCommonPartName()); - ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); - int statusCode = res.getStatus(); - - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, CREATED_STATUS); - return extractId(res); + + String result = null; + ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + try { + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + result = extractId(res); + } finally { + res.releaseConnection(); + } + + return result; } // Success outcomes + /** + * Read and check auth refs. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createWithAuthRefs"}) public void readAndCheckAuthRefs(String testName) throws Exception { @@ -310,14 +363,14 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete Person resource(s) (before PersonAuthority resources). - ClientResponse res; for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. - res = personAuthClient.deleteItem(personAuthCSID, resourceId); + personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection(); } // Delete PersonAuthority resource(s). // Note: Any non-success response is ignored and not reported. - res = personAuthClient.delete(personAuthCSID); + personAuthClient.delete(personAuthCSID).releaseConnection(); + String parentResourceId; String itemResourceId; OrgAuthorityClient client = new OrgAuthorityClient(); @@ -327,24 +380,34 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { parentResourceId = entry.getValue(); // Note: Any non-success responses from the delete operation // below are ignored and not reported. - res = client.deleteItem(parentResourceId, itemResourceId); + client.deleteItem(parentResourceId, itemResourceId).releaseConnection(); } + // Clean up parent resources. for (String resourceId : allResourceIdsCreated) { // Note: Any non-success responses from the delete operation // below are ignored and not reported. - res = client.delete(resourceId); + client.delete(resourceId).releaseConnection(); } } // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + /** + * Creates the org authority instance. + * + * @param identifier the identifier + * @return the multipart output + */ private MultipartOutput createOrgAuthorityInstance(String identifier) { String displayName = "displayName-" + identifier; String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true); diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index db4d0ac4d..00a58f8f8 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,24 +61,49 @@ import org.testng.annotations.Test; */ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { + /** The logger. */ private final Logger logger = LoggerFactory.getLogger(OrgAuthorityServiceTest.class); // Instance variables specific to this test. + /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "orgauthorities"; + + /** The ITE m_ servic e_ pat h_ component. */ final String ITEM_SERVICE_PATH_COMPONENT = "items"; + + /** The CONTAC t_ servic e_ pat h_ component. */ final String CONTACT_SERVICE_PATH_COMPONENT = "contacts"; + + /** The TES t_ or g_ shortname. */ private final String TEST_ORG_SHORTNAME = "Test Org"; + + /** The TES t_ or g_ foundin g_ place. */ private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA"; + + /** The known resource id. */ private String knownResourceId = null; + + /** The known resource display name. */ private String knownResourceDisplayName = null; + + /** The known resource ref name. */ private String knownResourceRefName = null; + + /** The known item resource id. */ private String knownItemResourceId = null; + + /** The known contact resource id. */ private String knownContactResourceId = null; + + /** The n items to create in list. */ private int nItemsToCreateInList = 3; - private List allResourceIdsCreated = new ArrayList(); + + /** The all item resource ids created. */ private Map allItemResourceIdsCreated = new HashMap(); + + /** The all contact resource ids created. */ private Map allContactResourceIdsCreated = new HashMap(); @@ -104,6 +128,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"create"}) @@ -122,27 +149,34 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( displayName, refName, client.getCommonPartName()); - ClientResponse res = client.create(multipart); - int statusCode = res.getStatus(); - - // 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? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + + String newID = null; + ClientResponse res = client.create(multipart); + try { + int statusCode = res.getStatus(); + + // 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? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the refname from the first resource created + // for additional tests below. + knownResourceRefName = refName; + + newID = OrgAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the refname from the first resource created - // for additional tests below. - knownResourceRefName = refName; - - String newID = OrgAuthorityClientUtils.extractId(res); + // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ @@ -157,6 +191,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { allResourceIdsCreated.add(newID); } + /** + * Creates the item. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"create"}, dependsOnMethods = {"create"}) public void createItem(String testName) { @@ -164,6 +203,13 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { String newID = createItemInAuthority(knownResourceId, knownResourceRefName); } + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param authRefName the auth ref name + * @return the string + */ private String createItemInAuthority(String vcsid, String authRefName) { final String testName = "createItemInAuthority"; @@ -201,6 +247,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { return newID; } + /** + * Creates the contact. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"create"}, dependsOnMethods = {"createItem"}) public void createContact(String testName) { @@ -208,6 +259,13 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { String newID = createContactInItem(knownResourceId, knownItemResourceId); } + /** + * Creates the contact in item. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @return the string + */ private String createContactInItem(String parentcsid, String itemcsid) { final String testName = "createContactInItem"; @@ -222,19 +280,25 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = ContactClientUtils.createContactInstance(parentcsid, itemcsid, identifier, new ContactClient().getCommonPartName()); + + String newID = null; ClientResponse res = client.createContact(parentcsid, itemcsid, multipart); - int statusCode = res.getStatus(); - String newID = OrgAuthorityClientUtils.extractId(res); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + newID = OrgAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Store the ID returned from the first contact resource created // for additional tests below. @@ -257,16 +321,28 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -353,7 +429,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // CRUD tests : CREATE LIST tests // --------------------------------------------------------------- // Success outcomes - @Override + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ +@Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"createList"}, dependsOnGroups = {"create"}) public void createList(String testName) throws Exception { @@ -362,6 +441,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the item list. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"createList"}, dependsOnMethods = {"createList"}) public void createItemList(String testName) throws Exception { @@ -371,6 +456,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } } + /** + * Creates the contact list. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"createList"}, dependsOnMethods = {"createItemList"}) public void createContactList(String testName) throws Exception { @@ -384,6 +475,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // CRUD tests : READ tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) @@ -395,27 +489,37 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": 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(); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": 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(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } + /** + * Read by name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) public void readByName(String testName) throws Exception { @@ -426,24 +530,28 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readByName(knownResourceDisplayName); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": 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(); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": 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(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } @@ -479,7 +587,13 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } */ - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + /** + * Read item. + * + * @param testName the test name + * @throws Exception the exception + */ +@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"read"}) public void readItem(String testName) throws Exception { @@ -489,31 +603,41 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a organization. - MultipartInput input = (MultipartInput) res.getEntity(); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a organization. + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(organization, + OrganizationsCommon.class)); + } + Assert.assertEquals(organization.getInAuthority(), knownResourceId); + } finally { + res.releaseConnection(); } - Assert.assertEquals(organization.getInAuthority(), knownResourceId); } + /** + * Verify item display name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"readItem", "updateItem"}) public void verifyItemDisplayName(String testName) throws Exception { @@ -523,20 +647,26 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); + MultipartInput input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether organization has expected displayName. + input = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether organization has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(organization); @@ -560,18 +690,23 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + OrganizationsCommon updatedOrganization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); @@ -594,18 +729,23 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + updatedOrganization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); @@ -620,6 +760,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { "Updated DisplayName (not computed) in Organization not stored."); } + /** + * Verify illegal item display name. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"verifyItemDisplayName"}) public void verifyIllegalItemDisplayName(String testName) throws Exception { @@ -666,6 +812,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Read contact. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { @@ -705,6 +857,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"read"}) @@ -728,6 +883,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Read item non existent. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"readItem"}) public void readItemNonExistent(String testName) { @@ -750,6 +910,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Read contact non existent. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { @@ -778,6 +943,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"readList"}, dependsOnGroups = {"createList", "read"}) @@ -821,16 +989,28 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } } + /** + * Read item list. + */ @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) public void readItemList() { readItemList(knownResourceId, null); } + /** + * Read item list by authority name. + */ @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) public void readItemListByAuthorityName() { readItemList(null, knownResourceDisplayName); } + /** + * Read item list. + * + * @param vcsid the vcsid + * @param name the name + */ private void readItemList(String vcsid, String name) { final String testName = "readItemList"; @@ -896,11 +1076,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } } + /** + * Read contact list. + */ @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) public void readContactList() { readContactList(knownResourceId, knownItemResourceId); } + /** + * Read contact list. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + */ private void readContactList(String parentcsid, String itemcsid) { final String testName = "readContactList"; @@ -962,6 +1151,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // CRUD tests : UPDATE tests // --------------------------------------------------------------- // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnGroups = {"read", "readList"}) @@ -1023,6 +1215,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { "Data in updated object did not match submitted data."); } + /** + * Update item. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"update"}) public void updateItem(String testName) throws Exception { @@ -1086,6 +1284,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { "Data in updated Organization did not match submitted data."); } + /** + * Update contact. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"updateItem"}) public void updateContact(String testName) throws Exception { @@ -1152,16 +1356,28 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -1244,7 +1460,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } */ - @Override + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ +@Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { @@ -1271,6 +1490,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Update non existent item. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) public void updateNonExistentItem(String testName) throws Exception { @@ -1303,6 +1528,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Update non existent contact. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"}) public void updateNonExistentContact(String testName) throws Exception { @@ -1317,6 +1548,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Note: delete sub-resources in ascending hierarchical order, // before deleting their parents. + /** + * Delete contact. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) public void deleteContact(String testName) throws Exception { @@ -1346,6 +1583,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Delete item. + * + * @param testName the test name + * @throws Exception the exception + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteItem(String testName) throws Exception { @@ -1373,6 +1616,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnMethods = {"deleteItem"}) @@ -1401,6 +1647,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnMethods = {"delete"}) @@ -1424,6 +1673,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Delete non existent item. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnMethods = {"deleteItem"}) public void deleteNonExistentItem(String testName) { @@ -1446,6 +1700,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + /** + * Delete non existent contact. + * + * @param testName the test name + */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"delete"}, dependsOnMethods = {"deleteContact"}) public void deleteNonExistentContact(String testName) { @@ -1497,6 +1756,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } + /** + * Test item submit request. + */ @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) public void testItemSubmitRequest() { @@ -1518,6 +1780,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } + /** + * Test contact submit request. + */ @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"}) public void testContactSubmitRequest() { @@ -1555,6 +1820,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { */ @AfterClass(alwaysRun=true) + @Override public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { @@ -1566,6 +1832,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } + String parentResourceId; String itemResourceId; String contactResourceId; @@ -1579,6 +1846,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // below are ignored and not reported. ClientResponse res = client.deleteContact(parentResourceId, itemResourceId, contactResourceId); + res.releaseConnection(); } // Clean up item resources. for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { @@ -1588,27 +1856,38 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // below are ignored and not reported. ClientResponse res = client.deleteItem(parentResourceId, itemResourceId); + res.releaseConnection(); } // Clean up parent resources. - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses from the delete operation - // below are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } + super.cleanUp(); + } // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } + /** + * Gets the item service path component. + * + * @return the item service path component + */ public String getItemServicePathComponent() { return ITEM_SERVICE_PATH_COMPONENT; } + /** + * Gets the contact service path component. + * + * @return the contact service path component + */ public String getContactServicePathComponent() { return CONTACT_SERVICE_PATH_COMPONENT; } @@ -1686,6 +1965,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { itemResourceIdentifier) + "/" + contactResourceIdentifier; } + /** + * Creates the org authority instance. + * + * @param identifier the identifier + * @return the multipart output + */ private MultipartOutput createOrgAuthorityInstance(String identifier) { String displayName = "displayName-" + identifier; String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true); diff --git a/services/person/client/pom.xml b/services/person/client/pom.xml index 4c7f7d649..a9c46ab4e 100644 --- a/services/person/client/pom.xml +++ b/services/person/client/pom.xml @@ -56,6 +56,7 @@ testng 5.6 + org.jboss.resteasy resteasy-jaxrs @@ -75,6 +76,7 @@ org.jboss.resteasy resteasy-multipart-provider + commons-httpclient commons-httpclient diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index fb28b2979..a62708048 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -1,3 +1,29 @@ +/** + * PersonAuthorityClientUtils.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * 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 {Contributing Institution} + * + * 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 + */ package org.collectionspace.services.client; import java.util.ArrayList; @@ -19,10 +45,23 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * The Class PersonAuthorityClientUtils. + */ public class PersonAuthorityClientUtils { + + /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(PersonAuthorityClientUtils.class); + /** + * Creates the person authority instance. + * + * @param displayName the display name + * @param refName the ref name + * @param headerLabel the header label + * @return the multipart output + */ public static MultipartOutput createPersonAuthorityInstance( String displayName, String refName, String headerLabel ) { PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon(); @@ -41,6 +80,15 @@ public class PersonAuthorityClientUtils { return multipart; } + /** + * Creates the person instance. + * + * @param inAuthority the in authority + * @param personRefName the person ref name + * @param personInfo the person info + * @param headerLabel the header label + * @return the multipart output + */ public static MultipartOutput createPersonInstance(String inAuthority, String personRefName, Map personInfo, String headerLabel){ PersonsCommon person = new PersonsCommon(); @@ -98,6 +146,15 @@ public class PersonAuthorityClientUtils { return multipart; } + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param personAuthorityRefName the person authority ref name + * @param personMap the person map + * @param client the client + * @return the string + */ public static String createItemInAuthority(String vcsid, String personAuthorityRefName, Map personMap, PersonAuthorityClient client ) { @@ -132,23 +189,37 @@ public class PersonAuthorityClientUtils { MultipartOutput multipart = createPersonInstance( vcsid, refName, personMap, client.getItemCommonPartName() ); + + String result = null; ClientResponse res = client.createItem(vcsid, multipart); - - int statusCode = res.getStatus(); - - if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+refName - +"\" in personAuthority: \"" + personAuthorityRefName - +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + try { + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+refName + +"\" in personAuthority: \"" + personAuthorityRefName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+refName + +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode); + } + + result = extractId(res); + } finally { + res.releaseConnection(); } - if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+refName - +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode); - } - - return extractId(res); + + return result; } + /** + * Creates the person auth ref name. + * + * @param personAuthorityName the person authority name + * @param withDisplaySuffix the with display suffix + * @return the string + */ public static String createPersonAuthRefName(String personAuthorityName, boolean withDisplaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:personauthority:name(" +personAuthorityName+")"; @@ -157,6 +228,14 @@ public class PersonAuthorityClientUtils { return refName; } + /** + * Creates the person ref name. + * + * @param personAuthRefName the person auth ref name + * @param personName the person name + * @param withDisplaySuffix the with display suffix + * @return the string + */ public static String createPersonRefName( String personAuthRefName, String personName, boolean withDisplaySuffix) { String refName = personAuthRefName+":person:name("+personName+")"; @@ -165,6 +244,12 @@ public class PersonAuthorityClientUtils { return refName; } + /** + * Extract id. + * + * @param res the res + * @return the string + */ public static String extractId(ClientResponse res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); @@ -208,7 +293,7 @@ public class PersonAuthorityClientUtils { * @param surName * @param birthDate * @param deathDate - * @return + * @return display name */ public static String prepareDefaultDisplayName( String foreName, String middleName, String surName, diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 3006ad2c3..ad22c3e71 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -108,9 +107,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { /** The n items to create in list. */ private int nItemsToCreateInList = 3; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /** The all item resource ids created. */ private Map allItemResourceIdsCreated = new HashMap(); @@ -162,27 +158,32 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( displayName, fullRefName, client.getCommonPartName()); - ClientResponse res = client.create(multipart); - int statusCode = res.getStatus(); - - // 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? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - + + String newID = null; + ClientResponse res = client.create(multipart); + try { + int statusCode = res.getStatus(); + + // 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? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + newID = PersonAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); + } // Store the refname from the first resource created // for additional tests below. knownResourceRefName = baseRefName; - - String newID = PersonAuthorityClientUtils.extractId(res); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ @@ -243,18 +244,24 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap, client.getItemCommonPartName() ); + + String newID = null; ClientResponse res = client.createItem(vcsid, multipart); - int statusCode = res.getStatus(); - String newID = PersonAuthorityClientUtils.extractId(res); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + newID = PersonAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Store the ID returned from the first item resource created // for additional tests below. @@ -306,19 +313,25 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = ContactClientUtils.createContactInstance(parentcsid, itemcsid, identifier, new ContactClient().getCommonPartName()); + + String newID = null; ClientResponse res = client.createContact(parentcsid, itemcsid, multipart); - int statusCode = res.getStatus(); - String newID = PersonAuthorityClientUtils.extractId(res); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + newID = PersonAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Store the ID returned from the first contact resource created // for additional tests below. @@ -346,6 +359,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -353,6 +367,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -360,6 +375,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void createWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -449,7 +465,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) */ -@Override + @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"createList"}, dependsOnGroups = {"create"}) public void createList(String testName) throws Exception { @@ -506,24 +522,27 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": 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(); - PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); - Assert.assertNotNull(personAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": 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(); + PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, + client.getCommonPartName(), PersonauthoritiesCommon.class); + Assert.assertNotNull(personAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } @@ -537,30 +556,33 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { groups = {"read"}, dependsOnGroups = {"create"}) public void readByName(String testName) throws Exception { - // Perform setup. + // Perform setup. setupRead(); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readByName(knownResourceDisplayName); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": 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(); - PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); - Assert.assertNotNull(personAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": 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(); + PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, + client.getCommonPartName(), PersonauthoritiesCommon.class); + Assert.assertNotNull(personAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } @@ -605,36 +627,38 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"read"}) public void readItem(String testName) throws Exception { - // Perform setup. setupRead(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a person. - MultipartInput input = (MultipartInput) res.getEntity(); - PersonsCommon person = (PersonsCommon) extractPart(input, - client.getItemCommonPartName(), PersonsCommon.class); - Assert.assertNotNull(person); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(person, PersonsCommon.class)); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a person. + MultipartInput input = (MultipartInput) res.getEntity(); + PersonsCommon person = (PersonsCommon) extractPart(input, + client.getItemCommonPartName(), PersonsCommon.class); + Assert.assertNotNull(person); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(person, PersonsCommon.class)); + } + Assert.assertEquals(person.getInAuthority(), knownResourceId); + } finally { + res.releaseConnection(); } - Assert.assertEquals(person.getInAuthority(), knownResourceId); - } /** @@ -646,26 +670,31 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"readItem", "updateItem"}) public void verifyItemDisplayName(String testName) throws Exception { - // Perform setup. setupUpdate(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + MultipartInput input =null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether person has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether person has expected displayName. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); + } + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); @@ -676,7 +705,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { TEST_FORE_NAME, null, TEST_SUR_NAME, TEST_BIRTH_DATE, TEST_DEATH_DATE); Assert.assertNotNull(displayName, expectedDisplayName); - + // Update the shortName and verify the computed name is updated. person.setCsid(null); person.setDisplayNameComputed(true); @@ -691,18 +720,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + PersonsCommon updatedPerson = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); @@ -725,18 +759,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + updatedPerson = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); @@ -766,20 +805,26 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + MultipartInput input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + // Check whether Person has expected displayName. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - // Check whether Person has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); @@ -792,15 +837,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } /** @@ -812,28 +861,33 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { - // Perform setup. setupRead(testName); // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + MultipartInput input = null; ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a contact. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a contact. - MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); @@ -862,16 +916,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); 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)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } /** @@ -889,16 +946,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } /** @@ -917,16 +978,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } // --------------------------------------------------------------- @@ -947,18 +1012,24 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + PersonauthoritiesCommonList list = null; ClientResponse res = client.readList(); - PersonauthoritiesCommonList list = res.getEntity(); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + list = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; @@ -1012,24 +1083,30 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = null; - if(vcsid!= null) { + if (vcsid!= null) { res = client.readItemList(vcsid); - } else if(name!= null) { + } else if (name!= null) { res = client.readItemListForNamedAuthority(name); } else { Assert.fail("readItemList passed null csid and name!"); } - PersonsCommonList list = res.getEntity(); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + PersonsCommonList list = null; + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + list = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); List items = list.getPersonListItem(); @@ -1089,20 +1166,26 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); + ContactsCommonList list = null; ClientResponse res = client.readContactList(parentcsid, itemcsid); - ContactsCommonList list = res.getEntity(); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + list = res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - + List listitems = list.getContactListItem(); int nItemsReturned = listitems.size(); @@ -1155,17 +1238,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse res = - client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got PersonAuthority to update with ID: " + knownResourceId); + MultipartInput input = null; + ClientResponse res = client.read(knownResourceId); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got PersonAuthority to update with ID: " + knownResourceId); + } + input = res.getEntity(); + } finally { + res.releaseConnection(); } - MultipartInput input = (MultipartInput) res.getEntity(); + PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, client.getCommonPartName(), PersonauthoritiesCommon.class); Assert.assertNotNull(personAuthority); @@ -1183,18 +1271,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(personAuthority, 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(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + PersonauthoritiesCommon updatedPersonAuthority = (PersonauthoritiesCommon) extractPart(input, client.getCommonPartName(), PersonauthoritiesCommon.class); @@ -1221,19 +1314,25 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); + MultipartInput input = null; ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Person to update with ID: " + - knownItemResourceId + - " in PersonAuthority: " + knownResourceId ); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Person to update with ID: " + + knownItemResourceId + + " in PersonAuthority: " + knownResourceId ); + } + input = res.getEntity(); + } finally { + res.releaseConnection(); } - MultipartInput input = (MultipartInput) res.getEntity(); + PersonsCommon person = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); Assert.assertNotNull(person); @@ -1252,18 +1351,23 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getItemCommonPartName()); res = client.updateItem(knownResourceId, knownItemResourceId, output); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); + PersonsCommon updatedPerson = (PersonsCommon) extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); @@ -1284,26 +1388,31 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"update"}, dependsOnMethods = {"updateItem"}) public void updateContact(String testName) throws Exception { - // Perform setup. setupUpdate(testName); // Retrieve the contents of a resource to update. PersonAuthorityClient client = new PersonAuthorityClient(); + MultipartInput input = null; ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Contact to update with ID: " + - knownContactResourceId + - " in item: " + knownItemResourceId + - " in parent: " + knownResourceId ); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Contact to update with ID: " + + knownContactResourceId + + " in item: " + knownItemResourceId + + " in parent: " + knownResourceId ); + } + input = res.getEntity(); + } finally { + res.releaseConnection(); } - MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); @@ -1321,18 +1430,22 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", new ContactClient().getCommonPartName()); res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); ContactsCommon updatedContact = (ContactsCommon) extractPart(input, new ContactClient().getCommonPartName(), ContactsCommon.class); @@ -1352,6 +1465,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithEmptyEntityBody(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -1359,6 +1473,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithMalformedXml(String testName) throws Exception { + //Should this really be empty? } /* (non-Javadoc) @@ -1366,6 +1481,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @Override public void updateWithWrongXmlSchema(String testName) throws Exception { + //Should this really be empty? } /* @@ -1469,16 +1585,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { displayName, fullRefName, client.getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } /** @@ -1508,16 +1628,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } /** @@ -1564,6 +1688,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1597,6 +1722,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1627,6 +1753,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.delete(knownResourceId); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1654,6 +1781,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1681,6 +1809,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1709,6 +1838,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); int statusCode = res.getStatus(); + res.releaseConnection(); // Check the status code of the response: does it match // the expected response(s)? @@ -1812,6 +1942,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { */ @AfterClass(alwaysRun=true) + @Override public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { @@ -1836,6 +1967,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // below are ignored and not reported. ClientResponse res = client.deleteContact(parentResourceId, itemResourceId, contactResourceId); + res.releaseConnection(); } // Clean up item resources. for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { @@ -1845,13 +1977,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // below are ignored and not reported. ClientResponse res = client.deleteItem(parentResourceId, itemResourceId); + res.releaseConnection(); } // Clean up parent resources. - for (String resourceId : allResourceIdsCreated) { - // Note: Any non-success responses from the delete operation - // below are ignored and not reported. - ClientResponse res = client.delete(resourceId); - } + super.cleanUp(); } // --------------------------------------------------------------- diff --git a/services/person/import/pom.xml b/services/person/import/pom.xml index 13b28b703..79dc82721 100644 --- a/services/person/import/pom.xml +++ b/services/person/import/pom.xml @@ -18,14 +18,11 @@ org.slf4j slf4j-api - 1.5.2 - - + org.collectionspace.services org.collectionspace.services.person.jaxb diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 1b6070ee2..a02ee7ab2 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -47,14 +47,14 @@ import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResou import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; -import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.common.context.MultipartServiceContext; +//import org.collectionspace.services.common.authorityref.AuthorityRefList; +//import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; -import org.collectionspace.services.common.context.MultipartServiceContextImpl; +//import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.BadRequestException; -import org.collectionspace.services.common.document.DocumentException; +//import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; @@ -62,14 +62,14 @@ import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; -import org.collectionspace.services.common.vocabulary.RefNameUtils; +//import org.collectionspace.services.common.vocabulary.RefNameUtils; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.contact.ContactJAXBSchema; import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; @@ -265,7 +265,7 @@ public class PersonAuthorityResource extends @GET @Path("urn:cspace:name({specifier})") public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) { - String idValue = null; +//REM: String idValue = null; if (specifier == null) { logger.error("getPersonAuthority: missing name!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( @@ -325,6 +325,7 @@ public class PersonAuthorityResource extends * can be passed as a query param "type", and must match a configured type * for the service bindings. If not set, the type defaults to * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. + * @param parentcsid * * @param csid the parent csid * @param itemcsid the person csid @@ -334,7 +335,7 @@ public class PersonAuthorityResource extends */ @GET @Path("{csid}/items/{itemcsid}/refObjs") - @Produces("application/xml") + @Produces("application/xml") //FIXME: REM do this for CSPACE-1079 in Org authority. public AuthorityRefDocList getReferencingObjects( @PathParam("csid") String parentcsid, @PathParam("itemcsid") String itemcsid, @@ -355,7 +356,7 @@ public class PersonAuthorityResource extends } try { // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName()); + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName()); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); RepositoryClient repoClient = getRepositoryClient(ctx); DocumentFilter myFilter = handler.createDocumentFilter(); @@ -463,16 +464,16 @@ public class PersonAuthorityResource extends public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) { PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList(); try { - ServiceContext ctx = createServiceContext(); MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME +//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); +//REM: myFilter.setPagination(queryParams); //FIXME String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { - myFilter.setWhereClause("personauthorities_common:refName='" + nameQ + "'"); + handler.getDocumentFilter().setWhereClause("personauthorities_common:refName='" + nameQ + "'"); } - handler.setDocumentFilter(myFilter); +//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -588,9 +589,15 @@ public class PersonAuthorityResource extends } - /************************************************************************* + /** + * *********************************************************************** * Person parts - this is a sub-resource of PersonAuthority - *************************************************************************/ + * ***********************************************************************. + * + * @param parentcsid the parentcsid + * @param input the input + * @return the response + */ @POST @Path("{csid}/items") public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) { @@ -705,11 +712,11 @@ public class PersonAuthorityResource extends ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method +//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); +//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" - myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + + handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); // AND persons_common:displayName LIKE '%partialTerm%' @@ -719,10 +726,9 @@ public class PersonAuthorityResource extends PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause); - } - - handler.setDocumentFilter(myFilter); + handler.getDocumentFilter().appendWhereClause(ptClause); + } +//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -771,11 +777,11 @@ public class PersonAuthorityResource extends ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME +//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); +//REM: myFilter.setPagination(queryParams); //FIXME // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" - myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + + handler.createDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); // AND persons_common:displayName LIKE '%partialTerm%' @@ -785,10 +791,10 @@ public class PersonAuthorityResource extends PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause); + handler.createDocumentFilter().appendWhereClause(ptClause); } - handler.setDocumentFilter(myFilter); +//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -925,9 +931,16 @@ public class PersonAuthorityResource extends } - /************************************************************************* + /** + * *********************************************************************** * Contact parts - this is a sub-resource of Person (or "item") - *************************************************************************/ + * ***********************************************************************. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param input the input + * @return the response + */ @POST @Path("{parentcsid}/items/{itemcsid}/contacts") public Response createContact( @@ -987,9 +1000,9 @@ public class PersonAuthorityResource extends ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method - myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + +//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); +//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method + handler.createDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + ContactJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'" + " AND " + @@ -997,7 +1010,7 @@ public class PersonAuthorityResource extends ContactJAXBSchema.IN_ITEM + "='" + itemcsid + "'" + " AND ecm:isProxy = 0"); - handler.setDocumentFilter(myFilter); +//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); contactObjectList = (ContactsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { diff --git a/services/query/pom.xml b/services/query/pom.xml index 3915a6168..aa6b63256 100644 --- a/services/query/pom.xml +++ b/services/query/pom.xml @@ -3,14 +3,14 @@ org.collectionspace.services.main org.collectionspace.services - 1.0 + 0.7-SNAPSHOT + 4.0.0 org.collectionspace.services - 1.0 org.collectionspace.services.query - pom services.query + pom service diff --git a/services/query/service/pom.xml b/services/query/service/pom.xml index 830b2e951..25236060e 100644 --- a/services/query/service/pom.xml +++ b/services/query/service/pom.xml @@ -1,25 +1,19 @@ - - + - org.collectionspace.services.query org.collectionspace.services - 1.0 + org.collectionspace.services.query + 0.7-SNAPSHOT 4.0.0 org.collectionspace.services org.collectionspace.services.query.service - jar - 1.0 services.query.service - - org.collectionspace.services - org.collectionspace.services.common - 1.0 - org.slf4j slf4j-api @@ -29,10 +23,9 @@ slf4j-log4j12 - junit - junit - 4.1 - test + org.collectionspace.services + org.collectionspace.services.common + 1.0 org.testng @@ -52,25 +45,26 @@ commons-logging 1.1 - + - + + + org.jboss.resteasy + jaxrs-api + org.jboss.resteasy resteasy-jaxrs @@ -89,37 +83,6 @@ org.jboss.resteasy resteasy-multipart-provider - - - - - org.nuxeo.ecm.core - nuxeo-core-api - ${nuxeo.version.1.5} - - - jboss-remoting - jboss - - - - - - org.restlet - org.restlet - 1.0.7 - - - com.noelios.restlet - com.noelios.restlet.ext.httpclient - 1.0.7 - - - com.noelios.restlet - com.noelios.restlet - 1.0.7 - - diff --git a/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java index 6b7ad0733..ad6b3d228 100644 --- a/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java +++ b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java @@ -36,8 +36,8 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; +//import javax.xml.bind.JAXBContext; +//import javax.xml.bind.Marshaller; import org.collectionspace.services.common.query.QueryManager; //import org.collectionspace.services.common.NuxeoClientType;