From: remillet Date: Fri, 7 Aug 2015 22:44:24 +0000 (-0700) Subject: CSPACE-6281: More changes for RESTEasy client update for v3.0.1Final X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=752e6ff1167c9523859e044a197018c7bcaaec49;p=tmp%2Fjakarta-migration.git CSPACE-6281: More changes for RESTEasy client update for v3.0.1Final --- diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java index 1c1c6af86..588294380 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java @@ -484,12 +484,12 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { for(RelationsCommonList.RelationListItem listItem : relationListItems){ String foundCsid = listItem.getCsid(); - ClientResponse multiPartResponse = null; + Response multiPartResponse = null; try { multiPartResponse = relationClient.read(foundCsid); int responseStatus = multiPartResponse.getStatus(); Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); - PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)multiPartResponse.getEntity()); resultRelation = (RelationsCommon) extractPart(input, relationClient.getCommonPartName(), RelationsCommon.class); @@ -613,12 +613,12 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { RelationsCommon resultRelation = null; for(RelationsCommonList.RelationListItem listItem : relationListItems){ String foundCsid = listItem.getCsid(); - ClientResponse multiPartResponse = null; + Response multiPartResponse = null; try { multiPartResponse = relationClient.read(foundCsid); int responseStatus = multiPartResponse.getStatus(); Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); - PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)multiPartResponse.getEntity()); resultRelation = (RelationsCommon) extractPart(input, relationClient.getCommonPartName(), RelationsCommon.class); 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 216f0cc38..b610d8c89 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 @@ -31,13 +31,10 @@ import javax.ws.rs.core.Response; import org.testng.Assert; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.util.HttpResponseCodes; - import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; @@ -96,7 +93,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { try { Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK); } finally { - response.releaseConnection(); + response.close(); } Date stopTime = new Date(); totalTime = totalTime + (stopTime.getTime() - startTime.getTime()); @@ -140,7 +137,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { try { coListItem = searchResults.getEntity(); } finally { - searchResults.releaseConnection(); + searchResults.close(); } long time = stopTime.getTime() - startTime.getTime(); @@ -253,8 +250,8 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { */ private void readCollectionObject(CollectionObjectClient collectionObjectClient, String resourceId) { - ClientResponse res = collectionObjectClient.read(resourceId); - res.releaseConnection(); + Response res = collectionObjectClient.read(resourceId); + res.close(); } /** @@ -283,18 +280,17 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { */ public void readCollectionObjects() { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - ClientResponse response; List coListItems = null; do { - response = collectionObjectClient.readList(new Long(MAX_RECORDS), + Response res = collectionObjectClient.readList(new Long(MAX_RECORDS), new Long(0)); try { AbstractCommonList commonListElement = - (AbstractCommonList) response.getEntity(AbstractCommonList.class); + (AbstractCommonList) res.readEntity(AbstractCommonList.class); coListItems = commonListElement.getListItem(); } finally { - response.releaseConnection(); + res.close(); } Date startTime = new Date(); @@ -350,18 +346,17 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { */ private void deleteCollectionObjects() { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - ClientResponse response; List coListItems = null; do { - response = collectionObjectClient.readList(new Long(MAX_RECORDS), + Response res = collectionObjectClient.readList(new Long(MAX_RECORDS), new Long(0)); try { AbstractCommonList commonListElement = - (AbstractCommonList) response.getEntity(AbstractCommonList.class); + (AbstractCommonList) res.readEntity(AbstractCommonList.class); coListItems = commonListElement.getListItem(); } finally { - response.releaseConnection(); + res.close(); } Date startTime = new Date(); 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 9850d1ab9..79340c43d 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 @@ -25,6 +25,7 @@ package org.collectionspace.services.account.client.test; import java.util.Collection; import java.util.Hashtable; import java.util.List; +import java.lang.UnsupportedOperationException; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.AccountsCommonList; @@ -44,13 +45,12 @@ import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; import javax.ws.rs.core.Response; -import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -85,6 +85,13 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl getEntityResponseType() { + return AccountRole.class; + } /** * Seed data. @@ -636,4 +643,10 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl getCommonListType() { return AccountRole.class; } + + @Override + protected long getSizeOfList(AccountRole list) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Method getSizeOfList() is not implemented because this service does not support lists."); + } } 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 28aa2aa13..2c39ac72b 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 @@ -23,23 +23,22 @@ package org.collectionspace.services.account.client.test; import java.util.List; + import javax.ws.rs.core.Response; -import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.client.ClientResponse; import org.collectionspace.services.client.AccountClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.AccountsCommonList; import org.collectionspace.services.account.AccountListItem; - import org.collectionspace.services.account.Status; +import org.collectionspace.services.authorization.AccountRole; import org.collectionspace.services.client.AccountFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.ServiceRequestType; - import org.testng.Assert; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,6 +68,13 @@ public class AccountServiceTest extends AbstractServiceTestImpl getEntityResponseType() { + return AccountsCommon.class; + } + /* * This method is called only by the parent class, AbstractServiceTestImpl */ @@ -92,8 +98,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl response) { + protected AccountsCommonList getCommonList(Response response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } @@ -1074,4 +1079,9 @@ public class AccountServiceTest extends AbstractServiceTestImpl * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } 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 1f947f34e..56fb58711 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 @@ -288,27 +288,32 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl 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); + Response res = client.read(knownResourceId); + PoxPayloadIn input = 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + input = new PoxPayloadIn((String)res.getEntity()); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input, client.getCommonPartName(), AcquisitionsCommon.class); Assert.assertNotNull(acquisitionObject); // Verify the number and contents of values in repeatable fields, // as created in the instance record used for testing. - List acqSources = - acquisitionObject.getAcquisitionSources().getAcquisitionSource(); + List acqSources = acquisitionObject.getAcquisitionSources().getAcquisitionSource(); Assert.assertTrue(acqSources.size() > 0); Assert.assertNotNull(acqSources.get(0)); @@ -335,7 +340,7 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -364,12 +369,12 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); try { // Check the status code of the response: does it match // the expected response(s)? assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); + AbstractCommonList list = res.readEntity(this.getCommonListType()); // Optionally output additional data about list members for debugging. if (logger.isTraceEnabled() == true){ @@ -377,7 +382,7 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); + Response res = client.read(knownResourceId); + PoxPayloadIn input = null; + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); + + input = new PoxPayloadIn((String)res.getEntity()); + } finally { + res.close(); } - Assert.assertEquals(res.getStatus(), testExpectedStatusCode); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input, client.getCommonPartName(), AcquisitionsCommon.class); @@ -426,24 +436,28 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl 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); + Response res = client.update(NON_EXISTENT_ID, multipart); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -851,13 +868,13 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(csid); + Response res = client.read(csid); AcquisitionsCommon acquisition = null; try { // Check the status code of the response: does it match // the expected response(s)? assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); if (logger.isDebugEnabled()) { logger.debug(testName + ": Reading Common part ..."); @@ -867,7 +884,7 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl getEntityResponseType() { + return PermissionRole.class; + } + /** * Seed data. */ @@ -149,8 +156,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl response) { + protected PermissionRole getCommonList(Response response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } @@ -201,7 +207,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl getEntityResponseType() { + return Permission.class; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String) */ @@ -428,4 +435,10 @@ public class PermissionServiceTest extends AbstractServiceTestImpl getEntityResponseType() { + return PermissionRole.class; + } + /** * Seed data. */ @@ -707,6 +714,12 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl getEntityResponseType() { + return Role.class; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -902,5 +909,10 @@ public class RoleServiceTest extends AbstractServiceTestImpl { } @Override - protected AbstractCommonList getCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java index 984a4be49..0f8f633ea 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java @@ -89,8 +89,8 @@ public class BlobServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } /** @@ -157,7 +157,7 @@ public class BlobServiceTest extends AbstractPoxServiceTestImpl readResponse = client.read(blobCsid); + Response readResponse = client.read(blobCsid); BlobsCommon blobsCommon = null; try { assertStatusCode(readResponse, testName); @@ -213,7 +213,7 @@ public class BlobServiceTest extends AbstractPoxServiceTestImpl readList() { + public Response readList() { CollectionSpaceProxy proxy = (CollectionSpaceProxy)getProxy(); return proxy.readList(); } @Override - public ClientResponse readIncludeDeleted(Boolean includeDeleted) { + public Response readIncludeDeleted(Boolean includeDeleted) { CollectionSpacePoxProxy proxy = getProxy(); return proxy.readIncludeDeleted(includeDeleted.toString()); } @@ -40,7 +40,7 @@ public abstract class AbstractPoxServiceClientImpl update(String csid, PoxPayloadOut xmlPayload) { + public Response update(String csid, PoxPayloadOut xmlPayload) { return getProxy().update(csid, xmlPayload.getBytes()); } 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 69e24e09f..8304dfc89 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 @@ -552,7 +552,7 @@ public abstract class AbstractServiceClientImpl readList(Long pageSize, + public Response readList(Long pageSize, Long pageNumber) { return getProxy().readList(pageSize, pageNumber); } @@ -565,7 +565,7 @@ public abstract class AbstractServiceClientImpl readList(String sortBy, Long pageSize, + public Response readList(String sortBy, Long pageSize, Long pageNumber) { return getProxy().readList(sortBy, pageSize, pageNumber); } 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 d88554a84..298751101 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 @@ -182,7 +182,7 @@ public interface CollectionSpaceClient update(String csid, REQUEST_TYPE payload); + public Response update(String csid, REQUEST_TYPE payload); /** * Read list. @@ -191,11 +191,11 @@ public interface CollectionSpaceClient readList( + public Response readList( Long pageSize, Long pageNumber); - public ClientResponse readList(); + public Response readList(); // Formally, ClientResponse /** * Read list. @@ -205,7 +205,7 @@ public interface CollectionSpaceClient readList( + public Response readList( String sortBy, Long pageSize, Long pageNumber); diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceCommonListPoxProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceCommonListPoxProxy.java index a1f470806..95f2edfd0 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceCommonListPoxProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceCommonListPoxProxy.java @@ -3,6 +3,7 @@ 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.Response; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -10,7 +11,7 @@ import org.jboss.resteasy.client.ClientResponse; public interface CollectionSpaceCommonListPoxProxy extends CollectionSpacePoxProxy { @GET - ClientResponse readList(); + Response readList(); @Override @GET diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java index 676e4ad23..0efbfb9c2 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxClient.java @@ -1,5 +1,7 @@ package org.collectionspace.services.client; +import javax.ws.rs.core.Response; + import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -14,12 +16,12 @@ public interface CollectionSpacePoxClient readIncludeDeleted(String csid, Boolean includeDeleted); + public Response readIncludeDeleted(String csid, Boolean includeDeleted); /* * GET list with workflow 'deleted' state */ - public ClientResponse readIncludeDeleted(Boolean includeDeleted); + public Response readIncludeDeleted(Boolean includeDeleted); public ClientResponse keywordSearchIncludeDeleted(String keywords, Boolean includeDeleted); diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java index 0b2b6e800..3f17a9f20 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpacePoxProxy.java @@ -35,12 +35,12 @@ public interface CollectionSpacePoxProxy extends // (U)pdate @PUT @Path("/{csid}") - ClientResponse update(@PathParam("csid") String csid, byte[] payload); + Response update(@PathParam("csid") String csid, byte[] payload); // (L)ist non-deleted items @GET @Produces({ "application/xml" }) - ClientResponse readIncludeDeleted( + Response readIncludeDeleted( @QueryParam(WorkflowClient.WORKFLOWSTATE_QUERY) String workflowState); /** diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java index 40b6201f7..0532b507a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java @@ -76,7 +76,7 @@ public interface CollectionSpaceProxy { @GET @Produces({"application/xml"}) - ClientResponse readList(); + Response readList(); /** * Read list. @@ -87,7 +87,7 @@ public interface CollectionSpaceProxy { */ @GET @Produces({"application/xml"}) - ClientResponse readList( + Response readList( @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) Long pageSize, @QueryParam(IClientQueryParams.START_PAGE_PARAM) Long pageNumber); @@ -101,7 +101,7 @@ public interface CollectionSpaceProxy { */ @GET @Produces({"application/xml"}) - ClientResponse readList( + Response readList( @QueryParam(IClientQueryParams.ORDER_BY_PARAM) String sortBy, @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) Long pageSize, @QueryParam(IClientQueryParams.START_PAGE_PARAM) Long pageNumber); diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java index 08578f359..7bd15d44c 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractAuthorityServiceTest.java @@ -134,48 +134,58 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - 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 + " read authority:" + knownResourceId + "/Item:" - + knownItemResourceId + " status = " + statusCode); - } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - AUTHORITY_ITEM_TYPE vitem = extractItemCommonPartValue(res); - Assert.assertNotNull(vitem); - // Try to Update with new parent vocab (use self, for test). - Assert.assertEquals(client.getInAuthority(vitem), knownResourceId, - "VocabularyItem inAuthority does not match knownResourceId."); - client.setInAuthority(vitem, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); + AUTHORITY_ITEM_TYPE vitem = 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 + " read authority:" + knownResourceId + "/Item:" + + knownItemResourceId + " status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + vitem = extractItemCommonPartValue(res); + Assert.assertNotNull(vitem); + // Try to Update with new parent vocab (use self, for test). + Assert.assertEquals(client.getInAuthority(vitem), knownResourceId, + "VocabularyItem inAuthority does not match knownResourceId."); + client.setInAuthority(vitem, knownItemResourceId); + } finally { + res.close(); + } + // Submit the updated resource to the service and store the response. PoxPayloadOut output = this.createItemRequestTypeInstance(vitem); 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(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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Retrieve the updated resource and verify that the parent did not change + res = client.readItem(knownResourceId, knownItemResourceId); + AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res); + Assert.assertNotNull(updatedVocabularyItem); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(client.getInAuthority(updatedVocabularyItem), + knownResourceId, + "VocabularyItem allowed update to the parent (inAuthority)."); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Retrieve the updated resource and verify that the parent did not change - res = client.readItem(knownResourceId, knownItemResourceId); - AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res); - Assert.assertNotNull(updatedVocabularyItem); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(client.getInAuthority(updatedVocabularyItem), - knownResourceId, - "VocabularyItem allowed update to the parent (inAuthority)."); } @Test(dataProvider = "testName", @@ -220,19 +230,23 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); ClientResponse res = client.readByName(getKnowResourceIdentifier()); - 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res); + Assert.assertNotNull(commonPart); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res); - Assert.assertNotNull(commonPart); } /** @@ -242,10 +256,11 @@ public abstract class AbstractAuthorityServiceTest res) throws Exception { + public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception { AUTHORITY_ITEM_TYPE result = null; - AuthorityClientImpl client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClientImpl client = (AuthorityClientImpl) + this.getClientInstance(); PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName()); if (payloadInputPart != null) { result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody(); @@ -263,18 +278,23 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - 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); + AuthorityClientImpl client = (AuthorityClientImpl) + this.getClientInstance(); + Response res = client.readItem(knownResourceId, NON_EXISTENT_ID); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } @Test(dataProvider = "testName", @@ -285,22 +305,26 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - 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); + Response res = client.readItem(knownResourceId, knownItemResourceId); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res); + Assert.assertNotNull(itemCommonPart); + Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId); + verifyReadItemInstance(itemCommonPart); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res); - Assert.assertNotNull(itemCommonPart); - Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId); - verifyReadItemInstance(itemCommonPart); } protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception; @@ -312,7 +336,8 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); + AuthorityClientImpl client = (AuthorityClientImpl) + this.getClientInstance(); Response res = client.deleteItem(knownResourceId, knownItemResourceId); int statusCode; try { @@ -440,8 +465,7 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - ClientResponse res = - client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); try { if (logger.isDebugEnabled()) { logger.debug(testName + ": read status = " + res.getStatus()); @@ -463,7 +487,7 @@ public abstract class AbstractAuthorityServiceTest getEntityResponseType() { + return String.class; + } @Override public CPT extractCommonPartValue(PoxPayloadOut payloadOut) throws Exception { @@ -53,8 +65,8 @@ public abstract class AbstractPoxServiceTestImpl getEntityResponseType(); + + @SuppressWarnings("unchecked") + @Override @Test(dataProvider = "testName", dependsOnMethods = {"create"}) public void read(String testName) throws Exception { // Perform setup. @@ -197,9 +201,6 @@ public abstract class AbstractServiceTestImpl res = client.readList(); - CLT list = res.getEntity(); + Response res = client.readList(); + CLT list = res.readEntity(this.getCommonListType()); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -569,7 +570,7 @@ public abstract class AbstractServiceTestImpl res = client.readIncludeDeleted(csid, Boolean.FALSE); + Response res = client.readIncludeDeleted(csid, Boolean.FALSE); result = res.getStatus(); if (result == STATUS_NOT_FOUND) { logger.info("Workflow transition to 'deleted' is complete"); @@ -609,8 +610,9 @@ public abstract class AbstractServiceTestImpl res = client.readIncludeDeleted(csid, Boolean.FALSE); + Response res = client.readIncludeDeleted(csid, Boolean.FALSE); result = res.getStatus(); + res.close(); if (result == STATUS_OK) { logger.info("Workflow transition to 'project' is complete"); break; @@ -755,18 +757,21 @@ public abstract class AbstractServiceTestImpl 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); + Response res = client.update(NON_EXISTENT_ID, multipart); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -812,8 +817,7 @@ public abstract class AbstractServiceTestImpl response = - client.readList(sortBy, pageSize, pageNumber); + Response response = client.readList(sortBy, pageSize, pageNumber); CLT result = null; try { int statusCode = response.getStatus(); @@ -827,7 +831,7 @@ public abstract class AbstractServiceTestImpl res = client.readIncludeDeleted(includeDeleted); + Response res = client.readIncludeDeleted(includeDeleted); try { // // Check the status code of the response: does it match // the expected response(s)? // assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); + CLT list = res.readEntity(getCommonListType()); // // Now check that list size is correct // - result = list.getTotalItems(); + result = getSizeOfList(list); //list.getTotalItems(); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } 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 ff776163f..16a2564e0 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 @@ -190,9 +190,8 @@ public abstract class BaseServiceTest { return (Class)AbstractCommonList.class; } - protected CLT getCommonList( - ClientResponse response) { - return response.getEntity(getCommonListType()); + protected CLT getCommonList(Response response) { + return response.readEntity(getCommonListType()); } /** 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 609a27914..630a02faf 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 @@ -534,10 +534,10 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl updateRetrieve(String testName, String id) { + private Response updateRetrieve(String testName, String id) { setupRead(); CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.read(knownResourceId); + Response res = client.read(knownResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match // the expected response(s)? @@ -561,14 +561,15 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl updateSend(String testName, String id, + private Response updateSend(String testName, String id, CollectionobjectsCommon collectionObjectCommon) { setupUpdate(); PoxPayloadOut output = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(collectionObjectCommon, MediaType.APPLICATION_XML_TYPE); CollectionObjectClient client = new CollectionObjectClient(); commonPart.setLabel(client.getCommonPartName()); - ClientResponse res = client.update(knownResourceId, output); + + Response res = client.update(knownResourceId, output); int statusCode = res.getStatus(); // Check the status code of the response: does it match // the expected response(s)? @@ -578,7 +579,8 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl 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); + Response res = client.update(NON_EXISTENT_ID, multipart); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } /** @@ -751,7 +756,7 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl res = updateRetrieve(testName, knownResourceId); + Response res = updateRetrieve(testName, knownResourceId); CollectionobjectsCommon collectionObjectCommon = null; try { // Extract its common part. @@ -1150,7 +1155,7 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl res = client.read(csid); + Response res = client.read(csid); CollectionobjectsCommon collectionObject = null; try { int statusCode = res.getStatus(); diff --git a/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckAuthRefsTest.java b/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckAuthRefsTest.java index 566e78f4f..5d8df6075 100644 --- a/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckAuthRefsTest.java +++ b/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckAuthRefsTest.java @@ -86,8 +86,7 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } diff --git a/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckServiceTest.java b/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckServiceTest.java index 64f7ed344..dff89419e 100644 --- a/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckServiceTest.java +++ b/services/conditioncheck/client/src/test/java/org/collectionspace/services/client/test/ConditioncheckServiceTest.java @@ -78,9 +78,8 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -263,14 +262,14 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -323,7 +322,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -337,7 +336,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); assertStatusCode(res, testName); try { int statusCode = res.getStatus(); @@ -375,10 +374,10 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -461,10 +460,10 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.update(NON_EXISTENT_ID, multipart); + Response res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -523,7 +522,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // @Override @@ -277,16 +276,16 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); ContactsCommon contact = (ContactsCommon) extractPart(input, client.getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -304,10 +303,10 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); try { assertStatusCode(res, testName); - AbstractCommonList list = res.getEntity(); + AbstractCommonList list = res.readEntity(getCommonListType()); // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; @@ -316,7 +315,7 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); ContactsCommon contact = null; try { assertStatusCode(res, testName); @@ -345,13 +344,13 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl res = + Response 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- 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 92c041295..c793cd510 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 @@ -26,6 +26,8 @@ */ package org.collectionspace.services.client; +import javax.ws.rs.core.Response; + import org.collectionspace.services.dimension.DimensionsCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -60,7 +62,7 @@ public class DimensionClient extends AbstractPoxServiceClientImpl readList() { + public Response readList() { DimensionProxy proxy = (DimensionProxy)getProxy(); return proxy.readList(); } diff --git a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java index b3a848674..64ac3dfea 100644 --- a/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java +++ b/services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionProxy.java @@ -5,6 +5,7 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.dimension.DimensionsCommonList; @@ -19,7 +20,7 @@ import org.jboss.resteasy.client.ClientResponse; public interface DimensionProxy extends CollectionSpacePoxProxy { @GET @Produces({"application/xml"}) - ClientResponse readList(); + Response readList(); @Override @GET diff --git a/services/exhibition/client/src/test/java/org/collectionspace/services/client/test/ExhibitionServiceTest.java b/services/exhibition/client/src/test/java/org/collectionspace/services/client/test/ExhibitionServiceTest.java index a7451657a..9a08e4c14 100644 --- a/services/exhibition/client/src/test/java/org/collectionspace/services/client/test/ExhibitionServiceTest.java +++ b/services/exhibition/client/src/test/java/org/collectionspace/services/client/test/ExhibitionServiceTest.java @@ -68,9 +68,8 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -253,14 +252,14 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -301,7 +300,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -315,7 +314,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); assertStatusCode(res, testName); try { int statusCode = res.getStatus(); @@ -353,10 +352,10 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -439,10 +438,10 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.update(NON_EXISTENT_ID, multipart); + Response res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -501,7 +500,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- 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 83f154f7e..6c60884fb 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 @@ -102,8 +102,7 @@ public class IntakeAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } 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 08f7ac1ba..237e090f0 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 @@ -23,10 +23,11 @@ package org.collectionspace.services.client.test; import java.util.List; + import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.dom4j.Element; - import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.IntakeClient; import org.collectionspace.services.client.PayloadInputPart; @@ -40,11 +41,9 @@ import org.collectionspace.services.intake.CurrentLocationGroup; import org.collectionspace.services.intake.CurrentLocationGroupList; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.jaxb.AbstractCommonList; - import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -264,13 +263,19 @@ public class IntakeServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": read status = " + res.getStatus()); + PoxPayloadIn input = null; + Response res = client.read(knownResourceId); + try { + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); + + input = new PoxPayloadIn((String)res.getEntity()); + } finally { + res.close(); } - Assert.assertEquals(res.getStatus(), testExpectedStatusCode); - - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(COLLECTIONSPACE_CORE_SCHEMA); Element coreAsElement = null; if (payloadInputPart != null) { @@ -307,21 +312,25 @@ public class IntakeServiceTest extends AbstractPoxServiceTestImpl res = client.update(NON_EXISTENT_ID, multipart); + Response res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -508,7 +507,7 @@ public class LoaninServiceTest extends AbstractPoxServiceTestImpl { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } 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 95a873b9d..b7397abe6 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 @@ -74,9 +74,8 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -277,12 +276,12 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); LoansoutCommon loanoutCommon = null; try { assertStatusCode(res, testName); // Get the common part of the response and verify that it is not null. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); if (payloadInputPart != null) { loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); @@ -290,7 +289,7 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl 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); + Response res = client.read(NON_EXISTENT_ID); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- @@ -358,14 +361,14 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); AbstractCommonList list = null; try { assertStatusCode(res, testName); - list = res.getEntity(); + list = res.readEntity(getCommonListType()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // Optionally output additional data about list members for debugging. @@ -394,12 +397,12 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); LoansoutCommon loanoutCommon = null; try { assertStatusCode(res, testName); // Extract the common part from the response. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); if (payloadInputPart != null) { loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); @@ -407,7 +410,7 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl 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); + Response res = client.update(NON_EXISTENT_ID, multipart); + 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(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); } // --------------------------------------------------------------- diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index cf8b400c0..896f9bcda 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.ws.rs.core.Response; + import org.collectionspace.services.LocationJAXBSchema; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; @@ -42,12 +44,9 @@ import org.collectionspace.services.location.LocTermGroup; import org.collectionspace.services.location.LocTermGroupList; import org.collectionspace.services.location.LocationauthoritiesCommon; import org.collectionspace.services.location.LocationsCommon; - 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; @@ -169,17 +168,17 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); LocationsCommon location = null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); location = (LocationsCommon) extractPart(input, client.getItemCommonPartName(), LocationsCommon.class); Assert.assertNotNull(location); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -205,7 +204,7 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest update(String csid, PoxPayloadOut xmlPayload, String URI) { + public Response update(String csid, PoxPayloadOut xmlPayload, String URI) { return getProxy().update(csid, xmlPayload.getBytes()); } diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java index 9ac5e6dac..8e4596d9f 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaAuthRefsTest.java @@ -84,7 +84,7 @@ public class MediaAuthRefsTest extends BaseServiceTest { } @Override - protected AbstractCommonList getCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java index 347757dc1..52ec0a60c 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java @@ -96,8 +96,8 @@ public class MediaServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } /** diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java index c1d896a9f..ebcb49a73 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java @@ -92,8 +92,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java index 00569b780..2c6e27093 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java @@ -90,8 +90,7 @@ public class MovementSortByTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -632,19 +631,19 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = client.read(csid); + Response res = client.read(csid); MovementsCommon movementCommon = null; try { assertStatusCode(res, testName); // Extract and return the common part of the record. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); if (payloadInputPart != null) { movementCommon = (MovementsCommon) payloadInputPart.getBody(); } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -685,7 +684,7 @@ public class MovementSortByTest extends BaseServiceTest { list = res.getEntity(); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java index ed5c38e16..2445fb38b 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitAuthRefsTest.java @@ -89,7 +89,7 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest } @Override - protected AbstractCommonList getCommonList(ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java index 66728a064..a42697e23 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java @@ -70,8 +70,8 @@ public class ObjectExitServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- 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 379a133ef..8c755b678 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 @@ -93,7 +93,7 @@ public class OrgAuthorityClientUtils { public static String getOrgRefName(String inAuthority, String csid, OrgAuthorityClient client){ if(client==null) client = new OrgAuthorityClient(); - ClientResponse res = client.readItem(inAuthority, csid); + Response res = client.readItem(inAuthority, csid); try { int statusCode = res.getStatus(); if(!READ_REQ.isValidStatusCode(statusCode) @@ -102,7 +102,7 @@ public class OrgAuthorityClientUtils { } //FIXME: remove the following try catch once Aron fixes signatures try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); OrganizationsCommon org = (OrganizationsCommon) CollectionSpaceClientUtils.extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); @@ -114,7 +114,7 @@ public class OrgAuthorityClientUtils { throw new RuntimeException(e); } } finally { - res.releaseConnection(); + res.close(); } } 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 36d395fc3..f4c6431ec 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 @@ -119,8 +119,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } @@ -299,11 +298,11 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest res = orgAuthClient.readItem(knownResourceId, knownItemResourceId); + Response res = orgAuthClient.readItem(knownResourceId, knownItemResourceId); OrganizationsCommon organization = null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); organization = (OrganizationsCommon) extractPart(input, orgAuthClient.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(organization); @@ -312,9 +311,10 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest res = null; + Response res = null; if (CSID != null) { res = client.read(CSID); } else if (shortId != null) { @@ -315,7 +315,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest res = null; + Response res = null; if (authCSID != null) { if (itemCSID != null) { res = client.readItem(authCSID, itemCSID); @@ -414,7 +414,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); OrganizationsCommon organization = null; try { assertStatusCode(res, testName); // Check whether organization has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); organization = (OrganizationsCommon) extractPart(input, client.getItemCommonPartName(), OrganizationsCommon.class); Assert.assertNotNull(organization); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -497,7 +497,7 @@ public class OrgAuthorityServiceTest extends AbstractAuthorityServiceTest res = - client.deleteContact(parentResourceId, itemResourceId, contactResourceId); - res.releaseConnection(); + client.deleteContact(parentResourceId, itemResourceId, contactResourceId).close(); } // Clean up item resources. for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java index 85dae979c..e5a5f0c42 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java @@ -156,9 +156,8 @@ public class PersonAuthoritySearchTest extends BaseServiceTest response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } private String getPartialTermCommon() { diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java index c3927d4a8..e4e666356 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java @@ -115,9 +115,8 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } @BeforeClass 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 8cc0a6057..7ca29cfe1 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 @@ -1074,8 +1074,8 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = - client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); + ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, + knownContactResourceId); try { assertStatusCode(res, testName); if (logger.isDebugEnabled()) { diff --git a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java index 7341c4b3c..b2ac7d84d 100644 --- a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java +++ b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java @@ -113,7 +113,7 @@ public class PlaceAuthorityClientUtils { createPlaceInstance( placeAuthorityRefName, placeMap, terms, client.getItemCommonPartName() ); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -130,7 +130,7 @@ public class PlaceAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -161,7 +161,7 @@ public class PlaceAuthorityClientUtils { PoxPayloadOut multipart = createPlaceInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -176,7 +176,7 @@ public class PlaceAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -227,7 +227,7 @@ public class PlaceAuthorityClientUtils { return refName; } - public static String extractId(ClientResponse res) { + public static String extractId(Response res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); if(logger.isDebugEnabled()){ diff --git a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java index b18f51295..f5ee57955 100644 --- a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java +++ b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java @@ -26,6 +26,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + +import javax.ws.rs.core.Response; + import org.collectionspace.services.PlaceJAXBSchema; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; @@ -170,17 +173,17 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); PlacesCommon place= null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); place = (PlacesCommon) extractPart(input, client.getItemCommonPartName(), PlacesCommon.class); Assert.assertNotNull(place); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -206,7 +209,7 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -189,14 +188,14 @@ public class PublicItemServiceTest extends // Submit the request to the service and store the response. PublicItemClient client = new PublicItemClient(); - ClientResponse res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -229,7 +228,7 @@ public class PublicItemServiceTest extends // Submit the request to the service and store the response. PublicItemClient client = new PublicItemClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -243,7 +242,7 @@ public class PublicItemServiceTest extends Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -272,7 +271,7 @@ public class PublicItemServiceTest extends // Submit the request to the service and store the response. AbstractCommonList list = null; PublicItemClient client = new PublicItemClient(); - ClientResponse res = client.readList(); + Response res = client.readList(); assertStatusCode(res, testName); try { int statusCode = res.getStatus(); @@ -286,10 +285,10 @@ public class PublicItemServiceTest extends invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, testExpectedStatusCode); - list = res.getEntity(); + list = res.readEntity(getCommonListType()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -328,17 +327,17 @@ public class PublicItemServiceTest extends // Retrieve the contents of a resource to update. PublicItemClient client = new PublicItemClient(); - ClientResponse res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -379,10 +378,10 @@ public class PublicItemServiceTest extends Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, testExpectedStatusCode); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -427,7 +426,7 @@ public class PublicItemServiceTest extends // The only relevant ID may be the one used in update(), below. PublicItemClient client = new PublicItemClient(); PoxPayloadOut multipart = createPublicItemInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); + Response res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -441,7 +440,7 @@ public class PublicItemServiceTest extends Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 18a92de8d..99283dd98 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -139,6 +139,8 @@ public class RelationServiceTest extends AbstractPoxServiceTestImpl personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -147,13 +149,19 @@ public class RelationServiceTest extends AbstractPoxServiceTestImpl res = personAuthClient.createItem(personAuthCSID, multipart); - int statusCode = res.getStatus(); - - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, STATUS_CREATED); - return extractId(res); + Response res = personAuthClient.createItem(personAuthCSID, multipart); + try { + int statusCode = res.getStatus(); + + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, STATUS_CREATED); + result = extractId(res); + } finally { + res.close(); + } + + return result; } @Test(dataProvider="testName", diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java index 70ff0320d..2c74259bb 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java @@ -91,8 +91,7 @@ public class AuthenticationServiceTest extends BaseServiceTest response) { + protected AbstractCommonList getCommonList(Response response) { throw new UnsupportedOperationException(); //Since this test does not support lists, this method is not needed. } @@ -112,22 +111,25 @@ public class AuthenticationServiceTest extends BaseServiceTest res = accountClient.create(account); - int statusCode = res.getStatus(); - - if (logger.isDebugEnabled()) { - logger.debug(testName + ": barney status = " + statusCode); - } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Store the ID returned from this create operation - // for additional tests below. - barneyAccountId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": barneyAccountId=" + barneyAccountId); + try { + int statusCode = res.getStatus(); + + if (logger.isDebugEnabled()) { + logger.debug(testName + ": barney status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Store the ID returned from this create operation + // for additional tests below. + barneyAccountId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": barneyAccountId=" + barneyAccountId); + } + } finally { + res.close(); } - res.releaseConnection(); } diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java index 6ec64ffc6..c9f079ec1 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java @@ -411,16 +411,16 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.read(knownResourceId); + Response res = client.read(knownResourceId); try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); DimensionsCommon dimension = (DimensionsCommon) extractPart(input, client.getCommonPartName(), DimensionsCommon.class); Assert.assertNotNull(dimension); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -435,12 +435,12 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.read(knownResourceId); + Response res = client.read(knownResourceId); try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -467,12 +467,12 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.update(knownResourceId, output); + Response res = client.update(knownResourceId, output); try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // @@ -489,7 +489,7 @@ public class AuthorizationServiceTest extends BaseServiceTest { * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getCommonList( - ClientResponse response) { + protected AbstractCommonList getCommonList(Response response) { //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 throw new UnsupportedOperationException(); } @@ -369,15 +368,15 @@ public class MultiTenancyTest extends BaseServiceTest { // Submit the request to the service and store the response. DimensionClient client = new DimensionClient(); client.setAuth(true, userName, true, userName, true); - ClientResponse res = client.read(id); + Response res = client.read(id); try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); result = (DimensionsCommon) extractPart(input, client.getCommonPartName(), DimensionsCommon.class); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -412,12 +411,12 @@ public class MultiTenancyTest extends BaseServiceTest { // PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension); - ClientResponse res = client.update(TENANT_RESOURCE_2, output); + Response res = client.update(TENANT_RESOURCE_2, output); try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -578,7 +577,7 @@ public class MultiTenancyTest extends BaseServiceTest { result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } diff --git a/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java index 40f0f36a0..5ec63fdea 100644 --- a/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java +++ b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java @@ -72,12 +72,12 @@ public class ServiceGroupServiceTest extends BaseServiceTest } @Override - protected AbstractCommonList getCommonList(ClientResponse response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client, - ClientResponse res) throws Exception { + Response res) throws Exception { ServicegroupsCommon result = null; PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName()); @@ -90,12 +90,12 @@ public class ServiceGroupServiceTest extends BaseServiceTest return result; } - protected PayloadInputPart extractPart(ClientResponse res, String partLabel) + protected PayloadInputPart extractPart(Response res, String partLabel) throws Exception { if (getLogger().isDebugEnabled()) { getLogger().debug("Reading part " + partLabel + " ..."); } - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PayloadInputPart payloadInputPart = input.getPart(partLabel); Assert.assertNotNull(payloadInputPart, "Part " + partLabel + " was unexpectedly null."); @@ -110,7 +110,7 @@ public class ServiceGroupServiceTest extends BaseServiceTest // Submit the request to the service and store the response. CollectionSpaceClient client = this.getClientInstance(); - ClientResponse res = client.read(readGroupName); + Response res = client.read(readGroupName); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -140,9 +140,15 @@ public class ServiceGroupServiceTest extends BaseServiceTest // Submit the request to the service and store the response. CollectionSpaceClient client = this.getClientInstance(); - ClientResponse res = client.readList(); - AbstractCommonList list = res.getEntity(); - int statusCode = res.getStatus(); + Response res = client.readList(); + AbstractCommonList list = res.readEntity(getCommonListType()); + int statusCode; + try { + statusCode = res.getStatus(); + } finally { + res.close(); + } + // Check the status code of the response: does it match // the expected response(s)? @@ -159,6 +165,4 @@ public class ServiceGroupServiceTest extends BaseServiceTest AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName); } } - - } diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java index 886e79981..c0f6c63c4 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClientUtils.java @@ -167,7 +167,7 @@ public class TaxonomyAuthorityClientUtils { createTaxonInstance(TaxonomyauthorityRefName, taxonMap, terms, taxonAuthorGroupList, taxonCitationList, commonNameGroupList, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -184,7 +184,7 @@ public class TaxonomyAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -215,7 +215,7 @@ public class TaxonomyAuthorityClientUtils { PoxPayloadOut multipart = createTaxonInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -230,7 +230,7 @@ public class TaxonomyAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -283,7 +283,7 @@ public class TaxonomyAuthorityClientUtils { return refName; } - public static String extractId(ClientResponse res) { + public static String extractId(Response res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); if (logger.isDebugEnabled()) { diff --git a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java index d04c3c3a8..6b25f3260 100644 --- a/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java +++ b/services/taxonomy/client/src/test/java/org/collectionspace/services/client/test/TaxonomyAuthorityServiceTest.java @@ -198,12 +198,12 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); TaxonCommon taxon = null; try { assertStatusCode(res, testName); // Check whether Taxonomy has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); taxon = (TaxonCommon) extractPart(input, client.getItemCommonPartName(), TaxonCommon.class); Assert.assertNotNull(taxon); diff --git a/services/valuationcontrol/client/src/test/java/org/collectionspace/services/client/test/ValuationcontrolServiceTest.java b/services/valuationcontrol/client/src/test/java/org/collectionspace/services/client/test/ValuationcontrolServiceTest.java index cebe70b4f..7f574aaf2 100644 --- a/services/valuationcontrol/client/src/test/java/org/collectionspace/services/client/test/ValuationcontrolServiceTest.java +++ b/services/valuationcontrol/client/src/test/java/org/collectionspace/services/client/test/ValuationcontrolServiceTest.java @@ -68,9 +68,8 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl response) { - return response.getEntity(AbstractCommonList.class); + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -253,14 +252,14 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -301,7 +300,7 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -315,7 +314,7 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.readList(); + Response res = client.readList(); assertStatusCode(res, testName); try { int statusCode = res.getStatus(); @@ -353,10 +352,10 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.read(knownResourceId); + Response res = client.read(knownResourceId); PoxPayloadIn input = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); if (logger.isDebugEnabled()) { logger.debug("got object to update with ID: " + knownResourceId); } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -439,10 +438,10 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.update(NON_EXISTENT_ID, multipart); + Response res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -501,7 +500,7 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl itemMap, VocabularyClient client ) { + String result = null; + // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested @@ -78,21 +80,26 @@ public class VocabularyClientUtils { } PoxPayloadOut multipart = createVocabularyItemInstance(null, //vocabularyRefName, itemMap, client.getItemCommonPartName()); - ClientResponse res = client.createItem(vcsid, multipart); - - int statusCode = res.getStatus(); - - if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \"" + itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) - + "\" in personAuthority: \"" + vcsid //vocabularyRefName - + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - } - if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) - + "\" in vocabularyAuthority: \"" + vcsid /*vocabularyRefName*/ + "\", Status:" + statusCode); + Response res = client.createItem(vcsid, multipart); + + try { + int statusCode = res.getStatus(); + + if (!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \"" + itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) + + "\" in personAuthority: \"" + vcsid //vocabularyRefName + + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if (statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) + + "\" in vocabularyAuthority: \"" + vcsid /*vocabularyRefName*/ + "\", Status:" + statusCode); + } + result = extractId(res); + } finally { + res.close(); } - return extractId(res); + return result; } /** @@ -112,7 +119,7 @@ public class VocabularyClientUtils { requestType.validStatusCodesAsString(); } - public static String extractId(ClientResponse res) { + public static String extractId(Response res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); if(logger.isDebugEnabled()){ diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index 6efc71262..8021b52c4 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -115,7 +115,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest res = client.createItem(knownResourceId, multipart); + Response res = client.createItem(knownResourceId, multipart); try { int statusCode = res.getStatus(); @@ -130,7 +130,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); VocabularyitemsCommon vitem = null; try { assertStatusCode(res, testName); // Check whether Person has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); vitem = (VocabularyitemsCommon) extractPart(input, client.getItemCommonPartName(), VocabularyitemsCommon.class); Assert.assertNotNull(vitem); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // @@ -171,7 +171,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -130,7 +130,7 @@ public class WorkAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -161,7 +161,7 @@ public class WorkAuthorityClientUtils { PoxPayloadOut multipart = createWorkInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -176,7 +176,7 @@ public class WorkAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -227,7 +227,7 @@ public class WorkAuthorityClientUtils { return refName; } - public static String extractId(ClientResponse res) { + public static String extractId(Response res) { MultivaluedMap mvm = res.getMetadata(); String uri = (String) ((ArrayList) mvm.get("Location")).get(0); if(logger.isDebugEnabled()){ diff --git a/services/work/client/src/test/java/org/collectionspace/services/client/test/WorkAuthorityServiceTest.java b/services/work/client/src/test/java/org/collectionspace/services/client/test/WorkAuthorityServiceTest.java index 9e071b77a..096fc7265 100644 --- a/services/work/client/src/test/java/org/collectionspace/services/client/test/WorkAuthorityServiceTest.java +++ b/services/work/client/src/test/java/org/collectionspace/services/client/test/WorkAuthorityServiceTest.java @@ -26,6 +26,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + +import javax.ws.rs.core.Response; + import org.collectionspace.services.WorkJAXBSchema; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; @@ -168,52 +171,54 @@ public class WorkAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); - WorksCommon work = null; - try { - assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - work = (WorksCommon) extractPart(input, - client.getItemCommonPartName(), WorksCommon.class); - Assert.assertNotNull(work); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - - // - // Make an invalid UPDATE request, without a display name - // - WorkTermGroupList termList = work.getWorkTermGroupList(); - Assert.assertNotNull(termList); - List terms = termList.getWorkTermGroup(); - Assert.assertNotNull(terms); - Assert.assertTrue(terms.size() > 0); - terms.get(0).setTermDisplayName(null); - terms.get(0).setTermName(null); - - setupUpdateWithInvalidBody(); // we expect a failure - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(WorkAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), work); - setupUpdateWithInvalidBody(); // we expected a failure here. - res = client.updateItem(knownResourceId, knownItemResourceId, output); - try { - assertStatusCode(res, testName); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - } + public void verifyIllegalItemDisplayName(String testName) throws Exception { + // Perform setup for read. + setupRead(); + + // Submit the request to the service and store the response. + WorkAuthorityClient client = new WorkAuthorityClient(); + Response res = client.readItem(knownResourceId, knownItemResourceId); + WorksCommon work = null; + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); + work = (WorksCommon) extractPart(input, + client.getItemCommonPartName(), WorksCommon.class); + Assert.assertNotNull(work); + } finally { + if (res != null) { + res.close(); + } + } + + // + // Make an invalid UPDATE request, without a display name + // + WorkTermGroupList termList = work.getWorkTermGroupList(); + Assert.assertNotNull(termList); + List terms = termList.getWorkTermGroup(); + Assert.assertNotNull(terms); + Assert.assertTrue(terms.size() > 0); + terms.get(0).setTermDisplayName(null); + terms.get(0).setTermName(null); + + setupUpdateWithInvalidBody(); // we expect a failure + + // Submit the updated resource to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut( + WorkAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart( + client.getItemCommonPartName(), work); + setupUpdateWithInvalidBody(); // we expected a failure here. + res = client.updateItem(knownResourceId, knownItemResourceId, output); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + } /** * Read item list. @@ -264,7 +269,7 @@ public class WorkAuthorityServiceTest extends AbstractAuthorityServiceTest