From 64bd1ca84113cb323e8dcf6bdbcfef1932127279 Mon Sep 17 00:00:00 2001 From: remillet Date: Tue, 4 Aug 2015 17:10:25 -0700 Subject: [PATCH] CSPACE-6281: Replacing refs of now deprecated ClientResponse with javax.ws.rs.core.Response. --- .../PerformanceTests/test/I1591Multiple.java | 50 ++- .../PerformanceTests/test/I1591OneInst.java | 3 +- .../test/I1591OneInstOneClose.java | 3 +- .../test/PerformanceTest.java | 3 +- .../client/test/AccountRoleServiceTest.java | 18 +- .../client/test/AcquisitionAuthRefsTest.java | 51 +-- .../client/test/AcquisitionServiceTest.java | 18 +- .../test/PermissionRoleServiceTest.java | 16 +- .../test/RolePermissionServiceTest.java | 16 +- .../client/test/RoleServiceTest.java | 342 ++++++++++-------- .../services/batch/UriInfoImpl.java | 315 ++++++++++++++++ .../client/test/BlobAuthRefsTest.java | 20 +- .../client/CitationAuthorityClientUtils.java | 6 +- .../test/CitationAuthorityServiceTest.java | 4 +- .../client/AbstractPoxServiceClientImpl.java | 2 +- .../client/AbstractServiceClientImpl.java | 4 +- .../services/client/AuthorityClient.java | 6 +- .../services/client/AuthorityClientImpl.java | 6 +- .../services/client/AuthorityProxy.java | 2 +- .../client/CollectionSpaceClient.java | 4 +- .../client/CollectionSpacePoxProxy.java | 2 +- .../services/client/CollectionSpaceProxy.java | 2 +- .../test/AbstractAuthorityServiceTest.java | 18 +- .../test/AbstractPoxServiceTestImpl.java | 9 +- .../client/test/AbstractServiceTestImpl.java | 118 +++--- .../services/client/test/BaseServiceTest.java | 2 +- .../test/CollectionObjectAuthRefsTest.java | 74 ++-- .../test/CollectionObjectSearchTest.java | 181 ++++----- .../test/CollectionObjectServiceTest.java | 41 ++- .../client/ConceptAuthorityClientUtils.java | 6 +- .../test/ConceptAuthorityServiceTest.java | 4 +- .../test/ConditioncheckAuthRefsTest.java | 43 ++- .../test/ConditioncheckServiceTest.java | 8 +- .../client/test/ContactServiceTest.java | 48 ++- .../client/test/ExhibitionServiceTest.java | 8 +- .../client/test/IntakeAuthRefsTest.java | 44 ++- .../test/OrganizationAuthRefDocsTest.java | 17 +- .../client/test/PersonAuthRefDocsTest.java | 32 +- .../client/test/LoaninAuthRefsTest.java | 42 ++- .../client/test/LoaninServiceTest.java | 8 +- .../client/test/LoanoutAuthRefsTest.java | 34 +- .../client/test/LoanoutServiceTest.java | 48 ++- .../client/LocationAuthorityClientUtils.java | 10 +- .../test/LocationAuthorityServiceTest.java | 4 +- .../client/test/MediaAuthRefsTest.java | 16 +- .../client/test/MovementAuthRefsTest.java | 12 +- .../client/test/MovementSortByTest.java | 2 +- .../client/test/ObjectExitAuthRefsTest.java | 16 +- .../client/OrgAuthorityClientUtils.java | 12 +- .../client/test/OrgAuthorityAuthRefsTest.java | 12 +- .../client/test/OrgAuthorityServiceTest.java | 4 +- .../client/PersonAuthorityClientUtils.java | 16 +- .../test/PersonAuthoritySearchTest.java | 11 +- .../test/PersonAuthorityServicePerfTest.java | 8 +- .../test/PersonAuthorityServiceTest.java | 64 ++-- .../test/PlaceAuthorityServiceTest.java | 4 +- .../client/test/PublicItemServiceTest.java | 8 +- .../test/AuthenticationServiceTest.java | 35 +- .../client/test/AuthorizationServiceTest.java | 36 +- .../client/test/MultiTenancyTest.java | 36 +- .../test/TaxonomyAuthorityServiceTest.java | 23 +- .../test/ValuationcontrolServiceTest.java | 8 +- .../client/test/WorkAuthorityServiceTest.java | 4 +- 63 files changed, 1240 insertions(+), 779 deletions(-) create mode 100644 services/batch/service/src/main/java/org/collectionspace/services/batch/UriInfoImpl.java diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591Multiple.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591Multiple.java index 5e6c9f67f..bbc28b2d7 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591Multiple.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591Multiple.java @@ -112,34 +112,31 @@ public class I1591Multiple extends CollectionSpacePerformanceTest { * @param numberOfObjects The number of CollectionObject resources to create. * @return A list of the resource IDs of the newly-created object resources. */ - public String[] createCollectionObjects(int numberOfObjects) { - - long identifier = 0; - int i = 0; - - try { - for (i = 0; i <= numberOfObjects; i++) { - identifier = System.currentTimeMillis(); - coList[i] = createCollectionObject(identifier); - if (logger.isDebugEnabled() == true) { - logger.debug("Created CollectionObject #: " + i); - } - } - } catch (AssertionError e) { - if (logger.isDebugEnabled() == true) { - logger.debug("FAILURE: Created " + i + - " of " + numberOfObjects + - " before failing."); - } - Assert.assertTrue(false); - } - - return coList; - } + public String[] createCollectionObjects(int numberOfObjects) { + long identifier = 0; + int i = 0; + + try { + for (i = 0; i <= numberOfObjects; i++) { + identifier = System.currentTimeMillis(); + coList[i] = createCollectionObject(identifier); + if (logger.isDebugEnabled() == true) { + logger.debug("Created CollectionObject #: " + i); + } + } + } catch (AssertionError e) { + if (logger.isDebugEnabled() == true) { + logger.debug("FAILURE: Created " + i + " of " + numberOfObjects + + " before failing."); + } + Assert.assertTrue(false); + } + + return coList; + } @AfterClass(alwaysRun=true) public void cleanUp() { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String resourceId = ""; @@ -149,11 +146,10 @@ public class I1591Multiple extends CollectionSpacePerformanceTest { for (int i = 0; i < coList.length; i++) { resourceId = coList[i]; - ClientResponse res = collectionObjectClient.delete(resourceId); + collectionObjectClient.delete(resourceId).close(); if (logger.isDebugEnabled() == true) { logger.debug("Deleted CollectionObject #: " + i); } - res.releaseConnection(); } if (logger.isDebugEnabled()) { diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInst.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInst.java index e20b3f77f..99478a813 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInst.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInst.java @@ -128,11 +128,10 @@ public class I1591OneInst extends CollectionSpacePerformanceTest { for (int i = 0; i < coList.length; i++) { resourceId = coList[i]; - ClientResponse res = collectionObjectClient.delete(resourceId); + collectionObjectClient.delete(resourceId).close();; if (logger.isDebugEnabled() == true) { logger.debug("Deleted CollectionObject #: " + i); } - res.releaseConnection(); } if (logger.isDebugEnabled()) { diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInstOneClose.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInstOneClose.java index e2418267c..6bd225505 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInstOneClose.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/I1591OneInstOneClose.java @@ -124,11 +124,10 @@ public class I1591OneInstOneClose extends CollectionSpacePerformanceTest { for (int i = 0; i < coList.length; i++) { resourceId = coList[i]; - ClientResponse res = collectionObjectClient.delete(resourceId); + collectionObjectClient.delete(resourceId).close(); if (logger.isDebugEnabled() == true) { logger.debug("Deleted CollectionObject #: " + i); } - res.releaseConnection(); } if (logger.isDebugEnabled()) { 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 563577903..216f0cc38 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 @@ -321,8 +321,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { */ private void deleteCollectionObject(CollectionObjectClient collectionObjectClient, String resourceId) { - ClientResponse res = collectionObjectClient.delete(resourceId); - res.releaseConnection(); + collectionObjectClient.delete(resourceId).close(); } /** 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 e006e29f4..9850d1ab9 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 @@ -362,14 +362,14 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl res = client.delete(prebuiltAdminCSID); + Response res = client.delete(prebuiltAdminCSID); try { int statusCode = res.getStatus(); Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), @@ -392,7 +392,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl res = accClient.delete(accId); + Response res = accClient.delete(accId); try { assertStatusCode(res, "DeleteAccount"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -582,12 +582,12 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl res = roleClient.delete(roleId); + Response res = roleClient.delete(roleId); try { assertStatusCode(res, "DeleteRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java index fca3d9424..aaecd2c2e 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java @@ -208,17 +208,23 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest term.setTermDisplayName(termName); term.setTermName(termName); personTerms.add(term); + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); - PoxPayloadOut multipart = - PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse 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; } // Success outcomes @@ -230,19 +236,19 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest // Submit the request to the service and store the response. AcquisitionClient acquisitionClient = new AcquisitionClient(); - ClientResponse res = acquisitionClient.read(knownResourceId); + Response res = acquisitionClient.read(knownResourceId); 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()); acquisition = (AcquisitionsCommon) extractPart(input, acquisitionClient.getCommonPartName(), AcquisitionsCommon.class); Assert.assertNotNull(acquisition); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -277,21 +283,21 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest // // Get the auth refs and check them // - ClientResponse res2 = acquisitionClient.getAuthorityRefs(knownResourceId); + res = acquisitionClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { - assertStatusCode(res2, testName); - list = res2.getEntity(); + assertStatusCode(res, testName); + list = (AuthorityRefList)res.getEntity(); Assert.assertNotNull(list); } finally { - if (res2 != null) { - res2.releaseConnection(); + if (res != null) { + res.close(); } } List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); - if (logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("Expected " + NUM_AUTH_REFS_EXPECTED + " authority references, found " + numAuthRefsFound); } @@ -345,19 +351,16 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest AcquisitionClient acquisitionClient = new AcquisitionClient(); for (String resourceId : acquisitionIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse res = acquisitionClient.delete(resourceId); - res.releaseConnection(); + acquisitionClient.delete(resourceId).close(); } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete persons before PersonAuth for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); - res.releaseConnection(); + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } // Note: Any non-success response is ignored and not reported. - ClientResponse res = personAuthClient.delete(personAuthCSID); - res.releaseConnection(); + personAuthClient.delete(personAuthCSID).close(); } // --------------------------------------------------------------- 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 14c08f283..1f947f34e 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 @@ -637,8 +637,13 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); - int statusCode = res.getStatus(); + Response res = client.delete(knownResourceId); + int statusCode; + try { + statusCode = res.getStatus(); + } finally { + res.close(); + } // Check the status code of the response: does it match // the expected response(s)? @@ -663,8 +668,13 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); - int statusCode = res.getStatus(); + Response res = client.delete(NON_EXISTENT_ID); + int statusCode; + try { + statusCode = res.getStatus(); + } finally { + res.close(); + } // Check the status code of the response: does it match // the expected response(s)? diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java index 39804c57f..78649e079 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java @@ -471,14 +471,14 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl res = null; + Response res = permClient.delete(permId); try { - res = permClient.delete(permId); int statusCode = res.getStatus(); if (logger.isDebugEnabled()) { logger.debug("deletePermission: delete permission id=" @@ -624,7 +623,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl res = null; + Response res = roleClient.delete(roleId); try { - res = roleClient.delete(roleId); int statusCode = res.getStatus(); if (logger.isDebugEnabled()) { logger.debug("deleteRole: delete role id=" + roleId @@ -688,7 +686,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl delRes = null; + Response delRes = client.delete(rv.getRoleId()); try { - delRes = client.delete(rv.getRoleId()); int statusCode = delRes.getStatus(); Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (delRes != null) { - delRes.releaseConnection(); + delRes.close(); } } @@ -599,9 +598,8 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl res = null; + Response res = permClient.delete(permId); try { - res = permClient.delete(permId); int statusCode = res.getStatus(); if (logger.isDebugEnabled()) { logger.debug("deletePermission: delete permission id=" @@ -613,7 +611,7 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl res = null; + Response res = null; try { res = roleClient.delete(roleId); int statusCode = res.getStatus(); @@ -673,7 +671,7 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl res = client.create(role); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - // - // Specifically: - // Does it fall within the set of valid status codes? - // Does it exactly match the expected status code? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Store the ID returned from this create operation - // for additional tests below. - knownResourceId = extractId(res); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownResourceId=" + knownResourceId); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Store the ID returned from this create operation + // for additional tests below. + knownResourceId = extractId(res); + //allResourceIdsCreated.add(knownResourceId); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } finally { + res.close(); } } @@ -381,26 +384,30 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.read(verifyResourceId); - 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); + + Role output = (Role) res.getEntity(); + Assert.assertNotNull(output); + + //FIXME: Tenant ID of "1" should not be hard coded + String roleNameToVerify = "ROLE_" + + "1_" + + verifyRoleName.toUpperCase(); + Assert.assertEquals(output.getRoleName(), roleNameToVerify, + "RoleName fix did not work!"); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - Role output = (Role) res.getEntity(); - Assert.assertNotNull(output); - - //FIXME: Tenant ID of "1" should not be hard coded - String roleNameToVerify = "ROLE_" + - "1_" + - verifyRoleName.toUpperCase(); - Assert.assertEquals(output.getRoleName(), roleNameToVerify, - "RoleName fix did not work!"); } // Failure outcomes /* (non-Javadoc) @@ -417,16 +424,19 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.read(NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + int statusCode = res.getStatus(); + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(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); } // --------------------------------------------------------------- @@ -458,7 +468,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.update(knownResourceId, roleToUpdate); - int statusCode = res.getStatus(); - // Check the status code of the response: does it match the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + try { + // Check the status code of the response: does it match the expected response(s)? + int statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + + Role roleUpdated = (Role) res.getEntity(); + Assert.assertNotNull(roleUpdated); + + Assert.assertEquals(roleUpdated.getDescription(), + roleToUpdate.getDescription(), + "Data in updated object did not match submitted data."); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - - Role roleUpdated = (Role) res.getEntity(); - Assert.assertNotNull(roleUpdated); - - Assert.assertEquals(roleUpdated.getDescription(), - roleToUpdate.getDescription(), - "Data in updated object did not match submitted data."); } @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"}) public void verifyProtectionReadOnly(String testName) throws Exception { - + // Setup to create a new role setupCreate(); - - // Submit the request to the service and store the response. - RoleClient client = new RoleClient(); - Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true); + Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true); role.setMetadataProtection(RoleClient.IMMUTABLE); role.setPermsProtection(RoleClient.IMMUTABLE); + // + // Submit the create request to the service and store the response. + // + RoleClient client = new RoleClient(); ClientResponse res = client.create(role); - int statusCode = res.getStatus(); - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Store the ID returned from this create operation - // for additional tests below. - String testResourceId = extractId(res); - allResourceIdsCreated.add(testResourceId); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": testResourceId=" + testResourceId); + String testResourceId = null; + try { + int statusCode = res.getStatus(); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + // Store the ID returned from this create operation + // for additional tests below. + testResourceId = extractId(res); + allResourceIdsCreated.add(testResourceId); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": testResourceId=" + testResourceId); + } + } finally { + res.close(); } + + // Next, read back the role we just created. setupRead(); - // Submit the request to the service and store the response. ClientResponse roleRes = client.read(testResourceId); - statusCode = roleRes.getStatus(); - - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - Role roleRead = (Role) roleRes.getEntity(); - Assert.assertNotNull(roleRead); - String mdProtection = roleRead.getMetadataProtection(); - String permsProtection = roleRead.getPermsProtection(); - if (logger.isTraceEnabled()) { - logger.trace(testName + ": metadataProtection=" + mdProtection); - logger.trace(testName + ": permsProtection=" + permsProtection); + try { + int statusCode = roleRes.getStatus(); + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + Role roleRead = (Role) roleRes.getEntity(); + Assert.assertNotNull(roleRead); + String mdProtection = roleRead.getMetadataProtection(); + String permsProtection = roleRead.getPermsProtection(); + if (logger.isTraceEnabled()) { + logger.trace(testName + ": metadataProtection=" + mdProtection); + logger.trace(testName + ": permsProtection=" + permsProtection); + } + Assert.assertFalse(role.getMetadataProtection().equals(mdProtection), + "Role allowed create to set the metadata protection flag."); + Assert.assertFalse(role.getPermsProtection().equals(permsProtection), + "Role allowed create to set the perms protection flag."); + } finally { + res.close(); } - Assert.assertFalse(role.getMetadataProtection().equals(mdProtection), - "Role allowed create to set the metadata protection flag."); - Assert.assertFalse(role.getPermsProtection().equals(permsProtection), - "Role allowed create to set the perms protection flag."); - + // Finally, update the role with changes and verify setupUpdate(); Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true); @@ -604,31 +627,33 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.update(knownResourceId, roleToUpdate); - 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, Response.Status.BAD_REQUEST.getStatusCode()); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); - } // Failure outcomes @@ -711,16 +739,20 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.update(NON_EXISTENT_ID, role); - 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); } // --------------------------------------------------------------- @@ -756,17 +788,21 @@ public class RoleServiceTest extends AbstractServiceTestImpl res = client.delete(NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + Response res = client.delete(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); } // --------------------------------------------------------------- diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/UriInfoImpl.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/UriInfoImpl.java new file mode 100644 index 000000000..237c156e4 --- /dev/null +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/UriInfoImpl.java @@ -0,0 +1,315 @@ +package org.collectionspace.services.batch; + +import org.jboss.resteasy.specimpl.MultivaluedMapImpl; +import org.jboss.resteasy.specimpl.PathSegmentImpl; +import org.jboss.resteasy.util.Encode; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Bill Burke + * @version $Revision: 1 $ + */ +public class UriInfoImpl implements UriInfo +{ + private String path; + private String encodedPath; + private MultivaluedMap queryParameters; + private MultivaluedMap encodedQueryParameters; + private MultivaluedMap pathParameters; + private MultivaluedMap encodedPathParameters; + private MultivaluedMap pathParameterPathSegments; + private MultivaluedMap encodedPathParameterPathSegments; + + private List pathSegments; + private List encodedPathSegments; + private URI absolutePath; + private URI absolutePathWithQueryString; + private URI baseURI; + private List matchedUris; + private List encodedMatchedUris; + private List ancestors; + + + public UriInfoImpl(URI absolutePath, URI baseUri, String encodedPath, String queryString, List encodedPathSegments) + { + /* + logger.info("**** URIINFO encodedPath: " + encodedPath); + for (PathSegment segment : encodedPathSegments) + { + logger.info(" Segment: " + segment.getPath()); + } + */ + this.encodedPath = encodedPath; + this.path = Encode.decodePath(encodedPath); + //System.out.println("path: " + path); + //System.out.println("encodedPath: " + encodedPath); + + this.absolutePath = absolutePath; + this.encodedPathSegments = encodedPathSegments; + this.baseURI = baseUri; + + extractParameters(queryString); + this.pathSegments = new ArrayList(encodedPathSegments.size()); + for (PathSegment segment : encodedPathSegments) + { + pathSegments.add(new PathSegmentImpl(((PathSegmentImpl) segment).getOriginal(), true)); + } + if (queryString == null) + { + this.absolutePathWithQueryString = absolutePath; + } + else + { + this.absolutePathWithQueryString = URI.create(absolutePath.toString() + "?" + queryString); + } + } + + public String getPath() + { + return path; + } + + public String getPath(boolean decode) + { + if (decode) return getPath(); + return encodedPath; + } + + public List getPathSegments() + { + return pathSegments; + } + + public List getPathSegments(boolean decode) + { + if (decode) return getPathSegments(); + return encodedPathSegments; + } + + public URI getRequestUri() + { + return absolutePathWithQueryString; + } + + public UriBuilder getRequestUriBuilder() + { + return UriBuilder.fromUri(absolutePathWithQueryString); + } + + public URI getAbsolutePath() + { + return absolutePath; + } + + public UriBuilder getAbsolutePathBuilder() + { + return UriBuilder.fromUri(absolutePath); + } + + public URI getBaseUri() + { + return baseURI; + } + + public UriBuilder getBaseUriBuilder() + { + return UriBuilder.fromUri(baseURI); + } + + public MultivaluedMap getPathParameters() + { + if (pathParameters == null) + { + pathParameters = new MultivaluedMapImpl(); + } + return pathParameters; + } + + public void addEncodedPathParameter(String name, String value) + { + getEncodedPathParameters().add(name, value); + String value1 = Encode.decodePath(value); + getPathParameters().add(name, value1); + } + + private MultivaluedMap getEncodedPathParameters() + { + if (encodedPathParameters == null) + { + encodedPathParameters = new MultivaluedMapImpl(); + } + return encodedPathParameters; + } + + public MultivaluedMap getEncodedPathParameterPathSegments() + { + if (encodedPathParameterPathSegments == null) + { + encodedPathParameterPathSegments = new MultivaluedMapImpl(); + } + return encodedPathParameterPathSegments; + } + + public MultivaluedMap getPathParameterPathSegments() + { + if (pathParameterPathSegments == null) + { + pathParameterPathSegments = new MultivaluedMapImpl(); + } + return pathParameterPathSegments; + } + + public MultivaluedMap getPathParameters(boolean decode) + { + if (decode) return getPathParameters(); + return getEncodedPathParameters(); + } + + public MultivaluedMap getQueryParameters() + { + if (queryParameters == null) + { + queryParameters = new MultivaluedMapImpl(); + } + return queryParameters; + } + + protected MultivaluedMap getEncodedQueryParameters() + { + if (encodedQueryParameters == null) + { + this.encodedQueryParameters = new MultivaluedMapImpl(); + } + return encodedQueryParameters; + } + + + public MultivaluedMap getQueryParameters(boolean decode) + { + if (decode) return getQueryParameters(); + else return getEncodedQueryParameters(); + } + + protected void extractParameters(String queryString) + { + if (queryString == null || queryString.equals("")) return; + + String[] params = queryString.split("&"); + + for (String param : params) + { + if (param.indexOf('=') >= 0) + { + String[] nv = param.split("=", 2); + try + { + String name = URLDecoder.decode(nv[0], "UTF-8"); + String val = nv.length > 1 ? nv[1] : ""; + getEncodedQueryParameters().add(name, val); + getQueryParameters().add(name, URLDecoder.decode(val, "UTF-8")); + } + catch (UnsupportedEncodingException e) + { + throw new RuntimeException(e); + } + } + else + { + try + { + String name = URLDecoder.decode(param, "UTF-8"); + getEncodedQueryParameters().add(name, ""); + getQueryParameters().add(name, ""); + } + catch (UnsupportedEncodingException e) + { + throw new RuntimeException(e); + } + } + } + } + + public List getMatchedURIs(boolean decode) + { + if (decode) + { + if (matchedUris == null) matchedUris = new ArrayList(); + return matchedUris; + } + else + { + if (encodedMatchedUris == null) encodedMatchedUris = new ArrayList(); + return encodedMatchedUris; + } + } + + public List getMatchedURIs() + { + return getMatchedURIs(true); + } + + public List getMatchedResources() + { + if (ancestors == null) ancestors = new ArrayList(); + return ancestors; + } + + + public void pushCurrentResource(Object resource) + { + if (ancestors == null) ancestors = new ArrayList(); + ancestors.add(0, resource); + } + + public void popCurrentResource() + { + if (ancestors != null && ancestors.size() > 0) + { + ancestors.remove(0); + } + } + + public void pushMatchedURI(String encoded, String decoded) + { + if (encodedMatchedUris == null) encodedMatchedUris = new ArrayList(); + encodedMatchedUris.add(0, encoded); + + if (matchedUris == null) matchedUris = new ArrayList(); + matchedUris.add(0, decoded); + } + + public void popMatchedURI() + { + if (encodedMatchedUris != null && encodedMatchedUris.size() > 0) + { + encodedMatchedUris.remove(0); + } + if (matchedUris != null && matchedUris.size() > 0) + { + matchedUris.remove(0); + } + } + +@Override +public URI relativize(URI arg0) { + // TODO Auto-generated method stub + return null; +} + +@Override +public URI resolve(URI arg0) { + // TODO Auto-generated method stub + return null; +} + +} diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java index c91bcad95..96a88e296 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java @@ -166,13 +166,13 @@ public class BlobAuthRefsTest extends BaseServiceTest { personTerms.add(term); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + Response res = personAuthClient.createItem(personAuthCSID, multipart); try { assertStatusCode(res, "createPerson (not a surefire test)"); result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -189,17 +189,17 @@ public class BlobAuthRefsTest extends BaseServiceTest { public void readAndCheckAuthRefs(String testName) throws Exception { testSetup(STATUS_OK, ServiceRequestType.READ); BlobClient blobClient = new BlobClient(); - ClientResponse res = blobClient.read(knownResourceId); + Response res = blobClient.read(knownResourceId); BlobsCommon blob = null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); blob = (BlobsCommon) extractPart(input, blobClient.getCommonPartName(), BlobsCommon.class); Assert.assertNotNull(blob); logger.debug(objectAsXmlString(blob, BlobsCommon.class)); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -207,10 +207,10 @@ public class BlobAuthRefsTest extends BaseServiceTest { Assert.assertEquals(blob.getName(), blobName); // Get the auth refs and check them - ClientResponse res2 = blobClient.getAuthorityRefs(knownResourceId); + res = blobClient.getAuthorityRefs(knownResourceId); try { - assertStatusCode(res2, testName); - AuthorityRefList list = res2.getEntity(); + assertStatusCode(res, testName); + AuthorityRefList list = (AuthorityRefList)res.getEntity(); List items = list.getAuthorityRefItem(); int numAuthRefsFound = items.size(); logger.debug("Authority references, found " + numAuthRefsFound); @@ -227,8 +227,8 @@ public class BlobAuthRefsTest extends BaseServiceTest { } } } finally { - if (res2 != null) { - res2.releaseConnection(); + if (res != null) { + res.close(); } } } diff --git a/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java index 30c54f5c0..7cee06e85 100644 --- a/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java +++ b/services/citation/client/src/main/java/org/collectionspace/services/client/CitationAuthorityClientUtils.java @@ -85,7 +85,7 @@ public class CitationAuthorityClientUtils { PoxPayloadOut multipart = createCitationInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -100,7 +100,7 @@ public class CitationAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -120,7 +120,7 @@ public class CitationAuthorityClientUtils { return createItemInAuthority(vcsid, commonPartXML, client ); } - 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/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java index 77d06abc9..98f99d3f2 100644 --- a/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java +++ b/services/citation/client/src/test/java/org/collectionspace/services/client/test/CitationAuthorityServiceTest.java @@ -265,13 +265,13 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest read(String csid) { + public Response read(String csid) { return getProxy().read(csid); } 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 2b6d0c5f9..69e24e09f 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 @@ -513,7 +513,7 @@ public abstract class AbstractServiceClientImpl delete(String csid) { + public Response delete(String csid) { return getProxy().delete(csid); } @@ -523,7 +523,7 @@ public abstract class AbstractServiceClientImpl getAuthorityRefs(String csid) { + public Response getAuthorityRefs(String csid) { // Response.getEntity returns AuthorityRefList type return getProxy().getAuthorityRefs(csid); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java index affb581bd..85596a5ce 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java @@ -31,10 +31,10 @@ public interface AuthorityClient void setInAuthority(AUTHORITY_ITEM_TYPE item, String inAuthorityCsid); //(C)reate Item - ClientResponse createItem(String vcsid, PoxPayloadOut poxPayloadOut); + Response createItem(String vcsid, PoxPayloadOut poxPayloadOut); //(R)ead Item - ClientResponse readItem(String vcsid, String csid); + Response readItem(String vcsid, String csid); //(R)ead Item ClientResponse readItem(String vcsid, String csid, Boolean includeDeleted); @@ -43,7 +43,7 @@ public interface AuthorityClient ClientResponse updateItem(String vcsid, String csid, PoxPayloadOut poxPayloadOut); //(D)elete Item - ClientResponse deleteItem(String vcsid, String csid); + Response deleteItem(String vcsid, String csid); // Get a list of objects that ClientResponse getReferencingObjects( diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java index 7d8443a21..d8e1d3de7 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClientImpl.java @@ -21,13 +21,13 @@ public abstract class AuthorityClientImpl createItem(String vcsid, PoxPayloadOut poxPayloadOut) { + public Response createItem(String vcsid, PoxPayloadOut poxPayloadOut) { return getProxy().createItem(vcsid, poxPayloadOut.getBytes()); } //(R)ead Item @Override - public ClientResponse readItem(String vcsid, String csid) { + public Response readItem(String vcsid, String csid) { return getProxy().readItem(vcsid, csid, INCLUDE_DELETE_TRUE); } @@ -44,7 +44,7 @@ public abstract class AuthorityClientImpl deleteItem(String vcsid, String csid) { + public Response deleteItem(String vcsid, String csid) { return getProxy().deleteItem(vcsid, csid); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java index 37f16e458..0d9ccdf12 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityProxy.java @@ -47,7 +47,7 @@ public interface AuthorityProxy extends CollectionSpaceCommonListPoxProxy { //(D)elete Item @DELETE @Path("/{vcsid}/items/{csid}") - ClientResponse deleteItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + Response deleteItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); /** * Get a list of objects that reference a given authority term. 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 5f3e55772..d88554a84 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 @@ -180,7 +180,7 @@ public interface CollectionSpaceClient read(String csid); + public Response read(String csid); public ClientResponse update(String csid, REQUEST_TYPE payload); @@ -226,7 +226,7 @@ public interface CollectionSpaceClient getAuthorityRefs(String csid); + public Response getAuthorityRefs(String csid); // Response.getEntity returns AuthorityRefList type /** * Delete. 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 e8aade4ea..0b2b6e800 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 @@ -23,7 +23,7 @@ public interface CollectionSpacePoxProxy extends // (R)ead @GET @Path("/{csid}") - ClientResponse read(@PathParam("csid") String csid); + Response read(@PathParam("csid") String csid); // Returned entity type in response is String // (R)ead @GET 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 2ed0b6830..40b6201f7 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 @@ -50,7 +50,7 @@ public interface CollectionSpaceProxy { //(D)elete @DELETE @Path("/{csid}") - ClientResponse delete(@PathParam("csid") String csid); + Response delete(@PathParam("csid") String csid); // List Authority References @GET 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 f878f897e..08578f359 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 @@ -313,8 +313,13 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); + Response res = client.deleteItem(knownResourceId, knownItemResourceId); + int statusCode; + try { + statusCode = res.getStatus(); + } finally { + res.close(); + } // Check the status code of the response: does it match // the expected response(s)? @@ -386,8 +391,13 @@ public abstract class AbstractAuthorityServiceTest client = (AuthorityClientImpl)this.getClientInstance(); - ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); - int statusCode = res.getStatus(); + Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); + int statusCode; + try { + statusCode = res.getStatus(); + } finally { + res.close(); + } // Check the status code of the response: does it match // the expected response(s)? diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java index 5d228ee66..b4c1abce2 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractPoxServiceTestImpl.java @@ -1,5 +1,7 @@ package org.collectionspace.services.client.test; +import javax.ws.rs.core.Response; + import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; @@ -7,7 +9,6 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; - import org.jboss.resteasy.client.ClientResponse; import org.testng.Assert; @@ -19,7 +20,7 @@ public abstract class AbstractPoxServiceTestImpl { @Override - public CPT extractCommonPartValue(ClientResponse res) throws Exception { + public CPT extractCommonPartValue(Response res) throws Exception { CPT result = null; CollectionSpaceClient client = getClientInstance(); @@ -66,12 +67,12 @@ public abstract class AbstractPoxServiceTestImpl 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."); diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index 6d6550f44..6b6514d9b 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -185,26 +185,30 @@ public abstract class AbstractServiceTestImpl res = client.read(getKnowResourceId()); - 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(getKnowResourceId()); + 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); + + RESPONSE_TYPE output = (RESPONSE_TYPE) res.getEntity(); + Assert.assertNotNull(output); + + // + // Now compare with the expected field values + // + REQUEST_TYPE expectedResult = createInstance("read_test"); + compareReadInstances(extractCommonPartValue(expectedResult), extractCommonPartValue(res)); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - RESPONSE_TYPE output = (RESPONSE_TYPE) res.getEntity(); - Assert.assertNotNull(output); - - // - // Now compare with the expected field values - // - REQUEST_TYPE expectedResult = createInstance("read_test"); - compareReadInstances(extractCommonPartValue(expectedResult), extractCommonPartValue(res)); } @Override @@ -238,7 +242,7 @@ public abstract class AbstractServiceTestImpl res = client.read(NON_EXISTENT_ID); + Response res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); try { // Check the status code of the response: does it match @@ -250,7 +254,7 @@ public abstract class AbstractServiceTestImpl getCommonPartTypeClass(); - public CPT extractCommonPartValue(ClientResponse res) throws Exception { + public CPT extractCommonPartValue(Response res) throws Exception { CPT result = null; result = (CPT) res.getEntity(); return result; @@ -322,18 +326,24 @@ public abstract class AbstractServiceTestImpl res = client.read(getKnowResourceId()); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), testExpectedStatusCode); - - if (logger.isDebugEnabled()) { - logger.debug("Got object to update with CSID= " + getKnowResourceId()); + Response res = client.read(getKnowResourceId()); + CPT commonPartObject = null; + try { + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), testExpectedStatusCode); + + if (logger.isDebugEnabled()) { + logger.debug("Got object to update with CSID= " + getKnowResourceId()); + } + + commonPartObject = this.extractCommonPartValue(res); + Assert.assertNotNull(commonPartObject); + } finally { + res.close(); } - - CPT commonPartObject = this.extractCommonPartValue(res); - Assert.assertNotNull(commonPartObject); + CPT theUpdate = updateInstance(commonPartObject); if (logger.isDebugEnabled()) { logger.debug("\n\nTo be updated fields: CSID = " + getKnowResourceId() + "\n" @@ -343,17 +353,22 @@ public abstract class AbstractServiceTestImpl personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); @@ -258,16 +259,21 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest 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; } /** @@ -351,6 +357,8 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest orgInfo = new HashMap(); orgInfo.put(OrganizationJAXBSchema.FOUNDING_PLACE, foundingPlace); orgInfo.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortIdentifier); @@ -364,13 +372,19 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest res = orgAuthClient.createItem(orgAuthCSID, multipart); - int statusCode = res.getStatus(); - - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, STATUS_CREATED); - return extractId(res); + Response res = orgAuthClient.createItem(orgAuthCSID, 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; } /** @@ -417,30 +431,30 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest res = collectionObjectClient.read(knownResourceId); + Response res = collectionObjectClient.read(knownResourceId); CollectionobjectsCommon collectionObject = null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); collectionObject = (CollectionobjectsCommon) extractPart(input, collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class); Assert.assertNotNull(collectionObject); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // // Next, get all of the auth refs and check that the expected number is returned // - ClientResponse res2 = collectionObjectClient.getAuthorityRefs(knownResourceId); + res = collectionObjectClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { - assertStatusCode(res2, testName); - list = res2.getEntity(); + assertStatusCode(res, testName); + list = (AuthorityRefList)res.getEntity(); } finally { - if (res2 != null) { - res2.releaseConnection(); + if (res != null) { + res.close(); } } @@ -510,24 +524,24 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest res = doAdvancedSearch(propertyName, propertyValue, "="); - 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); + + // Verify that the number of resources matched by the search + // is identical to the expected result + long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); + Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Verify that the number of resources matched by the search - // is identical to the expected result - long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); - Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, groups = { "oneKeyword" }) @@ -199,22 +203,26 @@ public class CollectionObjectSearchTest extends BaseServiceTest res = doSearch(KEYWORD); - 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); + + // Verify that the number of resources matched by the search + // is identical to the expected result + long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); + Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Verify that the number of resources matched by the search - // is identical to the expected result - long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); - Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) @@ -238,44 +246,51 @@ public class CollectionObjectSearchTest extends BaseServiceTest res = doSearch(TWO_KEYWORDS); - 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); + + // Verify that the number of resources matched by the search + // is identical to the expected result + long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); + Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Verify that the number of resources matched by the search - // is identical to the expected result - long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); - Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); // Search using a single term // Send the search request and receive a response res = doSearch(TWO_KEYWORDS.get(0)); - 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); + + // Verify that the number of resources matched by the search + // is identical to the expected result + long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); + Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Verify that the number of resources matched by the search - // is identical to the expected result - NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); - Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); - } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) @@ -394,23 +409,27 @@ public class CollectionObjectSearchTest extends BaseServiceTest res = doSearch(NON_EXISTENT_KEYWORD); - int statusCode = res.getStatus(); + int statusCode; + try { + 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); + // 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); + + // Verify that the number of resources matched by the search + // is identical to the expected result + long NUM_MATCHES_EXPECTED = 0; + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); + Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Verify that the number of resources matched by the search - // is identical to the expected result - long NUM_MATCHES_EXPECTED = 0; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); - Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); - } // --------------------------------------------------------------- @@ -440,7 +459,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest res = client - .advancedSearchIncludeDeleted(whereClause, false); // NOT_INCLUDING_DELETED_RESOURCES + ClientResponse res = client.advancedSearchIncludeDeleted(whereClause, false); // NOT_INCLUDING_DELETED_RESOURCES + return res; } 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 00fc27506..609a27914 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 @@ -550,6 +550,7 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -835,7 +836,7 @@ public class CollectionObjectServiceTest extends AbstractPoxServiceTestImpl res = client.read(csid); - 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); + CollectionobjectsCommon collectionObject = 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); + + // Extract the common part. + collectionObject = extractCommonPartValue(res); + Assert.assertNotNull(collectionObject); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, testExpectedStatusCode); - - // Extract the common part. - CollectionobjectsCommon collectionObject = extractCommonPartValue(res); - Assert.assertNotNull(collectionObject); return collectionObject; } diff --git a/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClientUtils.java b/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClientUtils.java index 39bbdc7a0..5b3f20fd0 100644 --- a/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClientUtils.java +++ b/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClientUtils.java @@ -84,7 +84,7 @@ public class ConceptAuthorityClientUtils { PoxPayloadOut multipart = createConceptInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -99,7 +99,7 @@ public class ConceptAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -119,7 +119,7 @@ public class ConceptAuthorityClientUtils { return createItemInAuthority(vcsid, commonPartXML, client ); } - 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/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java index e3462f9dc..ad5361596 100644 --- a/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java +++ b/services/concept/client/src/test/java/org/collectionspace/services/client/test/ConceptAuthorityServiceTest.java @@ -273,13 +273,13 @@ public class ConceptAuthorityServiceTest extends AbstractAuthorityServiceTest personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -183,16 +185,21 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest res = personAuthClient.createItem(personAuthCSID, multipart); - int statusCode = res.getStatus(); + + 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(); + } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - Assert.assertEquals(statusCode, STATUS_CREATED); - return extractId(res); + return result; } // Success outcomes @@ -204,12 +211,12 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest res = conditioncheckClient.read(knownResourceId); + Response res = conditioncheckClient.read(knownResourceId); ConditionchecksCommon conditioncheckCommon = 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()); conditioncheckCommon = (ConditionchecksCommon) extractPart(input, conditioncheckClient.getCommonPartName(), ConditionchecksCommon.class); Assert.assertNotNull(conditioncheckCommon); @@ -218,7 +225,7 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest res2 = conditioncheckClient.getAuthorityRefs(knownResourceId); + Response res2 = conditioncheckClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); Assert.assertNotNull(list); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } @@ -298,9 +305,7 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest response = - personAuthClient.deleteItem(personAuthCSID, resourceId); // alternative to personAuthClient.deleteItem().releaseConnection(); - response.releaseConnection(); + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } // Delete PersonAuthority resource(s). @@ -309,11 +314,9 @@ public class ConditioncheckAuthRefsTest extends BaseServiceTest response = null; for (String resourceId : conditioncheckIdsCreated) { // Note: Any non-success responses are ignored and not reported. - response = conditioncheckClient.delete(resourceId); // alternative to conditioncheckClient.delete(resourceId).releaseConnection(); - response.releaseConnection(); + conditioncheckClient.delete(resourceId).close(); } } } 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 e8cd3b933..64f7ed344 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 @@ -546,7 +546,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { int statusCode = res.getStatus(); @@ -560,7 +560,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -593,7 +593,7 @@ public class ConditioncheckServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + Response res = client.delete(knownResourceId); + 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); } // Failure outcomes @@ -595,17 +599,21 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + Response res = client.delete(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); } // --------------------------------------------------------------- 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 20287fb8d..a7451657a 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 @@ -524,7 +524,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { int statusCode = res.getStatus(); @@ -538,7 +538,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -571,7 +571,7 @@ public class ExhibitionServiceTest extends AbstractPoxServiceTestImpl { } protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -222,13 +224,19 @@ public class IntakeAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse 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; } // Success outcomes @@ -240,10 +248,10 @@ public class IntakeAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. IntakeClient intakeClient = new IntakeClient(); - ClientResponse res = intakeClient.read(knownResourceId); + Response res = intakeClient.read(knownResourceId); try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); IntakesCommon intake = (IntakesCommon) extractPart(input, intakeClient.getCommonPartName(), IntakesCommon.class); Assert.assertNotNull(intake); @@ -253,19 +261,19 @@ public class IntakeAuthRefsTest extends BaseServiceTest { Assert.assertEquals(intake.getInsurers().getInsurer().get(0), insurerRefName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // Get the auth refs and check them - ClientResponse res2 = intakeClient.getAuthorityRefs(knownResourceId); + res = intakeClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { - assertStatusCode(res2, testName); - list = res2.getEntity(); + assertStatusCode(res, testName); + list = (AuthorityRefList)res.getEntity(); } finally { - if (res2 != null) { - res2.releaseConnection(); + if (res != null) { + res.close(); } } @@ -325,14 +333,14 @@ public class IntakeAuthRefsTest extends BaseServiceTest { IntakeClient intakeClient = new IntakeClient(); // Note: Any non-success responses are ignored and not reported. for (String resourceId : intakeIdsCreated) { - intakeClient.delete(resourceId).releaseConnection(); + intakeClient.delete(resourceId).close(); } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete persons before PersonAuth for (String resourceId : personIdsCreated) { - personAuthClient.deleteItem(personAuthCSID, resourceId).releaseConnection(); + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } - personAuthClient.delete(personAuthCSID).releaseConnection(); + personAuthClient.delete(personAuthCSID).close(); } // --------------------------------------------------------------- diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java index 02284dbd9..1f92cf1d0 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java @@ -226,7 +226,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest res = orgAuthClient.createItem(orgAuthCSID, multipart); + Response res = orgAuthClient.createItem(orgAuthCSID, multipart); int statusCode = res.getStatus(); Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), @@ -244,16 +244,15 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest refDocListResp = - orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID); + Response refDocListResp = orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID); AuthorityRefDocList list = null; try { assertStatusCode(refDocListResp, testName); - list = refDocListResp.getEntity(); + list = (AuthorityRefDocList)refDocListResp.getEntity(); Assert.assertNotNull(list); } finally { if (refDocListResp != null) { - refDocListResp.releaseConnection(); + refDocListResp.close(); } } @@ -310,17 +309,15 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest res = intakeClient.delete(resourceId); - res.releaseConnection(); + intakeClient.delete(resourceId).close(); } // Delete persons before PersonAuth OrgAuthorityClient personAuthClient = new OrgAuthorityClient(); for (String resourceId : orgIdsCreated) { - ClientResponse res = personAuthClient.deleteItem(orgAuthCSID, resourceId); - res.releaseConnection(); + personAuthClient.deleteItem(orgAuthCSID, resourceId).close(); } if (orgAuthCSID != null) { - personAuthClient.delete(orgAuthCSID).releaseConnection(); + personAuthClient.delete(orgAuthCSID).close(); } } diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java index 9f81cccb3..04f2c2978 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java @@ -226,6 +226,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { } protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -240,13 +242,19 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse 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; } // Success outcomes @@ -266,7 +274,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { list = res.getEntity(); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -417,17 +425,15 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { IntakeClient intakeClient = new IntakeClient(); // Note: Any non-success responses are ignored and not reported. for (String resourceId : intakeIdsCreated) { - ClientResponse res = intakeClient.delete(resourceId); - res.releaseConnection(); + intakeClient.delete(resourceId).close(); } // Delete persons before PersonAuth PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); for (String resourceId : personIdsCreated) { - ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); - res.releaseConnection(); + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } if (personAuthCSID != null) { - personAuthClient.delete(personAuthCSID).releaseConnection(); + personAuthClient.delete(personAuthCSID).close(); } } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java index 7322af4d2..9432dfbc9 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java @@ -210,6 +210,8 @@ public class LoaninAuthRefsTest extends BaseServiceTest { } protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -224,13 +226,19 @@ public class LoaninAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse 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; } // Success outcomes @@ -242,12 +250,12 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. LoaninClient loaninClient = new LoaninClient(); - ClientResponse res = loaninClient.read(knownResourceId); + Response res = loaninClient.read(knownResourceId); LoansinCommon loaninCommon = 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()); loaninCommon = (LoansinCommon) extractPart(input, loaninClient.getCommonPartName(), LoansinCommon.class); Assert.assertNotNull(loaninCommon); @@ -256,7 +264,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // @@ -269,15 +277,15 @@ public class LoaninAuthRefsTest extends BaseServiceTest { Assert.assertEquals(loaninCommon.getBorrowersAuthorizer(), borrowersAuthorizerRefName); // Get the auth refs and check them - ClientResponse res2 = loaninClient.getAuthorityRefs(knownResourceId); + Response res2 = loaninClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); Assert.assertNotNull(list); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } @@ -341,9 +349,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. - ClientResponse response = - personAuthClient.deleteItem(personAuthCSID, resourceId); // alternative to personAuthClient.deleteItem().releaseConnection(); - response.releaseConnection(); + personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } // Delete PersonAuthority resource(s). @@ -352,11 +358,9 @@ public class LoaninAuthRefsTest extends BaseServiceTest { personAuthClient.delete(personAuthCSID); // Delete Loans In resource(s). LoaninClient loaninClient = new LoaninClient(); - ClientResponse response = null; for (String resourceId : loaninIdsCreated) { // Note: Any non-success responses are ignored and not reported. - response = loaninClient.delete(resourceId); // alternative to loaninClient.delete(resourceId).releaseConnection(); - response.releaseConnection(); + loaninClient.delete(resourceId).close(); } } } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index 75a223331..6d4df126d 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -531,7 +531,7 @@ public class LoaninServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { int statusCode = res.getStatus(); @@ -545,7 +545,7 @@ public class LoaninServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -578,7 +578,7 @@ public class LoaninServiceTest extends AbstractPoxServiceTestImpl { } protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + String result = null; + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); @@ -219,13 +221,19 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse 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; } // Success outcomes @@ -237,12 +245,12 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. LoanoutClient loanoutClient = new LoanoutClient(); - ClientResponse res = loanoutClient.read(knownResourceId); + Response res = loanoutClient.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()); loanoutCommon = (LoansoutCommon) extractPart(input, loanoutClient.getCommonPartName(), LoansoutCommon.class); Assert.assertNotNull(loanoutCommon); @@ -251,7 +259,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -262,14 +270,14 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { Assert.assertEquals(loanoutCommon.getLendersContact(), lendersContactRefName); // Get the auth refs and check them - ClientResponse res2 = loanoutClient.getAuthorityRefs(knownResourceId); + Response res2 = loanoutClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } 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 41d46a08c..95a873b9d 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 @@ -644,17 +644,21 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl res = client.delete(knownResourceId); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + Response res = client.delete(knownResourceId); + 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); } // Failure outcomes @@ -670,17 +674,21 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if (logger.isDebugEnabled()) { - logger.debug(testName + ": status = " + statusCode); + Response res = client.delete(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); } // --------------------------------------------------------------- diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index d13558888..fbc3e3a94 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -138,7 +138,7 @@ public class LocationAuthorityClientUtils { createLocationInstance( locationAuthorityRefName, locationMap, terms, client.getItemCommonPartName() ); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -155,7 +155,7 @@ public class LocationAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -186,7 +186,7 @@ public class LocationAuthorityClientUtils { PoxPayloadOut multipart = createLocationInstance(commonPartXML, client.getItemCommonPartName()); String newID = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -201,7 +201,7 @@ public class LocationAuthorityClientUtils { } newID = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return newID; @@ -252,7 +252,7 @@ public class LocationAuthorityClientUtils { 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/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 55c909eed..cf8b400c0 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 @@ -347,13 +347,13 @@ public class LocationAuthorityServiceTest extends AbstractAuthorityServiceTest { personTerms.add(term); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance( personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + Response res = personAuthClient.createItem(personAuthCSID, multipart); try { assertStatusCode(res, "createPerson (not a surefire test)"); result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -191,18 +191,18 @@ public class MediaAuthRefsTest extends BaseServiceTest { testSetup(STATUS_OK, ServiceRequestType.READ); MediaClient mediaClient = new MediaClient(); - ClientResponse res = mediaClient.read(knownResourceId); + Response res = mediaClient.read(knownResourceId); PoxPayloadIn input = null; MediaCommon media = null; try { assertStatusCode(res, testName); - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); media = (MediaCommon) extractPart(input, mediaClient.getCommonPartName(), MediaCommon.class); Assert.assertNotNull(media); logger.debug(objectAsXmlString(media, MediaCommon.class)); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -210,14 +210,14 @@ public class MediaAuthRefsTest extends BaseServiceTest { Assert.assertEquals(media.getTitle(), title); // Get the auth refs and check them - ClientResponse res2 = mediaClient.getAuthorityRefs(knownResourceId); + Response res2 = mediaClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } 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 73f373e16..c1d896a9f 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 @@ -222,12 +222,12 @@ public class MovementAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient movementClient = new MovementClient(); - ClientResponse res = movementClient.read(knownResourceId); + Response res = movementClient.read(knownResourceId); 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(movementClient.getCommonPartName()); if (payloadInputPart != null) { movementCommon = (MovementsCommon) payloadInputPart.getBody(); @@ -238,7 +238,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { } } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } // Check a couple of fields @@ -246,14 +246,14 @@ public class MovementAuthRefsTest extends BaseServiceTest { Assert.assertEquals(movementCommon.getMovementContact(), movementContactRefName); // Get the auth refs and check them - ClientResponse res2 = movementClient.getAuthorityRefs(knownResourceId); + Response res2 = movementClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } 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 54841b467..00569b780 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 @@ -516,7 +516,7 @@ public class MovementSortByTest extends BaseServiceTest { MovementClient movementClient = new MovementClient(); for (String resourceId : movementIdsCreated) { // Note: Any non-success responses are ignored and not reported. - movementClient.delete(resourceId).releaseConnection(); + movementClient.delete(resourceId).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 a98bbf47a..ed5c38e16 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 @@ -181,13 +181,13 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); - ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + Response res = personAuthClient.createItem(personAuthCSID, multipart); try { assertStatusCode(res, "createPerson (not a surefire test)"); result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -199,17 +199,17 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest public void readAndCheckAuthRefs(String testName) throws Exception { testSetup(STATUS_OK, ServiceRequestType.READ); ObjectExitClient objectexitClient = new ObjectExitClient(); - ClientResponse res = objectexitClient.read(knownResourceId); + Response res = objectexitClient.read(knownResourceId); ObjectexitCommon objectexit = null; try { assertStatusCode(res, testName); - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); objectexit = (ObjectexitCommon) extractPart(input, objectexitClient.getCommonPartName(), ObjectexitCommon.class); Assert.assertNotNull(objectexit); logger.debug(objectAsXmlString(objectexit, ObjectexitCommon.class)); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -218,14 +218,14 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest Assert.assertEquals(objectexit.getExitNumber(), exitNumber); // Get the auth refs and check them - ClientResponse res2 = objectexitClient.getAuthorityRefs(knownResourceId); + Response res2 = objectexitClient.getAuthorityRefs(knownResourceId); AuthorityRefList list = null; try { assertStatusCode(res2, testName); - list = res2.getEntity(); + list = (AuthorityRefList)res2.getEntity(); } finally { if (res2 != null) { - res2.releaseConnection(); + res2.close(); } } List items = list.getAuthorityRefItem(); 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 e07bbed73..379a133ef 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 @@ -59,7 +59,7 @@ public class OrgAuthorityClientUtils { public static String getAuthorityRefName(String csid, OrgAuthorityClient client){ if(client==null) client = new OrgAuthorityClient(); - ClientResponse res = client.read(csid); + Response res = client.read(csid); try { int statusCode = res.getStatus(); if(!READ_REQ.isValidStatusCode(statusCode) @@ -68,7 +68,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()); OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input, client.getCommonPartName(), OrgauthoritiesCommon.class); @@ -80,7 +80,7 @@ public class OrgAuthorityClientUtils { throw new RuntimeException(e); } } finally { - res.releaseConnection(); + res.close(); } } @@ -176,7 +176,7 @@ public class OrgAuthorityClientUtils { createOrganizationInstance(orgAuthorityRefName, orgInfo, terms, orgRepeatablesInfo, client.getItemCommonPartName()); - ClientResponse res = client.createItem(inAuthority, multipart); + Response res = client.createItem(inAuthority, multipart); String result; try { int statusCode = res.getStatus(); @@ -193,7 +193,7 @@ public class OrgAuthorityClientUtils { result = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return result; @@ -319,7 +319,7 @@ public class OrgAuthorityClientUtils { * @param res the res * @return the string */ - 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/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 9b3b6275f..36d395fc3 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 @@ -269,7 +269,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest res = personAuthClient.createItem(personAuthCSID, multipart); + Response res = personAuthClient.createItem(personAuthCSID, multipart); try { int statusCode = res.getStatus(); @@ -278,7 +278,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest res = - client.deleteItem(parentResourceId, itemResourceId); - res.releaseConnection(); + client.deleteItem(parentResourceId, itemResourceId).close(); } // Clean up parent resources. super.cleanUp(); diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index 23c963b70..da32fafc7 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -68,7 +68,7 @@ public class PersonAuthorityClientUtils { if (client == null) { client = new PersonAuthorityClient(); } - ClientResponse res = client.read(csid); + Response res = client.read(csid); try { int statusCode = res.getStatus(); if(!READ_REQ.isValidStatusCode(statusCode) @@ -77,7 +77,7 @@ public class PersonAuthorityClientUtils { } //FIXME: remove the following try catch once Aron fixes signatures try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input, client.getCommonPartName(), PersonauthoritiesCommon.class); @@ -89,7 +89,7 @@ public class PersonAuthorityClientUtils { throw new RuntimeException(e); } } finally { - res.releaseConnection(); + res.close(); } } @@ -102,7 +102,7 @@ public class PersonAuthorityClientUtils { if ( client == null) { client = new PersonAuthorityClient(); } - ClientResponse res = client.readItem(inAuthority, csid); + Response res = client.readItem(inAuthority, csid); try { int statusCode = res.getStatus(); if(!READ_REQ.isValidStatusCode(statusCode) @@ -111,7 +111,7 @@ public class PersonAuthorityClientUtils { } //FIXME: remove the following try catch once Aron fixes signatures try { - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity()); PersonsCommon person = (PersonsCommon) CollectionSpaceClientUtils.extractPart(input, client.getItemCommonPartName(), PersonsCommon.class); @@ -123,7 +123,7 @@ public class PersonAuthorityClientUtils { throw new RuntimeException(e); } } finally { - res.releaseConnection(); + res.close(); } } @@ -306,7 +306,7 @@ public class PersonAuthorityClientUtils { personMap, terms, personRepeatablesMap, client.getItemCommonPartName()); String result = null; - ClientResponse res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); try { int statusCode = res.getStatus(); @@ -322,7 +322,7 @@ public class PersonAuthorityClientUtils { result = extractId(res); } finally { - res.releaseConnection(); + res.close(); } return result; 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 5d0013f6d..85dae979c 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 @@ -518,14 +518,13 @@ public class PersonAuthoritySearchTest extends BaseServiceTest res = - client.deleteItem(parentResourceId, itemResourceId); - res.releaseConnection(); + Response res = client.deleteItem(parentResourceId, itemResourceId); + res.close(); } // Clean up authority resources. for (String resourceId : allResourceIdsCreated) { // Note: Any non-success responses are ignored and not reported. - client.delete(resourceId).releaseConnection(); + client.delete(resourceId).close(); } } @@ -651,12 +650,12 @@ public class PersonAuthoritySearchTest extends BaseServiceTest res = client.createItem(authorityCsid, multipart); + Response res = client.createItem(authorityCsid, multipart); try { newID = PersonAuthorityClientUtils.extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } 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 217e1722e..c3927d4a8 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 @@ -219,13 +219,13 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest res = client.createItem(authId, multipart); + Response res = client.createItem(authId, multipart); try { assertStatusCode(res, "createItem"); newID = PersonAuthorityClientUtils.extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -348,9 +348,9 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest res = client.createItem(vcsid, multipart); + Response res = client.createItem(vcsid, multipart); String newID = null; try { assertStatusCode(res, testName); newID = PersonAuthorityClientUtils.extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -444,14 +444,14 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.createItem(knownResourceId, multipart); + Response res = client.createItem(knownResourceId, multipart); // Check the status code of the response: does it match // the expected response(s)? try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -517,7 +517,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = null; + Response res = null; setupRead(); if (CSID != null) { res = client.read(CSID); @@ -530,7 +530,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = null; + Response res = null; if (authCSID != null) { if (itemCSID != null) { res = client.readItem(authCSID, itemCSID); @@ -613,10 +613,11 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); 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(); } } // @@ -692,7 +693,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.read(knownResourceId); + Response res = client.read(knownResourceId); try { assertStatusCode(res, testName); if (logger.isDebugEnabled()) { logger.debug("got PersonAuthority to update with ID: " + knownResourceId); } - input = new PoxPayloadIn(res.getEntity()); + input = new PoxPayloadIn((String)res.getEntity()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -951,10 +952,10 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = - client.readItem(knownResourceId, knownItemResourceId); + Response res = client.readItem(knownResourceId, knownItemResourceId); try { assertStatusCode(res, testName); if (logger.isDebugEnabled()) { @@ -992,10 +992,10 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.deleteContact(parentResourceId, itemResourceId, contactResourceId); - res.releaseConnection(); + res.close(); } // Clean up item resources. for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { @@ -1299,9 +1299,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest res = - client.deleteItem(parentResourceId, itemResourceId); - res.releaseConnection(); + client.deleteItem(parentResourceId, itemResourceId).close(); } // Clean up parent resources. super.cleanUp(); 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 503e44431..b18f51295 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 @@ -348,13 +348,13 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { int statusCode = res.getStatus(); @@ -483,7 +483,7 @@ public class PublicItemServiceTest extends Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -506,7 +506,7 @@ public class PublicItemServiceTest extends // Submit the request to the service and store the response. PublicItemClient client = new PublicItemClient(); - ClientResponse res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -520,7 +520,7 @@ public class PublicItemServiceTest extends Assert.assertEquals(statusCode, testExpectedStatusCode); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } 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 c5f4e40ca..70ff0320d 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 @@ -381,22 +381,31 @@ public class AuthenticationServiceTest extends BaseServiceTest res = accountClient.delete(barneyAccountId); - int statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": barney status = " + statusCode); + + Response res = accountClient.delete(barneyAccountId); + int statusCode; + try { + statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": barney status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - + res = accountClient.delete(georgeAccountId); - statusCode = res.getStatus(); - if (logger.isDebugEnabled()) { - logger.debug(testName + ": george status = " + statusCode); + try { + statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": george status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + } finally { + res.close(); } - Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), - invalidStatusCodeMessage(testRequestType, statusCode)); - 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 2d9bb5981..6ec64ffc6 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 @@ -513,12 +513,12 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -532,12 +532,12 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -675,12 +675,12 @@ public class AuthorizationServiceTest extends BaseServiceTest res = permClient.delete(permId); + Response res = permClient.delete(permId); try { assertStatusCode(res, "DeletePermission"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -699,7 +699,7 @@ public class AuthorizationServiceTest extends BaseServiceTest res = roleClient.delete(roleId); + Response res = roleClient.delete(roleId); try { assertStatusCode(res, "DeleteRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -733,7 +733,7 @@ public class AuthorizationServiceTest extends BaseServiceTest res = accClient.delete(accId); + Response res = accClient.delete(accId); try { assertStatusCode(res, "DeleteAccount"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -768,7 +768,7 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.delete(av.getAccountId()); + Response res = client.delete(av.getAccountId()); try { assertStatusCode(res, "DeleteAccountRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -809,7 +809,7 @@ public class AuthorizationServiceTest extends BaseServiceTest res = client.delete(pv.getPermissionId()); + Response res = client.delete(pv.getPermissionId()); try { assertStatusCode(res, "DeletePermissionRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } diff --git a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java index 56a4cd762..f962371a4 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java @@ -447,12 +447,12 @@ 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.delete(id); + Response res = client.delete(id); try { result = assertStatusCode(res, testName); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -473,7 +473,7 @@ public class MultiTenancyTest extends BaseServiceTest { DimensionClient client = new DimensionClient(); //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1 client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true); - ClientResponse res = client.delete(TENANT_RESOURCE_1); + Response res = client.delete(TENANT_RESOURCE_1); try { int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -488,7 +488,7 @@ public class MultiTenancyTest extends BaseServiceTest { Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode()); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -590,12 +590,12 @@ public class MultiTenancyTest extends BaseServiceTest { PermissionClient permClient = new PermissionClient(); UserInfo ui = tenantAdminUsers.get(tenantId); permClient.setAuth(true, ui.userName, true, ui.password, true); - ClientResponse res = permClient.delete(permId); + Response res = permClient.delete(permId); try { assertStatusCode(res, "DeletePermission"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -617,7 +617,7 @@ public class MultiTenancyTest extends BaseServiceTest { result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -629,12 +629,12 @@ public class MultiTenancyTest extends BaseServiceTest { RoleClient roleClient = new RoleClient(); UserInfo ui = tenantAdminUsers.get(tenantId); roleClient.setAuth(true, ui.userName, true, ui.password, true); - ClientResponse res = roleClient.delete(roleId); + Response res = roleClient.delete(roleId); try { assertStatusCode(res, "DeleteRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -655,7 +655,7 @@ public class MultiTenancyTest extends BaseServiceTest { result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -667,12 +667,12 @@ public class MultiTenancyTest extends BaseServiceTest { AccountClient accClient = new AccountClient(); UserInfo ui = tenantAdminUsers.get(tenantId); accClient.setAuth(true, ui.userName, true, ui.password, true); - ClientResponse res = accClient.delete(accId); + Response res = accClient.delete(accId); try { assertStatusCode(res, "DeleteAccount"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -694,7 +694,7 @@ public class MultiTenancyTest extends BaseServiceTest { result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -712,12 +712,12 @@ public class MultiTenancyTest extends BaseServiceTest { client.setAuth(true, ui.userName, true, ui.password, true); AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( av, rvs, true, true); - ClientResponse res = client.delete(av.getAccountId()); + Response res = client.delete(av.getAccountId()); try { assertStatusCode(res, "DeleteAccountRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } @@ -740,7 +740,7 @@ public class MultiTenancyTest extends BaseServiceTest { result = extractId(res); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } @@ -757,12 +757,12 @@ public class MultiTenancyTest extends BaseServiceTest { client.setAuth(true, ui.userName, true, ui.password, true); PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( pv, rvls, true, true); - ClientResponse res = client.delete(pv.getPermissionId()); + Response res = client.delete(pv.getPermissionId()); try { assertStatusCode(res, "DeletePermissionRole"); } finally { if (res != null) { - res.releaseConnection(); + res.close(); } } } 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 8dda0d307..d04c3c3a8 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 @@ -209,7 +209,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest items = - list.getListItem(); + List items = list.getListItem(); int nItemsReturned = items.size(); // There will be 'nItemsToCreateInList' // items created by the createItemList test, @@ -313,7 +312,7 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest res = - client.deleteItem(parentResourceId, itemResourceId); - res.releaseConnection(); + client.deleteItem(parentResourceId, itemResourceId).close(); } + // Clean up parent resources. for (String resourceId : allResourceIdsCreated) { // Note: Any non-success responses from the delete operation // below are ignored and not reported. - ClientResponse res = client.delete(resourceId); - res.releaseConnection(); + client.delete(resourceId).close(); } } @@ -438,10 +435,8 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.delete(knownResourceId); + Response res = client.delete(knownResourceId); try { int statusCode = res.getStatus(); @@ -538,7 +538,7 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl res = client.delete(NON_EXISTENT_ID); + Response res = client.delete(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -571,7 +571,7 @@ public class ValuationcontrolServiceTest extends AbstractPoxServiceTestImpl