From 8d898b2c712f6069d4363dcb194ba220c47a52f2 Mon Sep 17 00:00:00 2001 From: remillet Date: Wed, 8 Jun 2016 16:13:03 -0700 Subject: [PATCH] CSPACE-6959: Refactored client code to deal better with init exceptions. --- .../test/CollectionSpaceIntegrationTest.java | 8 +- .../test/RelationIntegrationTest.java | 29 +- .../PerformanceTests/test/I1591Multiple.java | 25 +- .../PerformanceTests/test/I1591OneInst.java | 22 +- .../test/I1591OneInstOneClose.java | 18 +- .../test/PerformanceTest.java | 27 +- .../services/client/AccountClient.java | 8 +- .../services/client/AccountRoleClient.java | 6 +- .../services/client/TenantClient.java | 7 +- .../client/test/AccountRoleServiceTest.java | 27 +- .../client/test/AccountServiceTest.java | 11 +- .../services/client/AcquisitionClient.java | 4 +- .../client/test/AcquisitionAuthRefsTest.java | 9 +- .../client/test/AcquisitionServiceTest.java | 10 +- .../vocabulary/AuthorityJAXBSchema.java | 1 + .../vocabulary/AuthorityServiceUtils.java | 83 +- .../nuxeo/AuthorityDocumentModelHandler.java | 21 +- .../AuthorityItemDocumentModelHandler.java | 15 +- .../services/client/PermissionClient.java | 4 +- .../services/client/PermissionRoleClient.java | 4 +- .../services/client/RoleClient.java | 8 +- .../services/client/RolePermissionClient.java | 4 +- .../test/PermissionRoleServiceTest.java | 25 +- .../client/test/PermissionServiceTest.java | 7 +- .../test/RolePermissionServiceTest.java | 25 +- .../client/test/RoleServiceTest.java | 6 +- .../services/client/BatchClient.java | 4 +- .../client/test/BatchServiceTest.java | 14 +- .../services/client/BlobClient.java | 4 +- .../client/test/BlobAuthRefsTest.java | 10 +- .../services/client/test/BlobScaleTest.java | 9 +- .../services/client/test/BlobServiceTest.java | 13 +- .../client/CitationAuthorityClient.java | 4 +- .../test/CitationAuthorityServiceTest.java | 14 +- ...bstractCommonListPoxServiceClientImpl.java | 4 +- .../client/AbstractPoxServiceClientImpl.java | 4 +- .../client/AbstractServiceClientImpl.java | 136 +- .../services/client/AuthorityClientImpl.java | 4 +- .../client/CollectionSpaceClient.java | 18 +- .../client/GenericAuthorityClientImpl.java | 4 + .../services/client/RelationClient.java | 4 +- .../services/client/TestServiceClient.java | 6 +- .../services/client/index/IndexClient.java | 5 + .../test/AbstractAuthorityServiceTest.java | 41 +- .../test/AbstractPoxServiceTestImpl.java | 2 +- .../client/test/AbstractServiceTestImpl.java | 26 +- .../services/client/test/BaseServiceTest.java | 60 +- .../client/workflow/WorkflowClient.java | 6 +- .../sas-collectionspace-client.properties | 8 +- .../client/CollectionObjectClient.java | 4 +- .../test/CollectionObjectAuthRefsTest.java | 28 +- .../test/CollectionObjectSearchTest.java | 41 +- .../test/CollectionObjectServiceTest.java | 27 +- .../services/common/api/Tools.java | 95 ++ .../client/test/ServiceLayerTest.java | 11 +- .../context/AbstractServiceContextImpl.java | 36 +- .../common/context/ServiceContext.java | 3 + .../document/AbstractDocumentHandlerImpl.java | 3 - .../nuxeo/client/java/TenantRepository.java | 5 + .../client/ConceptAuthorityClient.java | 4 +- .../test/ConceptAuthorityServiceTest.java | 13 +- .../services/client/ConditioncheckClient.java | 4 +- .../test/ConditioncheckAuthRefsTest.java | 10 +- .../test/ConditioncheckServiceTest.java | 12 +- .../config/src/main/resources/instance1.xml | 323 ++++ .../config/src/main/resources/service.xsd | 1 + services/config/src/main/resources/tenant.xsd | 28 +- .../services/client/ConservationClient.java | 4 +- .../client/test/ConservationAuthRefsTest.java | 10 +- .../client/test/ConservationServiceTest.java | 12 +- .../AuthorityWithContactsClientImpl.java | 7 +- .../services/client/ContactClient.java | 4 +- .../client/test/ContactServiceTest.java | 7 +- .../services/client/DimensionClient.java | 4 +- .../client/test/DimensionServiceTest.java | 7 +- .../services/client/ExhibitionClient.java | 4 +- .../client/test/ExhibitionServiceTest.java | 12 +- .../services/client/GroupClient.java | 4 +- .../client/test/GroupServiceTest.java | 11 +- .../services/client/IdClient.java | 4 +- .../services/id/IdServiceTest.java | 8 +- .../services/client/IntakeClient.java | 4 +- .../client/test/IntakeAuthRefsTest.java | 10 +- .../client/test/IntakeServiceTest.java | 13 +- .../test/OrganizationAuthRefDocsTest.java | 11 +- .../client/test/PersonAuthRefDocsTest.java | 11 +- .../services/client/LoaninClient.java | 4 +- .../client/test/LoaninAuthRefsTest.java | 10 +- .../client/test/LoaninServiceTest.java | 15 +- .../services/client/LoanoutClient.java | 4 +- .../client/test/LoanoutAuthRefsTest.java | 10 +- .../client/test/LoanoutServiceTest.java | 15 +- .../client/LocationAuthorityClient.java | 4 +- .../test/LocationAuthorityServiceTest.java | 10 +- .../client/MaterialAuthorityClient.java | 4 +- .../test/MaterialAuthorityServiceTest.java | 68 +- .../services/client/MediaClient.java | 5 +- .../client/test/MediaAuthRefsTest.java | 10 +- .../client/test/MediaServiceTest.java | 11 +- .../services/media/MediaResource.java | 20 +- .../services/client/MovementClient.java | 6 +- .../client/test/MovementAuthRefsTest.java | 10 +- .../client/test/MovementServiceTest.java | 11 +- .../client/test/MovementSortByTest.java | 6 +- .../services/client/ObjectExitClient.java | 4 +- .../client/test/ObjectExitAuthRefsTest.java | 10 +- .../client/test/ObjectExitServiceTest.java | 11 +- .../services/client/OrgAuthorityClient.java | 4 +- .../client/OrgAuthorityClientUtils.java | 9 +- .../client/test/OrgAuthorityAuthRefsTest.java | 10 +- .../client/test/OrgAuthorityServiceTest.java | 41 +- .../client/PersonAuthorityClient.java | 4 +- .../client/PersonAuthorityClientUtils.java | 7 +- .../test/PersonAuthoritySearchTest.java | 41 +- .../test/PersonAuthorityServicePerfTest.java | 14 +- .../test/PersonAuthorityServiceTest.java | 43 +- .../services/client/PlaceAuthorityClient.java | 4 +- .../test/PlaceAuthorityServiceTest.java | 8 +- .../services/client/PublicItemClient.java | 4 +- .../client/test/PublicItemServiceTest.java | 15 +- .../client/test/RelationServiceTest.java | 19 +- .../services/client/ReportClient.java | 4 +- .../client/test/ReportServiceTest.java | 15 +- .../test/AuthenticationServiceTest.java | 44 +- .../client/test/AuthorizationServiceTest.java | 1489 ++++++++--------- .../client/test/MultiTenancyTest.java | 56 +- .../services/client/ServiceGroupClient.java | 4 +- .../client/test/ServiceGroupServiceTest.java | 5 +- .../client/TaxonomyAuthorityClient.java | 4 +- .../test/TaxonomyAuthorityServiceTest.java | 8 +- .../client/ValuationcontrolClient.java | 4 +- .../test/ValuationcontrolServiceTest.java | 12 +- .../services/client/VocabularyClient.java | 4 +- .../client/test/VocabularyServiceTest.java | 10 +- .../services/client/WorkAuthorityClient.java | 4 +- .../client/test/WorkAuthorityServiceTest.java | 8 +- .../client/test/WorkflowServiceTest.java | 8 +- 137 files changed, 2203 insertions(+), 1556 deletions(-) create mode 100644 services/config/src/main/resources/instance1.xml diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java index 534cae94d..1fa2515c7 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java @@ -142,8 +142,8 @@ public abstract class CollectionSpaceIntegrationTest { String extractId(Response res) { String result = null; - MultivaluedMap mvm = res.getMetadata(); - String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); verbose("extractId:uri=" + uri); String[] segments = uri.split("/"); result = segments[segments.length - 1]; @@ -167,13 +167,13 @@ public abstract class CollectionSpaceIntegrationTest { * @throws Exception * the exception */ - static Object extractPart(PoxPayloadIn input, String label, Class clazz) { + static Object extractPart(PoxPayloadIn input, String label) { Object obj = null; PayloadInputPart payloadInputPart = input.getPart(label); if (payloadInputPart != null) { obj = payloadInputPart.getBody(); - } + } return obj; } diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java index aec72528c..6c174f5db 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java @@ -65,13 +65,19 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { // // Get clients for the CollectionSpace services // - private CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - private RelationClient relationClient = new RelationClient(); - private IntakeClient intakeClient = new IntakeClient(); - private DimensionClient dimensionClient = new DimensionClient(); + private CollectionObjectClient collectionObjectClient; + private RelationClient relationClient; + private IntakeClient intakeClient; + private DimensionClient dimensionClient; private static final int OBJECTS_TO_INTAKE = 1; + public RelationIntegrationTest() throws Exception { + collectionObjectClient = new CollectionObjectClient(); + relationClient = new RelationClient(); + intakeClient = new IntakeClient(); + dimensionClient = new DimensionClient(); + } @AfterClass(alwaysRun = true) public void cleanUp() { @@ -119,7 +125,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { return multipart; } - protected PoxPayloadOut createDimensionInstance(String identifier) { + protected PoxPayloadOut createDimensionInstance(String identifier) throws Exception { DimensionClient client = new DimensionClient(); return createDimensionInstance(client.getCommonPartName(), identifier); } @@ -139,7 +145,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { "entryDate-" + identifier); } - @Test void deleteCollectionObjectRelationshipToLockedDimension() { + @Test void deleteCollectionObjectRelationshipToLockedDimension() throws Exception { // First create a CollectionObject CollectionobjectsCommon co = new CollectionobjectsCommon(); fillCollectionObject(co, createIdentifier()); @@ -225,7 +231,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { } } - @Test void createCollectionObjectRelationshipToManyDimensions() { + @Test void createCollectionObjectRelationshipToManyDimensions() throws Exception { // // First create a CollectionObject // @@ -358,7 +364,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { } } - @Test void releteCollectionObjectToLockedDimension() { + @Test void releteCollectionObjectToLockedDimension() throws Exception { // // First create a CollectionObject // @@ -532,8 +538,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.readEntity(String.class)); resultRelation = (RelationsCommon) extractPart(input, - relationClient.getCommonPartName(), - RelationsCommon.class); + relationClient.getCommonPartName()); } catch (Exception e) { e.printStackTrace(); } finally { @@ -663,9 +668,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { int responseStatus = multiPartResponse.getStatus(); Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode()); PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.readEntity(String.class)); - resultRelation = (RelationsCommon) extractPart(input, - relationClient.getCommonPartName(), - RelationsCommon.class); + resultRelation = (RelationsCommon) extractPart(input, relationClient.getCommonPartName()); } catch (Exception e) { e.printStackTrace(); } finally { 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 bbc28b2d7..669ada3ed 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 @@ -28,14 +28,8 @@ import javax.ws.rs.core.Response; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; - import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; @@ -53,17 +47,20 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommon; public class I1591Multiple extends CollectionSpacePerformanceTest { final Logger logger = LoggerFactory.getLogger(I1591Multiple.class); - private final String COLLECTION_OBJECT_COMMON_PART_NAME = - getCollectionObjectCommonPartName(); private static int MAX_RECORDS = 500; String[] coList = new String[MAX_RECORDS]; + private String COLLECTION_OBJECT_COMMON_PART_NAME; + + public I1591Multiple() throws Exception { + COLLECTION_OBJECT_COMMON_PART_NAME = getCollectionObjectCommonPartName(); + } - private String getCollectionObjectCommonPartName() { + private String getCollectionObjectCommonPartName() throws Exception { return new CollectionObjectClient().getCommonPartName(); } @Test - public void testCreateWithMultipleClientInstantiations() { + public void testCreateWithMultipleClientInstantiations() throws Exception { coList = this.createCollectionObjects(MAX_RECORDS); } @@ -75,8 +72,9 @@ public class I1591Multiple extends CollectionSpacePerformanceTest { * @param identifier A arbitrary identifier to use when filling * the CollectionObject's fields with values. * @return A resource ID for the newly-created object. + * @throws Exception */ - private String createCollectionObject(long identifier) throws AssertionError { + private String createCollectionObject(long identifier) throws AssertionError, Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String resourceId = null; @@ -111,8 +109,9 @@ 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. + * @throws Exception */ - public String[] createCollectionObjects(int numberOfObjects) { + public String[] createCollectionObjects(int numberOfObjects) throws Exception { long identifier = 0; int i = 0; @@ -136,7 +135,7 @@ public class I1591Multiple extends CollectionSpacePerformanceTest { } @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String resourceId = ""; 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 99478a813..e0f6238f7 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 @@ -28,14 +28,9 @@ import javax.ws.rs.core.Response; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; - import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; @@ -54,17 +49,11 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommon; public class I1591OneInst extends CollectionSpacePerformanceTest { final Logger logger = LoggerFactory.getLogger(I1591OneInst.class); - private final String COLLECTION_OBJECT_COMMON_PART_NAME = - getCollectionObjectCommonPartName(); private static int MAX_RECORDS = 500; String[] coList = new String[MAX_RECORDS]; - - private String getCollectionObjectCommonPartName() { - return new CollectionObjectClient().getCommonPartName(); - } - + @Test - public void testCreateWithSingleClientInstantiation() { + public void testCreateWithSingleClientInstantiation() throws Exception { createCollectionObjects(MAX_RECORDS); } @@ -72,13 +61,12 @@ public class I1591OneInst extends CollectionSpacePerformanceTest { * Creates multiple CollectionObject resources. * * @param numberOfObjects The number of CollectionObject resources to create. + * @throws Exception */ - public void createCollectionObjects(int numberOfObjects) { - + public void createCollectionObjects(int numberOfObjects) throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); long identifier = 0; - for (int i = 0; i <= numberOfObjects; i++) { // Create a CollectionObject instance. @@ -117,7 +105,7 @@ public class I1591OneInst extends CollectionSpacePerformanceTest { } @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String resourceId = ""; 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 6bd225505..b48684b18 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 @@ -28,14 +28,9 @@ import javax.ws.rs.core.Response; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; - import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; @@ -54,17 +49,11 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommon; public class I1591OneInstOneClose extends CollectionSpacePerformanceTest { final Logger logger = LoggerFactory.getLogger(I1591OneInstOneClose.class); - private final String COLLECTION_OBJECT_COMMON_PART_NAME = - getCollectionObjectCommonPartName(); private static int MAX_RECORDS = 500; String[] coList = new String[MAX_RECORDS]; - private String getCollectionObjectCommonPartName() { - return new CollectionObjectClient().getCommonPartName(); - } - @Test - public void testCreateWithSingleClientInstantiationAndOneClose() { + public void testCreateWithSingleClientInstantiationAndOneClose() throws Exception { createCollectionObjects(MAX_RECORDS); } @@ -72,8 +61,9 @@ public class I1591OneInstOneClose extends CollectionSpacePerformanceTest { * Creates multiple CollectionObject resources. * * @param numberOfObjects The number of CollectionObject resources to create. + * @throws Exception */ - public void createCollectionObjects(int numberOfObjects) { + public void createCollectionObjects(int numberOfObjects) throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); long identifier = 0; @@ -113,7 +103,7 @@ public class I1591OneInstOneClose extends CollectionSpacePerformanceTest { } @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String resourceId = ""; 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 387ce3f4b..300dac9da 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 @@ -28,13 +28,12 @@ import java.util.Random; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.jboss.resteasy.util.HttpResponseCodes; +import org.jboss.resteasy.util.HttpResponseCodes; import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; @@ -63,9 +62,10 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { /** * Performance test. + * @throws Exception */ @Test - public void performanceTest() { + public void performanceTest() throws Exception { roundTripOverhead(10); deleteCollectionObjects(); String[] coList = this.createCollectionObjects(MAX_RECORDS); @@ -80,8 +80,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * * @param numOfCalls the num of calls * @return the long + * @throws Exception */ - private long roundTripOverhead(int numOfCalls) { + private long roundTripOverhead(int numOfCalls) throws Exception { long result = 0; CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); @@ -112,8 +113,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * Search collection objects. * * @param numberOfObjects the number of objects + * @throws Exception */ - private void searchCollectionObjects(int numberOfObjects) { + private void searchCollectionObjects(int numberOfObjects) throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Random randomGenerator = new Random(System.currentTimeMillis()); Response searchResultsResponse; @@ -197,8 +199,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * * @param numberOfObjects the number of objects * @return the string[] + * @throws Exception */ - public String[] createCollectionObjects(int numberOfObjects) { + public String[] createCollectionObjects(int numberOfObjects) throws Exception { Random randomGenerator = new Random(System.currentTimeMillis()); CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); String[] coList = new String[numberOfObjects]; @@ -260,8 +263,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * Delete collection objects. * * @param arrayOfObjects the array of objects + * @throws Exception */ - public void readCollectionObjects(String[] arrayOfObjects) { + public void readCollectionObjects(String[] arrayOfObjects) throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Date startTime = new Date(); @@ -279,8 +283,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { /** * Delete collection objects. * FIXME: Deletes a page at a time until there are no more CollectionObjects. + * @throws Exception */ - public void readCollectionObjects() { + public void readCollectionObjects() throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); List coListItems = null; @@ -326,8 +331,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { * Delete collection objects. * * @param arrayOfObjects the array of objects + * @throws Exception */ - private void deleteCollectionObjects(String[] arrayOfObjects) { + private void deleteCollectionObjects(String[] arrayOfObjects) throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); Date startTime = new Date(); @@ -345,8 +351,9 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { /** * Delete collection objects. * FIXME: Deletes a page at a time until there are no more CollectionObjects. + * @throws Exception */ - private void deleteCollectionObjects() { + private void deleteCollectionObjects() throws Exception { CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); List coListItems = null; diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java index b94982bb7..7efb2f600 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountClient.java @@ -27,8 +27,8 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; -import org.apache.http.HttpStatus; +import org.apache.http.HttpStatus; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.AccountsCommonList; import org.collectionspace.services.description.ServiceDescription; @@ -45,11 +45,11 @@ public class AccountClient extends AbstractServiceClientImpl { public static final String SERVICE_NAME = "accountroles"; - public AccountRoleClient() { + public AccountRoleClient() throws Exception { super(); } - public AccountRoleClient(String clientPropertiesFilename) { + public AccountRoleClient(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/TenantClient.java b/services/account/client/src/main/java/org/collectionspace/services/client/TenantClient.java index 1dcee1967..b50b2af91 100644 --- a/services/account/client/src/main/java/org/collectionspace/services/client/TenantClient.java +++ b/services/account/client/src/main/java/org/collectionspace/services/client/TenantClient.java @@ -40,7 +40,12 @@ import org.collectionspace.services.description.ServiceDescription; */ public class TenantClient extends AbstractServiceClientImpl { - public static final String SERVICE_NAME = "tenants"; + + public TenantClient() throws Exception { + super(); + } + + public static final String SERVICE_NAME = "tenants"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; 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 aead4d2c9..2fba8111e 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 @@ -81,7 +81,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl acquisitionIdsCreated.add(extractId(res)); } - protected void createPersonRefs(){ + protected void createPersonRefs() throws Exception{ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); @@ -199,7 +199,7 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest personIdsCreated.add(csid); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) throws Exception { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); @@ -337,9 +337,10 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -384,7 +385,7 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest String acquisitionAuthorizer, List acquisitionFundingSources, List acqOwners, - List acquisitionSources) { + List acquisitionSources) throws Exception { AcquisitionsCommon acquisition = new AcquisitionsCommon(); StructuredDateGroup accessionDateGroup = new StructuredDateGroup(); 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 c6012e830..fd0b6b523 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 @@ -40,7 +40,6 @@ import org.collectionspace.services.acquisition.AcquisitionDateGroupList; import org.collectionspace.services.acquisition.AcquisitionSourceList; import org.collectionspace.services.acquisition.OwnerList; import org.collectionspace.services.acquisition.StructuredDateGroup; - import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -77,12 +76,12 @@ public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl remoteClientConfigList = remoteClientConfigurations.getRemoteClientConfig(); + for (RemoteClientConfig config : remoteClientConfigList) { + if (config.getName().equalsIgnoreCase(remoteClientConfigName)) { + result = config; + break; + } + } + } else { + String errMsg = String.format("No remote client configurations could be found in the tenant bindings for tenant named '%s'.", + ctx.getTenantName()); + logger.error(errMsg); + throw new Exception(errMsg); + } + + if (result == null) { + String errMsg = String.format("Could not find a remote client configuration named '%s' in the tenant bindings for tenant named '%s'", + remoteClientConfigName, ctx.getTenantName()); + logger.error(errMsg); + throw new Exception(errMsg); + } + + return result; + } + /** * Make a request to the SAS Server for an authority payload. * @@ -53,10 +112,12 @@ public class AuthorityServiceUtils { * @return * @throws Exception */ - static public PoxPayloadIn requestPayloadIn(ServiceContext ctx, Specifier specifier, Class responseType) throws Exception { + static public PoxPayloadIn requestPayloadInFromRemoteServer(ServiceContext ctx, String remoteClientConfigName, Specifier specifier, Class responseType) throws Exception { PoxPayloadIn result = null; - AuthorityClient client = (AuthorityClient) ctx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); + RemoteClientConfig remoteClientConfig = getRemoteClientConfig(ctx, remoteClientConfigName); + AuthorityClient client = (AuthorityClient) ctx.getClient(remoteClientConfig); + Response res = client.read(specifier.getURNValue()); try { int statusCode = res.getStatus(); @@ -76,13 +137,19 @@ public class AuthorityServiceUtils { } // - // Makes a call to the SAS server for a authority item payload + // Makes a call to the remote SAS server for a authority item payload // - static public PoxPayloadIn requestPayloadIn(AuthorityItemSpecifier specifier, String serviceName, Class responseType, boolean syncHierarchicalRelationships) throws Exception { + static public PoxPayloadIn requestPayloadInFromRemoteServer( + AuthorityItemSpecifier specifier, + String remoteClientConfigName, + String serviceName, + Class responseType, + boolean syncHierarchicalRelationships) throws Exception { PoxPayloadIn result = null; - ServiceContext parentCtx = new MultipartServiceContextImpl(serviceName); - AuthorityClient client = (AuthorityClient) parentCtx.getClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); + ServiceContext authorityCtx = new MultipartServiceContextImpl(serviceName); + RemoteClientConfig remoteClientConfig = getRemoteClientConfig(authorityCtx, remoteClientConfigName); + AuthorityClient client = (AuthorityClient) authorityCtx.getClient(remoteClientConfig); Response res = client.readItem(specifier.getParentSpecifier().getURNValue(), specifier.getItemSpecifier().getURNValue(), AuthorityClient.INCLUDE_DELETED_ITEMS, syncHierarchicalRelationships); diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index f7cf59935..87b6720f4 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -32,24 +32,19 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; -import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadInputPart; -import org.collectionspace.services.client.VocabularyClient; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.XmlTools; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ResourceMap; -import org.collectionspace.services.common.api.CommonAPI; import org.collectionspace.services.common.api.RefName; import org.collectionspace.services.common.api.RefName.Authority; import org.collectionspace.services.common.api.RefNameUtils; -import org.collectionspace.services.common.api.RefNameUtils.AuthorityInfo; import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentException; -import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentReferenceException; import org.collectionspace.services.common.document.DocumentWrapper; @@ -68,7 +63,7 @@ import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; -import org.dom4j.Document; + import org.dom4j.Element; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -81,6 +76,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ +@SuppressWarnings("rawtypes") public abstract class AuthorityDocumentModelHandler extends NuxeoDocumentModelHandler { @@ -125,7 +121,7 @@ public abstract class AuthorityDocumentModelHandler return payloadInputPart; } - @Override + @Override public boolean handleSync(DocumentWrapper wrapDoc) throws Exception { boolean result = false; ServiceContext ctx = getServiceContext(); @@ -137,11 +133,12 @@ public abstract class AuthorityDocumentModelHandler if (docModel != null) { Long localRev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV); String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); + String remoteClientConfigName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REMOTECLIENT_CONFIG_NAME); // If set, contains the name of the remote client configuration (remoteClientConfigName) from the tenant bindings // // Using the short ID of the local authority, create a URN specifier to retrieve the SAS authority // Specifier sasSpecifier = new Specifier(SpecifierForm.URN_NAME, shortId); - PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(ctx, sasSpecifier, getEntityResponseType()); + PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadInFromRemoteServer(ctx, remoteClientConfigName, sasSpecifier, getEntityResponseType()); // // If the authority on the SAS is newer, synch all the items and then the authority record as well // @@ -261,7 +258,6 @@ public abstract class AuthorityDocumentModelHandler * @return * @throws Exception */ - @SuppressWarnings("rawtypes") private long deleteOrDeprecateItems(ServiceContext ctx, Specifier authoritySpecifier, ArrayList itemShortIdList) throws Exception { long result = 0; AuthorityItemSpecifier authorityItemSpecificer = null; @@ -362,9 +358,14 @@ public abstract class AuthorityDocumentModelHandler Specifier itemSpecifier = Specifier.getSpecifier(itemIdentifier); AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(authoritySpecifier, itemSpecifier); // + // Get the remote client configuration name + // + DocumentModel docModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, authoritySpecifier); + String remoteClientConfigName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REMOTECLIENT_CONFIG_NAME); // If set, contains the name of the remote client configuration (remoteClientConfigName) from the tenant bindings + // // Get the remote payload // - PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(sasAuthorityItemSpecifier, + PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadInFromRemoteServer(sasAuthorityItemSpecifier, remoteClientConfigName, ctx.getServiceName(), getEntityResponseType(), syncHierarchicalRelationships); sasPayloadIn = AuthorityServiceUtils.filterRefnameDomains(ctx, sasPayloadIn); // We need to filter domain name part of any and all refnames in the payload // diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 7f816c54c..2d6f74a3c 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -451,17 +451,16 @@ public abstract class AuthorityItemDocumentModelHandler // DocumentModel authorityDocModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, authorityItemSpecifier.getParentSpecifier()); - String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); + String authorityShortId = (String)NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); String localParentCsid = authorityDocModel.getName(); + String remoteClientConfigName = (String)NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.REMOTECLIENT_CONFIG_NAME); // // Using the short IDs of the local authority and item, create URN specifiers and retrieve the SAS authority item // AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(SpecifierForm.URN_NAME, authorityShortId, itemShortId); // Get the shared authority server's copy - PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(sasAuthorityItemSpecifier, - getAuthorityServicePath(), getEntityResponseType(), AuthorityClient.INCLUDE_RELATIONS); - Long sasRev = getRevision(sasPayloadIn); - String sasWorkflowState = getWorkflowState(sasPayloadIn); + PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadInFromRemoteServer(sasAuthorityItemSpecifier, + remoteClientConfigName, getAuthorityServicePath(), getEntityResponseType(), AuthorityClient.INCLUDE_RELATIONS); // // Get the RelationsCommonList and remove the CSIDs since they are for remote items only. We'll use @@ -556,13 +555,15 @@ public abstract class AuthorityItemDocumentModelHandler authorityItemSpecifier.getParentSpecifier()); String authorityShortId = (String) NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); String localParentCsid = authorityDocModel.getName(); + String remoteClientConfigName = (String)NuxeoUtils.getProperyValue(authorityDocModel, AuthorityJAXBSchema.REMOTECLIENT_CONFIG_NAME); + // // Using the short IDs of the local authority and item, create URN specifiers and retrieve the SAS authority item // AuthorityItemSpecifier sasAuthorityItemSpecifier = new AuthorityItemSpecifier(SpecifierForm.URN_NAME, authorityShortId, itemShortId); // Get the shared authority server's copy - PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(sasAuthorityItemSpecifier, - getAuthorityServicePath(), getEntityResponseType(), AuthorityClient.DONT_INCLUDE_RELATIONS); + PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadInFromRemoteServer(sasAuthorityItemSpecifier, + remoteClientConfigName, getAuthorityServicePath(), getEntityResponseType(), AuthorityClient.DONT_INCLUDE_RELATIONS); Long sasRev = getRevision(sasPayloadIn); String sasWorkflowState = getWorkflowState(sasPayloadIn); // diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java index 61e89d44d..442c23b88 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionClient.java @@ -44,11 +44,11 @@ public class PermissionClient extends AbstractServiceClientImpl { - public PermissionRoleClient() { + public PermissionRoleClient() throws Exception { super(); } - public PermissionRoleClient(String clientPropertiesFilename) { + public PermissionRoleClient(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java index edf0562e5..4a9755b60 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java @@ -32,6 +32,10 @@ import javax.ws.rs.core.Response; + + + + import org.apache.http.HttpStatus; import org.collectionspace.services.authorization.AccountRole; import org.collectionspace.services.authorization.Role; @@ -50,11 +54,11 @@ public class RoleClient extends AbstractServiceClientImpl { - public RolePermissionClient() { + public RolePermissionClient() throws Exception { super(); } - public RolePermissionClient(String clientPropertiesFilename) { + public RolePermissionClient(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } 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 9873aa3f2..b2a81d262 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 @@ -44,7 +44,6 @@ import org.collectionspace.services.client.PermissionRoleFactory; import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; import org.collectionspace.services.client.test.AbstractServiceTestImpl; - import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -82,7 +81,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl actions = PermissionFactory.createDefaultActions(); @@ -600,8 +602,9 @@ public class RolePermissionServiceTest extends AbstractServiceTestImpl { private final String CLASS_NAME = BatchServiceTest.class.getName(); @@ -57,13 +57,13 @@ public class BatchServiceTest extends AbstractPoxServiceTestImpl { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } - private PoxPayloadOut createBlobInstance(String depositorRefName) { + private PoxPayloadOut createBlobInstance(String depositorRefName) throws Exception { BlobClient blobClient = new BlobClient(); this.depositorRefName = depositorRefName; this.blobName = "testblob-"+createIdentifier(); @@ -125,7 +124,7 @@ public class BlobAuthRefsTest extends BaseServiceTest { } } - protected void createPersonRefs() { + protected void createPersonRefs() throws Exception { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); @@ -151,7 +150,7 @@ public class BlobAuthRefsTest extends BaseServiceTest { } } - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -241,9 +240,10 @@ public class BlobAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { logger.debug("Skipping Cleanup phase ..."); diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java index c0caf6b2e..56cefc5aa 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobScaleTest.java @@ -23,6 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.Test; +@SuppressWarnings("rawtypes") public class BlobScaleTest extends BaseServiceTest { private final Logger logger = LoggerFactory.getLogger(BlobScaleTest.class); @@ -40,12 +41,12 @@ public class BlobScaleTest extends BaseServiceTest { private static Random generator = new Random(System.currentTimeMillis()); @Override - protected CollectionSpaceClient getClientInstance() { + protected CollectionSpaceClient getClientInstance() throws Exception { return new BlobClient(); } @Override - protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { return new BlobClient(clientPropertiesFilename); } @@ -79,7 +80,7 @@ public class BlobScaleTest extends BaseServiceTest { } @Test(dataProvider = "testName", dependsOnMethods = {"scaleTest"}) - public void scaleGETTest(String testName) throws MalformedURLException, InterruptedException { + public void scaleGETTest(String testName) throws Exception { this.setupRead(); BlobClient client = new BlobClient(); @@ -100,7 +101,7 @@ public class BlobScaleTest extends BaseServiceTest { } @Test(dataProvider = "testName") - public void scaleTest(String testName) throws MalformedURLException { + public void scaleTest(String testName) throws Exception { this.createDirectory(GENERATED_IMAGES); setupCreate(); int imagesToCreate = getImagesToCreate(); diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java index b767284da..368c3643e 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java @@ -38,12 +38,10 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.blob.BlobsCommon; import org.collectionspace.services.blob.DimensionSubGroup; import org.collectionspace.services.blob.MeasuredPartGroup; - import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; @@ -52,6 +50,7 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart; * $LastChangedRevision: $ * $LastChangedDate: $ */ +@SuppressWarnings("rawtypes") public class BlobServiceTest extends AbstractPoxServiceTestImpl { private final String CLASS_NAME = BlobServiceTest.class.getName(); @@ -82,12 +81,12 @@ public class BlobServiceTest extends AbstractPoxServiceTestImpl { /** @@ -91,12 +91,12 @@ public class CitationAuthorityServiceTest extends AbstractAuthorityServiceTest allResourceIdsCreated = new ArrayList(); - public AbstractPoxServiceClientImpl(String clientPropertiesFilename) { + public AbstractPoxServiceClientImpl(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } - public AbstractPoxServiceClientImpl() { + public AbstractPoxServiceClientImpl() throws Exception { super(); } 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 ad76e11aa..bfb78d319 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 @@ -24,13 +24,11 @@ package org.collectionspace.services.client; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; -import javax.ws.rs.PathParam; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; @@ -40,19 +38,22 @@ import javax.xml.bind.DatatypeConverter; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; -import org.apache.http.impl.client.DefaultHttpClient; -import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.apache.commons.httpclient.auth.AuthScope; + +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext; -import org.jboss.resteasy.client.ProxyFactory; -import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor; + import org.jboss.resteasy.client.jaxrs.ResteasyClient; -//import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; +import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.spi.ResteasyProviderFactory; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// FIXME: Deprecated classes that need to be updated +import org.jboss.resteasy.client.ProxyFactory; +import org.apache.http.impl.client.DefaultHttpClient; + /** * Private class for JAX-RS authentication @@ -104,7 +105,7 @@ public abstract class AbstractServiceClientImpl { /** The logger. */ - protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class); + static protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class); /** * The character used to separate the words in a part label */ @@ -135,7 +136,7 @@ public abstract class AbstractServiceClientImpl { + public GenericAuthorityClientImpl() throws Exception { + super(); + } + @Override public String getItemCommonPartName() { // TODO Auto-generated method stub diff --git a/services/client/src/main/java/org/collectionspace/services/client/RelationClient.java b/services/client/src/main/java/org/collectionspace/services/client/RelationClient.java index 1aa33971e..38a73ed0c 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/RelationClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/RelationClient.java @@ -44,11 +44,11 @@ public class RelationClient extends AbstractPoxServiceClientImpl { - /** + public TestServiceClient() throws Exception { + super(); + } + + /** * * Returning NULL since this class is a base-level client, used (only) * to obtain the base service URL. diff --git a/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java b/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java index 6938e5065..3faba944e 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/index/IndexClient.java @@ -29,6 +29,7 @@ import org.collectionspace.services.index.IndexCommon; * */ public class IndexClient extends AbstractCommonListPoxServiceClientImpl { + public static final String SERVICE_NAME = "index"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -37,6 +38,10 @@ public class IndexClient extends AbstractCommonListPoxServiceClientImpl extends BaseServiceTest implements ServiceTest { /** The logger. */ @@ -113,17 +114,18 @@ public abstract class AbstractServiceTestImpl getEntityResponseType(); - @SuppressWarnings("unchecked") @Override @Test(dataProvider = "testName", dependsOnMethods = {"create"}) public void read(String testName) throws Exception { @@ -313,7 +314,7 @@ public abstract class AbstractServiceTestImpl - Common list type */ +@SuppressWarnings("rawtypes") public abstract class BaseServiceTest { //A default MIME type result static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1"; @@ -88,8 +89,16 @@ public abstract class BaseServiceTest { protected static final String MAVEN_BASEDIR_PROPERTY = "maven.basedir"; /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class); - /** The Constant serviceClient. */ - protected static final TestServiceClient serviceClient = new TestServiceClient(); + + /** The static serviceClient for all instances */ + protected static TestServiceClient serviceClient; + static { + try { + serviceClient = new TestServiceClient(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } protected String knownResourceIdentifier = null; /** Use this to keep track of a single known resource */ @@ -145,24 +154,26 @@ public abstract class BaseServiceTest { // // Status constants // - protected static final int STATUS_BAD_REQUEST = - Response.Status.BAD_REQUEST.getStatusCode(); - protected static final int STATUS_CREATED = - Response.Status.CREATED.getStatusCode(); - protected static final int STATUS_INTERNAL_SERVER_ERROR = - Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); - protected static final int STATUS_NOT_FOUND = - Response.Status.NOT_FOUND.getStatusCode(); - protected static final int STATUS_OK = - Response.Status.OK.getStatusCode(); - protected static final int STATUS_FORBIDDEN = - Response.Status.FORBIDDEN.getStatusCode(); + protected static final int STATUS_BAD_REQUEST = Response.Status.BAD_REQUEST.getStatusCode(); + protected static final int STATUS_CREATED = Response.Status.CREATED.getStatusCode(); + protected static final int STATUS_INTERNAL_SERVER_ERROR = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); + protected static final int STATUS_NOT_FOUND = Response.Status.NOT_FOUND.getStatusCode(); + protected static final int STATUS_OK = Response.Status.OK.getStatusCode(); + protected static final int STATUS_FORBIDDEN = Response.Status.FORBIDDEN.getStatusCode(); // // "Global flag to cancel cleanup() method // private static boolean cancelCleanup = false; - + + /** + * Instantiates a new base service test. + * @throws Exception + */ + public BaseServiceTest() { + super(); + } + // // Decide if cleanup should happen // @@ -181,13 +192,6 @@ public abstract class BaseServiceTest { cancelCleanup = true; } - /** - * Instantiates a new base service test. - */ - public BaseServiceTest() { - super(); - } - /* * A getter for retrieving the tests logger */ @@ -204,15 +208,17 @@ public abstract class BaseServiceTest { * Gets the client. * * @return the client + * @throws Exception */ - abstract protected CollectionSpaceClient getClientInstance(); + abstract protected CollectionSpaceClient getClientInstance() throws Exception; /** * Gets the client. * * @return the client + * @throws Exception */ - abstract protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename); + abstract protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception; /* * Subclasses can override this method to return their AbstractCommonList subclass @@ -248,8 +254,9 @@ public abstract class BaseServiceTest { * base path, if any. * * @return The URL path component of the service. + * @throws Exception */ - protected abstract String getServicePathComponent(); + protected abstract String getServicePathComponent() throws Exception; protected abstract String getServiceName(); @@ -759,9 +766,10 @@ public abstract class BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { if (cleanupCancelled() == true) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); diff --git a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java index de498b50f..622fe101a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java @@ -31,6 +31,7 @@ import org.collectionspace.services.workflow.WorkflowCommon; * */ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl { + public static final String SERVICE_NAME = "workflow"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -88,6 +89,10 @@ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl getProxyClass() { - // TODO Auto-generated method stub return WorkflowProxy.class; } diff --git a/services/client/src/main/resources/sas-collectionspace-client.properties b/services/client/src/main/resources/sas-collectionspace-client.properties index 79c8762cc..a4e246213 100644 --- a/services/client/src/main/resources/sas-collectionspace-client.properties +++ b/services/client/src/main/resources/sas-collectionspace-client.properties @@ -1,13 +1,13 @@ # # URL of the CollectionSpace server and user credentials # -cspace.url=http://qa.collectionspace.org:8180/cspace-services/ +cspace.url=http://localhost:8180/cspace-services/ cspace.ssl=false cspace.auth=true -cspace.user=admin@materials.collectionspace.org +cspace.user=admin@testsci.collectionspace.org cspace.password=Administrator # # default tenant information # -cspace.tenant=2000 -cspace.tenantID=materials.collectionspace.org \ No newline at end of file +cspace.tenant=2 +cspace.tenantID=testsci.collectionspace.org \ No newline at end of file diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index f6cf4f603..3a8fca72d 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -47,11 +47,11 @@ public class CollectionObjectClient extends AbstractCommonListPoxServiceClientIm public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; - public CollectionObjectClient() { + public CollectionObjectClient() throws Exception { super(); } - public CollectionObjectClient(String clientPropertiesFilename) { + public CollectionObjectClient(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java index 9e7383129..e8fd9ded1 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java @@ -55,7 +55,6 @@ import org.collectionspace.services.collectionobject.TitleGroupList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.organization.OrgTermGroup; import org.collectionspace.services.person.PersonTermGroup; - import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -220,8 +219,9 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest personInfo = new HashMap(); @@ -281,8 +282,9 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest orgInfo = new HashMap(); @@ -392,13 +396,11 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest titleGroups = titleGroupList.getTitleGroup(); diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java index a673be7c3..4ff9cabf6 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java @@ -94,27 +94,14 @@ public class CollectionObjectSearchTest extends BaseServiceTest(); keywords.add(keyword); boolean keywordsInSameField = true; @@ -491,7 +480,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest keywords, boolean keywordsInSameField) { + List keywords, boolean keywordsInSameField) throws Exception { testSetup(STATUS_CREATED, ServiceRequestType.CREATE); CollectionObjectClient client = new CollectionObjectClient(); for (long i = 0; i < numToCreate; i++) { @@ -514,7 +503,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest keywords, boolean keywordsInSameField) { + List keywords, boolean keywordsInSameField) throws Exception { CollectionobjectsCommon collectionObject = new CollectionobjectsCommon(); collectionObject.setObjectNumber(createIdentifier()); if (keywordsInSameField) { @@ -550,13 +539,13 @@ public class CollectionObjectSearchTest extends BaseServiceTest keywords) { + private Response doSearch(List keywords) throws Exception { String searchParamValue = listToString(keywords, KEYWORD_SEPARATOR); return doSearch(searchParamValue); } private Response doAdvancedSearch( - String propertyName, String propertyValue, String operator) { + String propertyName, String propertyValue, String operator) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Searching on property: " + propertyName + "=" + "'" + propertyValue + "'"); @@ -569,7 +558,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest 0) { + for (String key : inProperties.stringPropertyNames()) { + String propertyValue = inProperties.getProperty(key); + String newPropertyValue = Tools.getPasswordFromEnv(propertyValue); + if (newPropertyValue != null) { // non-null result means the property value was the name of an environment variable + inProperties.setProperty(key, newPropertyValue); + } + } + } + + return result; + } + + /** + * Try to find the value of a password variable in the system or JVM environment. This code substitutes only environment variables formed + * like ${cspace.password.mysecret} or ${cspace_password_mysecret_secret}. The corresponding environment variables would + * be "cspace.password.mysecret" and "cspace.password.mysecret.secret". + * + * Returns null if the passed in propertyValue is not a password variable -i.e., not something of the form {$cspace.password.foo} + * + * Throws an exception if the passed in propertyValue has a valid variable form but the corresponding environment variable is not + * set. + * + * @param propertyValue + * @return + * @throws Exception + */ + static private String getPasswordFromEnv(String propertyValue) throws Exception { + String result = null; + // + // Replace things like ${cspace.password.cow} with values from either the environment + // or from the JVM system properties. + // + Pattern pattern = Pattern.compile("\\$\\{([A-Za-z0-9_\\.]+)\\}"); // For example, "${cspace.password.mysecret}" or "${password_strong_longpassword}" + Matcher matcher = pattern.matcher(propertyValue); + String key = null; + if (matcher.find()) { + key = matcher.group(1); // Gets the string inside the ${} enclosure. For example, gets "cspace.password.mysecret" from "${cspace.password.mysecret}" + result = System.getenv(key); + if (result == null || result.isEmpty()) { + // If we couldn't find a value in the environment, check the JVM system properties + result = System.getProperty(key); + } + if (result == null || result.isEmpty()) { + String errMsg = String.format("Could find neither an environment variable nor a systen variable named '%s'", key); + throw new Exception(errMsg); + } + } + + return result; + } } diff --git a/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java b/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java index 75cfa1404..791dcbb93 100644 --- a/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java +++ b/services/common-test/src/test/java/org/collectionspace/services/client/test/ServiceLayerTest.java @@ -23,6 +23,7 @@ package org.collectionspace.services.client.test; import java.io.IOException; + import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; @@ -34,7 +35,6 @@ import org.apache.commons.httpclient.methods.OptionsMethod; import org.apache.commons.httpclient.methods.TraceMethod; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.TestServiceClient; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -53,8 +53,8 @@ public class ServiceLayerTest { private final String CLASS_NAME = ServiceLayerTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - private TestServiceClient serviceClient = new TestServiceClient(); - private HttpClient httpClient = serviceClient.getHttpClient(); + private TestServiceClient serviceClient; + private HttpClient httpClient; @BeforeSuite void printServiceClientProperties() { @@ -73,6 +73,11 @@ public class ServiceLayerTest { + serviceClient.getProperty(CollectionSpaceClient.PASSWORD_PROPERTY)); } } + + public ServiceLayerTest() throws Exception { + serviceClient = new TestServiceClient(); + httpClient = serviceClient.getHttpClient(); + } @Test public void servicesExist() { diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 607186f15..6e4d9470f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; @@ -38,6 +39,7 @@ import org.collectionspace.services.client.IClientQueryParams; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon; import org.collectionspace.services.common.config.PropertyItemUtils; import org.collectionspace.services.common.config.ServiceConfigUtils; @@ -51,6 +53,7 @@ import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.config.ClientType; import org.collectionspace.services.config.service.ObjectPartType; import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.tenant.RemoteClientConfig; import org.collectionspace.services.config.tenant.RepositoryDomainType; import org.collectionspace.services.config.tenant.TenantBindingType; import org.collectionspace.services.config.types.PropertyItemType; @@ -76,6 +79,7 @@ import org.slf4j.LoggerFactory; * @param * @param */ +@SuppressWarnings("rawtypes") public abstract class AbstractServiceContextImpl implements ServiceContext { @@ -665,10 +669,19 @@ public abstract class AbstractServiceContextImpl * (non-Javadoc) * @see org.collectionspace.services.common.context.ServiceContext#getClient(java.lang.String) */ - @Override + @Override public AuthorityClient getClient(String clientPropertiesFilename) throws Exception { AuthorityClient result = null; + Properties inProperties = Tools.loadProperties(clientPropertiesFilename, true); + result = getClient(inProperties); + + return result; + } + + public AuthorityClient getClient(Properties inProperties) throws Exception { + AuthorityClient result = null; + String authorityClientClazz = getServiceBinding().getClientHandler(); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); authorityClientClazz = authorityClientClazz.trim(); @@ -676,7 +689,7 @@ public abstract class AbstractServiceContextImpl Class c = tccl.loadClass(authorityClientClazz); if (AuthorityClient.class.isAssignableFrom(c)) { result = authorityClient = ((AuthorityClient) c.newInstance()); - result.setClientProperties(clientPropertiesFilename); + result.setClientProperties(inProperties); } else { logger.error(String.format("The service binding clientHandler class '%s' for '%s' service was not of type AuthorityClient.", authorityClientClazz, this.getServiceName())); @@ -688,7 +701,24 @@ public abstract class AbstractServiceContextImpl } return result; - } + } + + @Override + public AuthorityClient getClient(RemoteClientConfig remoteClientConfig) throws Exception { + AuthorityClient result = null; + + Properties properties = new Properties(); + properties.setProperty(AuthorityClient.URL_PROPERTY, remoteClientConfig.getUrl()); + properties.setProperty(AuthorityClient.USER_PROPERTY, remoteClientConfig.getUser()); + properties.setProperty(AuthorityClient.PASSWORD_PROPERTY, remoteClientConfig.getPassword()); + properties.setProperty(AuthorityClient.SSL_PROPERTY, remoteClientConfig.getSsl()); + properties.setProperty(AuthorityClient.AUTH_PROPERTY, remoteClientConfig.getAuth()); + properties.setProperty(AuthorityClient.TENANT_ID_PROPERTY, remoteClientConfig.getTenantId()); + properties.setProperty(AuthorityClient.TENANT_NAME_PROPERTY, remoteClientConfig.getTenantName()); + + result = getClient(properties); + return result; + } @Override public void addValidatorHandler(ValidatorHandler validator) throws Exception { diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index f72dbe648..eaff58c8c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -40,6 +40,7 @@ import org.collectionspace.services.common.security.SecurityContext; import org.collectionspace.services.config.ClientType; import org.collectionspace.services.config.service.ObjectPartType; import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.tenant.RemoteClientConfig; import org.collectionspace.services.config.tenant.RepositoryDomainType; /** @@ -359,6 +360,8 @@ public interface ServiceContext { public CollectionSpaceClient getClient() throws Exception; public CollectionSpaceClient getClient(String clientProperitesFilename) throws Exception; + + public CollectionSpaceClient getClient(RemoteClientConfig remoteClientConfig) throws Exception; /** * @return the JAX-RS resource of service for the current context. diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index 028dd4cea..770289760 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -28,12 +28,9 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import org.collectionspace.services.client.PoxPayloadIn; -import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.api.RefName; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.query.QueryContext; -import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/TenantRepository.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/TenantRepository.java index ecbeb4ef3..dee2fb069 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/TenantRepository.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/TenantRepository.java @@ -24,6 +24,7 @@ package org.collectionspace.services.nuxeo.client.java; import java.util.Hashtable; +import java.util.List; import javax.security.auth.login.LoginContext; @@ -34,9 +35,13 @@ import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; import org.collectionspace.services.config.ClientType; import org.collectionspace.services.config.RepositoryClientConfigType; import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.tenant.RemoteClientConfig; +import org.collectionspace.services.config.tenant.RemoteClientConfigurations; import org.collectionspace.services.config.tenant.RepositoryDomainType; import org.collectionspace.services.config.tenant.TenantBindingType; + import org.nuxeo.runtime.api.Framework; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClient.java b/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClient.java index ff1688fe4..7e0643c5a 100644 --- a/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClient.java +++ b/services/concept/client/src/main/java/org/collectionspace/services/client/ConceptAuthorityClient.java @@ -52,11 +52,11 @@ public class ConceptAuthorityClient extends AuthorityClientImpl + + + + + 123 + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + 123 + 123 + 123 + 123 + 123 + 123 + + + 123 + 123 + 123 + 123 + 123 + 123 + 123 + 123 + + + + 123 + 123 + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + 123 + 123 + + + + + + + + + + + 123 + + + + + + + + + + + + + + 123 + + 123 + + 123 + + 123 + + 123 + 123 + 123 + 123 + + 123 + 123 + 123 + 123 + 123 + 123 + 123 + + 123 + + + + 123 + 123 + 123 + 123 + + 123 + + + + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + + + + + + + 123 + 123 + + + 123 + 123 + + + + 123 + 123 + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + 123 + 123 + + + + + + + + + + + 123 + + + + + + + + + + + + + + + 123 + + 123 + + 123 + + 123 + + 123 + 123 + 123 + 123 + + 123 + 123 + 123 + 123 + 123 + 123 + 123 + + 123 + + + + 123 + 123 + 123 + 123 + + 123 + + + + + + + 123 + 123 + + + 123 + 123 + + + + + 123 + + + + + + + 123 + 123 + + + 123 + 123 + + + + 123 + 123 + + + 123 + 123 + + + 123 + 123 + + + + + 123 + 123 + + + 123 + 123 + + + + + diff --git a/services/config/src/main/resources/service.xsd b/services/config/src/main/resources/service.xsd index 158c1bb3f..0295f92e0 100644 --- a/services/config/src/main/resources/service.xsd +++ b/services/config/src/main/resources/service.xsd @@ -61,6 +61,7 @@ + diff --git a/services/config/src/main/resources/tenant.xsd b/services/config/src/main/resources/tenant.xsd index 5eb4e99c8..f9bf0d467 100644 --- a/services/config/src/main/resources/tenant.xsd +++ b/services/config/src/main/resources/tenant.xsd @@ -18,13 +18,14 @@ xmlns="http://collectionspace.org/services/config/tenant" xmlns:types="http://collectionspace.org/services/config/types" xmlns:service="http://collectionspace.org/services/config/service" + xmlns:remoteclientconfig="http://collectionspace.org/services/config/remoteclientconfig" targetNamespace="http://collectionspace.org/services/config/tenant" version="0.1" elementFormDefault="qualified"> - - + + @@ -47,6 +48,7 @@ + @@ -72,4 +74,26 @@ + + + + + + + + + Connection details for a remote CollectionSpace instance. Used for things like the Share Authority Server + + + + + + + + + + + + + diff --git a/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java index bdb76b2e9..2a816901f 100644 --- a/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java +++ b/services/conservation/client/src/main/java/org/collectionspace/services/client/ConservationClient.java @@ -33,11 +33,11 @@ public class ConservationClient extends AbstractCommonListPoxServiceClientImpl implements AuthorityWithContactsClient { - public AuthorityWithContactsClientImpl(String clientPropertiesFilename) { + public AuthorityWithContactsClientImpl(String clientPropertiesFilename) throws Exception { super(clientPropertiesFilename); } - public AuthorityWithContactsClientImpl() { + public AuthorityWithContactsClientImpl() throws Exception { super(); } diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java index c2d165d6c..f976fa29f 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java @@ -33,11 +33,11 @@ public class ContactClient extends AbstractCommonListPoxServiceClientImpl { - private final String CLASS_NAME = ContactServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(ContactServiceTest.class); // Instance variables specific to this test. // final String SERVICE_PATH_COMPONENT = "contacts"; @@ -70,12 +71,12 @@ public class ContactServiceTest extends AbstractPoxServiceTestImpl getClientInstance() { + protected CollectionSpaceClient getClientInstance() throws Exception { return new GroupClient(); } @Override - protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { return new GroupClient(clientPropertiesFilename); } @@ -79,18 +78,18 @@ public class GroupServiceTest extends AbstractPoxServiceTestImpl { intakeIdsCreated.add(newId); } - protected void createPersonRefs() { + protected void createPersonRefs() throws Exception { // // First, create a new person authority // @@ -205,7 +204,7 @@ public class IntakeAuthRefsTest extends BaseServiceTest { personIdsCreated.add(csid); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -315,9 +314,10 @@ public class IntakeAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -355,7 +355,7 @@ public class IntakeAuthRefsTest extends BaseServiceTest { String depositor, String conditionCheckerAssessor, String insurer, - String Valuer ) { + String Valuer ) throws Exception { IntakesCommon intake = new IntakesCommon(); intake.setEntryNumber(entryNumber); intake.setEntryDate(entryDate); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java index 0a13b8a4a..9bac78c9c 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java @@ -41,7 +41,6 @@ import org.collectionspace.services.intake.CurrentLocationGroup; import org.collectionspace.services.intake.CurrentLocationGroupList; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.jaxb.AbstractCommonList; - import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -64,12 +63,12 @@ public class IntakeServiceTest extends AbstractPoxServiceTestImpl { /** * Creates the person refs. + * @throws Exception */ - protected void createPersonRefs() { + protected void createPersonRefs() throws Exception { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); @@ -223,7 +223,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { personIdsCreated.add(csid); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -405,9 +405,10 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -447,7 +448,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { String depositor, String conditionCheckerAssessor, String insurer, - String Valuer) { + String Valuer) throws Exception { IntakesCommon intake = new IntakesCommon(); intake.setEntryNumber(entryNumber); intake.setEntryDate(entryDate); diff --git a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java index 32d36c1f0..f99f4a319 100644 --- a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java +++ b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java @@ -33,11 +33,11 @@ public class LoaninClient extends AbstractCommonListPoxServiceClientImpl { loaninIdsCreated.add(newId); } - protected void createPersonRefs(){ + protected void createPersonRefs() throws Exception{ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding @@ -210,7 +209,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // repeatable / multivalued authority reference fields. Be sure to } - protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -332,9 +331,10 @@ public class LoaninAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -384,7 +384,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { String lendersAuthorizer, String lendersContact, String borrowersContact, - String borrowersAuthorizer) { + String borrowersAuthorizer) throws Exception { LoansinCommon loaninCommon = new LoansinCommon(); loaninCommon.setLoanInNumber(loaninNumber); loaninCommon.setLoanInNumber(returnDate); 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 1eb2a7460..848628189 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 @@ -39,7 +39,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanin.LenderGroup; import org.collectionspace.services.loanin.LenderGroupList; import org.collectionspace.services.loanin.LoansinCommon; - import org.testng.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,12 +68,12 @@ public class LoaninServiceTest extends AbstractPoxServiceTestImpl { loanoutIdsCreated.add(newId); } - protected void createPersonRefs(){ + protected void createPersonRefs() throws Exception{ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding @@ -206,7 +205,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -323,9 +322,10 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -372,7 +372,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { String borrower, String borrowersContact, String lendersAuthorizer, - String lendersContact) { + String lendersContact) throws Exception { LoansoutCommon loanoutCommon = new LoansoutCommon(); loanoutCommon.setLoanOutNumber(loanoutNumber); loanoutCommon.setLoanReturnDate(returnDate); 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 d0779dbce..7739b2016 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 @@ -38,7 +38,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanout.LoanStatusGroup; import org.collectionspace.services.loanout.LoanStatusGroupList; import org.collectionspace.services.loanout.LoansoutCommon; - import org.testng.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,12 +62,12 @@ public class LoanoutServiceTest extends AbstractPoxServiceTestImpl entry : allResourceItemIdsCreated.entrySet()) { - itemResourceId = entry.getKey(); - parentResourceId = entry.getValue(); - // Note: Any non-success responses from the delete operation - // below are ignored and not reported. - 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. - client.delete(resourceId).close(); - } - } + public void cleanUp() throws Exception { + String noTest = System.getProperty("noTestCleanup"); + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + String parentResourceId; + String itemResourceId; + // Clean up contact resources. + MaterialAuthorityClient client = new MaterialAuthorityClient(); + parentResourceId = knownResourceId; + // Clean up item resources. + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { + itemResourceId = entry.getKey(); + parentResourceId = entry.getValue(); + // Note: Any non-success responses from the delete operation + // below are ignored and not reported. + 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. + client.delete(resourceId).close(); + } + } // --------------------------------------------------------------- // Utility methods used by tests above diff --git a/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java b/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java index f0def6990..632cf2d70 100644 --- a/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java +++ b/services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java @@ -17,6 +17,7 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; + import org.collectionspace.services.media.MediaCommon; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput; @@ -33,11 +34,11 @@ public class MediaClient extends AbstractCommonListPoxServiceClientImpl { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } - private PoxPayloadOut createMediaInstance(String depositorRefName, String title) { + private PoxPayloadOut createMediaInstance(String depositorRefName, String title) throws Exception { this.title = title; this.depositorRefName = depositorRefName; MediaCommon media = new MediaCommon(); @@ -124,7 +123,7 @@ public class MediaAuthRefsTest extends BaseServiceTest { } } - protected void createPersonRefs() { + protected void createPersonRefs() throws Exception { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( @@ -151,7 +150,7 @@ public class MediaAuthRefsTest extends BaseServiceTest { depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -246,9 +245,10 @@ public class MediaAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { logger.debug("Skipping Cleanup phase ..."); diff --git a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java index 3986cc09a..adddada32 100644 --- a/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java +++ b/services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java @@ -37,7 +37,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.media.LanguageList; import org.collectionspace.services.media.MediaCommon; import org.collectionspace.services.media.SubjectList; - import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput; import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; @@ -89,12 +88,12 @@ public class MediaServiceTest extends AbstractPoxServiceTestImpl { - public static final String SERVICE_NAME = "movements"; + public static final String SERVICE_NAME = "movements"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + public MovementClient() throws Exception { + super(); + } + @Override public String getServiceName() { return SERVICE_NAME; 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 5eb255909..0ab86d940 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 @@ -44,7 +44,6 @@ import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.movement.MovementsCommon; import org.collectionspace.services.person.PersonTermGroup; - import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -155,7 +154,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { movementIdsCreated.add(newId); } - protected void createPersonRefs(){ + protected void createPersonRefs() throws Exception{ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. @@ -182,7 +181,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { movementContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -297,9 +296,10 @@ public class MovementAuthRefsTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun=true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -345,7 +345,7 @@ public class MovementAuthRefsTest extends BaseServiceTest { private PoxPayloadOut createMovementInstance(String movementReferenceNumber, String locationDate, - String movementContact) { + String movementContact) throws Exception { MovementsCommon movementCommon = new MovementsCommon(); movementCommon.setMovementReferenceNumber(movementReferenceNumber); movementCommon.setLocationDate(locationDate); diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java index 8f48f2fa1..7d41dd325 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java @@ -32,7 +32,6 @@ import org.collectionspace.services.movement.MovementsCommon; import org.collectionspace.services.movement.MovementMethodsList; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; - import org.testng.Assert; import org.testng.annotations.Test; import org.slf4j.Logger; @@ -65,7 +64,7 @@ public class MovementServiceTest extends * () */ @Override - protected CollectionSpaceClient getClientInstance() { + protected CollectionSpaceClient getClientInstance() throws Exception { return new MovementClient(); } @@ -95,14 +94,15 @@ public class MovementServiceTest extends * @param identifier * the identifier * @return the multipart output + * @throws Exception */ - private PoxPayloadOut createMovementInstance(String identifier) { + private PoxPayloadOut createMovementInstance(String identifier) throws Exception { return createInstance("movementReferenceNumber-" + identifier); } @Override protected PoxPayloadOut createInstance(String commonPartName, - String identifier) { + String identifier) throws Exception { PoxPayloadOut result = createMovementInstance(identifier); return result; } @@ -114,9 +114,10 @@ public class MovementServiceTest extends * A movement reference number. * @return Multipart output suitable for use as a payload in a create or * update request. + * @throws Exception */ @Override - protected PoxPayloadOut createInstance(String movementReferenceNumber) { + protected PoxPayloadOut createInstance(String movementReferenceNumber) throws Exception { MovementsCommon movementCommon = new MovementsCommon(); // FIXME: Values of currentLocation, normalLocation, // and movementContact should be refNames. 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 0ce3a876e..c11d5f484 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 @@ -40,7 +40,6 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.movement.MovementsCommon; import org.collectionspace.services.jaxb.AbstractCommonList; - import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.DataProvider; @@ -498,9 +497,10 @@ public class MovementSortByTest extends BaseServiceTest { * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { @@ -653,7 +653,7 @@ public class MovementSortByTest extends BaseServiceTest { private PoxPayloadOut createMovementInstance( String movementReferenceNumber, String movementNote, - String locationDate) { + String locationDate) throws Exception { MovementsCommon movementCommon = new MovementsCommon(); movementCommon.setMovementReferenceNumber(movementReferenceNumber); movementCommon.setMovementNote(movementNote); diff --git a/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java index acd23cc49..59d28e1ff 100644 --- a/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java +++ b/services/objectexit/client/src/main/java/org/collectionspace/services/client/ObjectExitClient.java @@ -33,11 +33,11 @@ public class ObjectExitClient extends AbstractCommonListPoxServiceClientImpl throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } - private PoxPayloadOut createObjectExitInstance(String depositorRefName, String exitNumber, String exitDateDisplayDate) { + private PoxPayloadOut createObjectExitInstance(String depositorRefName, String exitNumber, String exitDateDisplayDate) throws Exception { this.exitNumber = exitNumber; this.depositorRefName = depositorRefName; this.exitDateGroup.setDateDisplayDate(exitDateDisplayDate); @@ -143,7 +142,7 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest objectexitIdsCreated.add(newId);// Store the IDs from every resource created; delete on cleanup } - protected void createPersonRefs() { + protected void createPersonRefs() throws Exception { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( @@ -170,7 +169,7 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String shortId, String authRefName) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); @@ -258,9 +257,10 @@ public class ObjectExitAuthRefsTest extends BaseServiceTest * For this reason, it attempts to remove all resources created * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. + * @throws Exception */ @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { logger.debug("Skipping Cleanup phase ..."); diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java index 824163f06..11c2cf808 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java @@ -31,7 +31,6 @@ import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.objectexit.ObjectexitCommon; - import org.testng.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,12 +57,12 @@ public class ObjectExitServiceTest extends AbstractPoxServiceTestImpl personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); @@ -376,9 +377,10 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest personInfo = new HashMap(); @@ -236,9 +236,10 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest itemFieldProperties, List terms, Map> itemRepeatableFieldProperties) { + Map itemFieldProperties, List terms, Map> itemRepeatableFieldProperties) throws Exception { final String testName = "createItemInAuthority"; if (logger.isDebugEnabled()) { @@ -356,10 +358,10 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest docTypes = new ArrayList(); docTypes.add(testDocType); return createReportInstance( @@ -289,13 +289,14 @@ public class ReportServiceTest extends AbstractPoxServiceTestImpl forDocTypeList, boolean supportsSingle, boolean supportsList, boolean supportsGroup, boolean supportsNoContext, String filename, - String outputMIME) { + String outputMIME) throws Exception { ReportsCommon reportCommon = new ReportsCommon(); reportCommon.setName(name); ReportsCommon.ForDocTypes forDocTypes = new ReportsCommon.ForDocTypes(); @@ -325,7 +326,7 @@ public class ReportServiceTest extends AbstractPoxServiceTestImpl { - private final String CLASS_NAME = AuthorizationServiceTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - // Instance variables specific to this test. - private Hashtable accValues = new Hashtable(); - //key for permValues is id as there could be several perms for the same resource - private Hashtable permValues = new Hashtable(); - //key for roleValues is roleName - private Hashtable roleValues = new Hashtable(); - private String bigbirdPermId; - private String elmoPermId; - private final static String TEST_SERVICE_NAME = "dimensions"; - private boolean accountRolesFlipped = false; - /* - * This method is called only by the parent class, AbstractServiceTestImpl - */ - - @Override + private final String CLASS_NAME = AuthorizationServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. + private Hashtable accValues = new Hashtable(); + // key for permValues is id as there could be several perms for the same + // resource + private Hashtable permValues = new Hashtable(); + // key for roleValues is roleName + private Hashtable roleValues = new Hashtable(); + private String bigbirdPermId; + private String elmoPermId; + private final static String TEST_SERVICE_NAME = "dimensions"; + private boolean accountRolesFlipped = false; + + /* + * This method is called only by the parent class, AbstractServiceTestImpl + */ + + @Override protected String getServiceName() { - // no need to return anything but null since no auth resources are - // accessed - throw new UnsupportedOperationException(); - } - - @Override - protected String getServicePathComponent() { - // no need to return anything but null since no auth resources are - // accessed - throw new UnsupportedOperationException(); - } - - @BeforeClass(alwaysRun = true) - public void seedData() { - seedPermissions(); - seedRoles(); - seedAccounts(); - seedAccountRoles(); - seedPermissionRoles(); - } - - private void seedPermissions() { - String res = TEST_SERVICE_NAME; - - PermissionAction pac = new PermissionAction(); - pac.setName(ActionType.CREATE); - PermissionAction par = new PermissionAction(); - par.setName(ActionType.READ); - PermissionAction pau = new PermissionAction(); - pau.setName(ActionType.UPDATE); - - - //bigbird can create, read and update but not delete - List bbactions = new ArrayList(); - bbactions.add(pac); - bbactions.add(par); - bbactions.add(pau); - bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT); - PermissionValue bbpv = new PermissionValue(); - bbpv.setResourceName(res); - bbpv.setPermissionId(bigbirdPermId); - permValues.put(bbpv.getPermissionId(), bbpv); - - //elmo can only read - List eactions = new ArrayList(); - eactions.add(par); - elmoPermId = createPermission(res, eactions, EffectType.PERMIT); - PermissionValue epv = new PermissionValue(); - epv.setResourceName(res); - epv.setPermissionId(elmoPermId); - permValues.put(epv.getPermissionId(), epv); - } - - private void seedRoles() { - String rn1 = "ROLE_TEST_CM"; - String r1RoleId = createRole(rn1); - RoleValue rv1 = new RoleValue(); - rv1.setRoleId(r1RoleId); - rv1.setRoleName(rn1); - roleValues.put(rv1.getRoleName(), rv1); - - String rn2 = "ROLE_TEST_INTERN"; - String r2RoleId = createRole(rn2); - RoleValue rv2 = new RoleValue(); - rv2.setRoleId(r2RoleId); - rv2.setRoleName(rn2); - roleValues.put(rv2.getRoleName(), rv2); - } - - private void seedAccounts() { - String userId1 = "bigbird2010"; - String accId1 = createAccount(userId1, "bigbird@cspace.org"); - AccountValue av1 = new AccountValue(); - av1.setScreenName(userId1); - av1.setUserId(userId1); - av1.setAccountId(accId1); - accValues.put(av1.getUserId(), av1); - - String userId2 = "elmo2010"; - String accId2 = createAccount(userId2, "elmo@cspace.org"); - AccountValue av2 = new AccountValue(); - av2.setScreenName(userId2); - av2.setUserId(userId2); - av2.setAccountId(accId2); - accValues.put(av2.getUserId(), av2); - - String userId3 = "lockedOut"; - String accId3 = createAccount(userId3, "lockedOut@cspace.org"); - AccountValue av3 = new AccountValue(); - av3.setScreenName(userId3); - av3.setUserId(userId3); - av3.setAccountId(accId3); - accValues.put(av3.getUserId(), av3); - } - - private void seedAccountRoles() { - - List bigbirdRoleValues = new ArrayList(); - bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); - createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues); - - List elmoRoleValues = new ArrayList(); - elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - createAccountRole(accValues.get("elmo2010"), elmoRoleValues); - } - - private void seedPermissionRoles() { - - List bigbirdRoleValues = new ArrayList(); - bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); - createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues); - - List elmoRoleValues = new ArrayList(); - elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - createPermissionRole(permValues.get(elmoPermId), elmoRoleValues); - - } - - - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() - */ - @Override - protected CollectionSpaceClient getClientInstance() { - // This method is meaningless to this test. - return null; - } + // no need to return anything but null since no auth resources are + // accessed + throw new UnsupportedOperationException(); + } + + @Override + protected String getServicePathComponent() { + // no need to return anything but null since no auth resources are + // accessed + throw new UnsupportedOperationException(); + } + + @BeforeClass(alwaysRun = true) + public void seedData() throws Exception { + seedPermissions(); + seedRoles(); + seedAccounts(); + seedAccountRoles(); + seedPermissionRoles(); + } + + private void seedPermissions() throws Exception { + String res = TEST_SERVICE_NAME; + + PermissionAction pac = new PermissionAction(); + pac.setName(ActionType.CREATE); + PermissionAction par = new PermissionAction(); + par.setName(ActionType.READ); + PermissionAction pau = new PermissionAction(); + pau.setName(ActionType.UPDATE); + + // bigbird can create, read and update but not delete + List bbactions = new ArrayList(); + bbactions.add(pac); + bbactions.add(par); + bbactions.add(pau); + bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT); + PermissionValue bbpv = new PermissionValue(); + bbpv.setResourceName(res); + bbpv.setPermissionId(bigbirdPermId); + permValues.put(bbpv.getPermissionId(), bbpv); + + // elmo can only read + List eactions = new ArrayList(); + eactions.add(par); + elmoPermId = createPermission(res, eactions, EffectType.PERMIT); + PermissionValue epv = new PermissionValue(); + epv.setResourceName(res); + epv.setPermissionId(elmoPermId); + permValues.put(epv.getPermissionId(), epv); + } + + private void seedRoles() throws Exception { + String rn1 = "ROLE_TEST_CM"; + String r1RoleId = createRole(rn1); + RoleValue rv1 = new RoleValue(); + rv1.setRoleId(r1RoleId); + rv1.setRoleName(rn1); + roleValues.put(rv1.getRoleName(), rv1); + + String rn2 = "ROLE_TEST_INTERN"; + String r2RoleId = createRole(rn2); + RoleValue rv2 = new RoleValue(); + rv2.setRoleId(r2RoleId); + rv2.setRoleName(rn2); + roleValues.put(rv2.getRoleName(), rv2); + } + + private void seedAccounts() throws Exception { + String userId1 = "bigbird2010"; + String accId1 = createAccount(userId1, "bigbird@cspace.org"); + AccountValue av1 = new AccountValue(); + av1.setScreenName(userId1); + av1.setUserId(userId1); + av1.setAccountId(accId1); + accValues.put(av1.getUserId(), av1); + + String userId2 = "elmo2010"; + String accId2 = createAccount(userId2, "elmo@cspace.org"); + AccountValue av2 = new AccountValue(); + av2.setScreenName(userId2); + av2.setUserId(userId2); + av2.setAccountId(accId2); + accValues.put(av2.getUserId(), av2); + + String userId3 = "lockedOut"; + String accId3 = createAccount(userId3, "lockedOut@cspace.org"); + AccountValue av3 = new AccountValue(); + av3.setScreenName(userId3); + av3.setUserId(userId3); + av3.setAccountId(accId3); + accValues.put(av3.getUserId(), av3); + } + + private void seedAccountRoles() throws Exception { + + List bigbirdRoleValues = new ArrayList(); + bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); + createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues); + + List elmoRoleValues = new ArrayList(); + elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + createAccountRole(accValues.get("elmo2010"), elmoRoleValues); + } + + private void seedPermissionRoles() throws Exception { + + List bigbirdRoleValues = new ArrayList(); + bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); + createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues); + + List elmoRoleValues = new ArrayList(); + elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + createPermissionRole(permValues.get(elmoPermId), elmoRoleValues); + + } + + /* + * (non-Javadoc) + * + * @see + * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance + * () + */ + @Override + protected CollectionSpaceClient getClientInstance() { + // This method is meaningless to this test. + return null; + } @Override protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { @@ -240,606 +243,590 @@ public class AuthorizationServiceTest extends BaseServiceTest bigbirdRoleValues = new ArrayList(); - bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); - deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues); - - List elmoRoleValues = new ArrayList(); - elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues); - } - - private void deleteAccountRoles() { - List bigbirdRoleValues = new ArrayList(); - bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); - - List elmoRoleValues = new ArrayList(); - elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - if(!accountRolesFlipped) { - deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues); - deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues); - } else { - deleteAccountRole(accValues.get("bigbird2010"), elmoRoleValues); - deleteAccountRole(accValues.get("elmo2010"),bigbirdRoleValues ); - } - } - - private void flipInitialAccountRoles() { - if(!accountRolesFlipped) { - List cmRoleValues = new ArrayList(); - List internRoleValues = new ArrayList(); - cmRoleValues.add(roleValues.get("ROLE_TEST_CM")); - internRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - - deleteAccountRole(accValues.get("bigbird2010"), cmRoleValues); - deleteAccountRole(accValues.get("elmo2010"), internRoleValues); - - createAccountRole(accValues.get("bigbird2010"), internRoleValues); - createAccountRole(accValues.get("elmo2010"), cmRoleValues); - - accountRolesFlipped = true; - } - } - - private void restoreInitialAccountRoles() { - if(accountRolesFlipped) { - List cmRoleValues = new ArrayList(); - List internRoleValues = new ArrayList(); - cmRoleValues.add(roleValues.get("ROLE_TEST_CM")); - internRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); - - deleteAccountRole(accValues.get("bigbird2010"), internRoleValues); - deleteAccountRole(accValues.get("elmo2010"), cmRoleValues); - - createAccountRole(accValues.get("bigbird2010"), internRoleValues); - createAccountRole(accValues.get("elmo2010"), cmRoleValues); - accountRolesFlipped = false; - } - } - - private void deletePermissions() { - //delete entities - for (PermissionValue pv : permValues.values()) { - deletePermission(pv.getPermissionId()); - } - } - - private void deleteRoles() { - for (RoleValue rv : roleValues.values()) { - deleteRole(rv.getRoleId()); - } - } - - private void deleteAccounts() { - - for (AccountValue av1 : accValues.values()) { - deleteAccount(av1.getAccountId()); - } - } - - private String createPermission(String resName, EffectType effect) { - List actions = PermissionFactory.createDefaultActions(); - return createPermission(resName, actions, effect); - } - - private String createPermission(String resName, - List actions, EffectType effect) { - String result = null; - - setupCreate(); - PermissionClient permClient = new PermissionClient(); - Permission permission = PermissionFactory.createPermissionInstance(resName, - "default permissions for " + resName, actions, effect, true, true, true); - Response res = permClient.create(permission); - try { - assertStatusCode(res, "CreatePermission"); - result = extractId(res); - } finally { - if (res != null) { - res.close(); - } - } - - return result; - } - - private void deletePermission(String permId) { - setupDelete(); - PermissionClient permClient = new PermissionClient(); - Response res = permClient.delete(permId); - try { - assertStatusCode(res, "DeletePermission"); - } finally { - if (res != null) { - res.close(); - } - } - } - - private String createRole(String roleName) { - String result = null; - - setupCreate(); - RoleClient roleClient = new RoleClient(); - Role role = RoleFactory.createRoleInstance(roleName, - roleName, //the display name - "role for " + roleName, true); - Response res = roleClient.create(role); - try { - assertStatusCode(res, "CreateRole"); - result = extractId(res); - } finally { - if (res != null) { - res.close(); - } - } - - return result; - } - - private void deleteRole(String roleId) { - setupDelete(); - RoleClient roleClient = new RoleClient(); - Response res = roleClient.delete(roleId); - try { - assertStatusCode(res, "DeleteRole"); - } finally { - if (res != null) { - res.close(); - } - } - } - - private String createAccount(String userName, String email) { - String result = null; - - setupCreate(); - AccountClient accountClient = new AccountClient(); - AccountsCommon account = AccountFactory.createAccountInstance( - userName, userName, userName, email, accountClient.getTenantId(), - true, false, true, true); - Response res = accountClient.create(account); - try { - assertStatusCode(res, "CreateAccount"); - result = extractId(res); - } finally { - if (res != null) { - res.close(); - } - } - - return result; - } - - private void deleteAccount(String accId) { - setupDelete(); - AccountClient accClient = new AccountClient(); - Response res = accClient.delete(accId); - try { - assertStatusCode(res, "DeleteAccount"); - } finally { - if (res != null) { - res.close(); - } - } - } - - private String createAccountRole(AccountValue av, - Collection rvs) { - String result = null; - - setupCreate(); - // Submit the request to the service and store the response. - AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( - av, rvs, true, true); - AccountRoleClient client = new AccountRoleClient(); - Response res = client.create(av.getAccountId(), accRole); - try { - assertStatusCode(res, "CreateAccountRole"); - result = extractId(res); - } finally { - if (res != null) { - res.close(); - } - } - - return result; - } - - private void deleteAccountRole(AccountValue av, - Collection rvs) { - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - AccountRoleClient client = new AccountRoleClient(); - AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( - av, rvs, true, true); - Response res = client.delete(av.getAccountId()); - try { - assertStatusCode(res, "DeleteAccountRole"); - } finally { - if (res != null) { - res.close(); - } - } - } - - private String createPermissionRole(PermissionValue pv, Collection rvs) { - String result = null; - - setupCreate(); - List rvls = new ArrayList(); - rvls.addAll(rvs); - PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( - pv, rvls, true, true); - PermissionRoleClient client = new PermissionRoleClient(); - Response res = client.create(pv.getPermissionId(), permRole); - try { - assertStatusCode(res, "CreatePermissionRole"); - result = extractId(res); - } finally { - if (res != null) { - res.close(); - } - } - - return result; - } - - private void deletePermissionRole(PermissionValue pv, - Collection rvs) { - List rvls = new ArrayList(); - rvls.addAll(rvs); - - // Perform setup. - setupDelete(); - - // Submit the request to the service and store the response. - PermissionRoleClient client = new PermissionRoleClient(); - PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( - pv, rvls, true, true); - Response res = client.delete(pv.getPermissionId()); - try { - assertStatusCode(res, "DeletePermissionRole"); - } finally { - if (res != null) { - res.close(); - } - } - } + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + + @Test(dataProvider = "testName") + public void create(String testName) throws Exception { + int statusCode; + setupCreate(); + + // Submit the request to the service and store the response. + DimensionClient client = new DimensionClient(); + // bigbird allowed to create + client.setAuth(true, "bigbird2010", true, "bigbird2010", true); + String identifier = createIdentifier(); + DimensionsCommon dimension = new DimensionsCommon(); + dimension.setDimension("dimensionType"); + dimension.setMeasurementUnit("measurementUnit-" + identifier); + dimension.setValueDate(new Date().toString()); + PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(), dimension); + Response res = client.create(multipart); + try { + statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode()); + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } finally { + res.close(); + } + + // Now verify that elmo cannot create + client = new DimensionClient(); + client.setAuth(true, "elmo2010", true, "elmo2010", true); + res = client.create(multipart); + try { + statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + " (verify not allowed): status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); + } finally { + res.close(); + } + + // Finally, verify that elmo has no access to Intakes + // Submit the request to the service and store the response. + IntakeClient iclient = new IntakeClient(); + iclient.setAuth(true, "elmo2010", true, "elmo2010", true); + multipart = createIntakeInstance("entryNumber-" + identifier, "entryDate-" + identifier, "depositor-" + + identifier); + res = iclient.create(multipart); + try { + if (logger.isDebugEnabled()) { + logger.debug(testName + " (verify create intake not allowed): status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); + } finally { + res.close(); + } + } + + /** + * Creates the intake instance. + * + * @param entryNumber + * the entry number + * @param entryDate + * the entry date + * @param depositor + * the depositor + * @return the multipart output + * @throws Exception + */ + private PoxPayloadOut createIntakeInstance(String entryNumber, String entryDate, String depositor) throws Exception { + IntakesCommon intake = new IntakesCommon(); + intake.setEntryNumber(entryNumber); + intake.setEntryDate(entryDate); + intake.setDepositor(depositor); + + PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new IntakeClient().getCommonPartName()); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, intake common"); + logger.debug(objectAsXmlString(intake, IntakesCommon.class)); + } + + return multipart; + } + + @Test(dataProvider = "testName", dependsOnMethods = { "delete" }) + public void verifyCreateWithFlippedRoles(String testName) throws Exception { + int statusCode; + setupCreate(); + + // Submit the request to the service and store the response. + DimensionClient client = new DimensionClient(); + flipInitialAccountRoles(); + + // Now verify that elmo can create + client.setAuth(true, "elmo2010", true, "elmo2010", true); + client = new DimensionClient(); + + String identifier = createIdentifier(); + DimensionsCommon dimension = new DimensionsCommon(); + dimension.setDimension("dimensionType"); + dimension.setMeasurementUnit("measurementUnit-" + identifier); + dimension.setValueDate(new Date().toString()); + PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(), dimension); + Response res = client.create(multipart); + try { + statusCode = res.getStatus(); + + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode()); + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } finally { + res.close(); + } + + // bigbird no longer allowed to create + client.setAuth(true, "bigbird2010", true, "bigbird2010", true); + res = client.create(multipart); + try { + statusCode = res.getStatus(); + if (logger.isDebugEnabled()) { + logger.debug(testName + " (verify not allowed): status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode()); + } finally { + res.close(); + } + + restoreInitialAccountRoles(); + } + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider = "testName", dependsOnMethods = { "create" }) + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + DimensionClient client = new DimensionClient(); + // elmo allowed to read + client.setAuth(true, "elmo2010", true, "elmo2010", true); + Response res = client.read(knownResourceId); + try { + assertStatusCode(res, testName); + PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class)); + DimensionsCommon dimension = (DimensionsCommon) extractPart(input, client.getCommonPartName(), + DimensionsCommon.class); + Assert.assertNotNull(dimension); + } finally { + if (res != null) { + res.close(); + } + } + } + + @Test(dataProvider = "testName", dependsOnMethods = { "read" }) + public void readLockedOut(String testName) throws Exception { + // Perform setup. + setupForbidden(); + + // Submit the request to the service and store the response. + DimensionClient client = new DimensionClient(); + // lockedOut allowed to read + client.setAuth(true, "lockedOut", true, "lockedOut", true); + Response res = client.read(knownResourceId); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + } + + @Test(dataProvider = "testName", dependsOnMethods = { "read" }) + public void updateNotAllowed(String testName) throws Exception { + setupForbidden(); + + // Create a new client and change its AuthN credentials + DimensionClient client = new DimensionClient(); + // elmo not allowed to update + client.setAuth(true, "elmo2010", true, "elmo2010", true); + // + // Create a new dimension object + // + DimensionsCommon dimension = new DimensionsCommon(); + dimension.setDimension("dimensionType"); + // Update the content of this resource. + dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit()); + dimension.setValueDate("updated-" + dimension.getValueDate()); + // + // Create and submit the request to the service and store the response. + // + PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension); + Response res = client.update(knownResourceId, output); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + // + // Create another new client with new credentials + // + client = new DimensionClient(); + // lockedOut not allowed to update + client.setAuth(true, "lockedOut", true, "lockedOut", true); + // + // Try the update again. + // + res = client.update(knownResourceId, output); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider = "testName", dependsOnMethods = { "updateNotAllowed" }) + public void deleteNotAllowed(String testName) throws Exception { + // Perform setup. + setupForbidden(); + // + // Create a new client and change the AuthN credentials + // + DimensionClient client = new DimensionClient(); + // bigbird can not delete + client.setAuth(true, "bigbird2010", true, "bigbird2010", true); + // + // Try to make a DELETE request + // + Response res = client.delete(knownResourceId); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + } + + @Test(dataProvider = "testName", dependsOnMethods = { "deleteNotAllowed" }) + public void delete(String testName) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + DimensionClient client = new DimensionClient(); + + Response res = client.delete(knownResourceId); + try { + assertStatusCode(res, testName); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @AfterClass(alwaysRun = true) + public void cleanUp() throws Exception { + setupDelete(); + String noTest = System.getProperty("noTestCleanup"); + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + + deletePermissionRoles(); + deleteAccountRoles(); + // FIXME delete on permission deletes all associations with roles + // this would delete association with ROLE_ADMINISTRATOR too + // deletePermissions(); + deleteRoles(); + deleteAccounts(); + } + + private void deletePermissionRoles() throws Exception { + List bigbirdRoleValues = new ArrayList(); + bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); + deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues); + + List elmoRoleValues = new ArrayList(); + elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues); + } + + private void deleteAccountRoles() throws Exception { + List bigbirdRoleValues = new ArrayList(); + bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM")); + + List elmoRoleValues = new ArrayList(); + elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + if (!accountRolesFlipped) { + deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues); + deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues); + } else { + deleteAccountRole(accValues.get("bigbird2010"), elmoRoleValues); + deleteAccountRole(accValues.get("elmo2010"), bigbirdRoleValues); + } + } + + private void flipInitialAccountRoles() throws Exception { + if (!accountRolesFlipped) { + List cmRoleValues = new ArrayList(); + List internRoleValues = new ArrayList(); + cmRoleValues.add(roleValues.get("ROLE_TEST_CM")); + internRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + + deleteAccountRole(accValues.get("bigbird2010"), cmRoleValues); + deleteAccountRole(accValues.get("elmo2010"), internRoleValues); + + createAccountRole(accValues.get("bigbird2010"), internRoleValues); + createAccountRole(accValues.get("elmo2010"), cmRoleValues); + + accountRolesFlipped = true; + } + } + + private void restoreInitialAccountRoles() throws Exception { + if (accountRolesFlipped) { + List cmRoleValues = new ArrayList(); + List internRoleValues = new ArrayList(); + cmRoleValues.add(roleValues.get("ROLE_TEST_CM")); + internRoleValues.add(roleValues.get("ROLE_TEST_INTERN")); + + deleteAccountRole(accValues.get("bigbird2010"), internRoleValues); + deleteAccountRole(accValues.get("elmo2010"), cmRoleValues); + + createAccountRole(accValues.get("bigbird2010"), internRoleValues); + createAccountRole(accValues.get("elmo2010"), cmRoleValues); + accountRolesFlipped = false; + } + } + + private void deletePermissions() throws Exception { + // delete entities + for (PermissionValue pv : permValues.values()) { + deletePermission(pv.getPermissionId()); + } + } + + private void deleteRoles() throws Exception { + for (RoleValue rv : roleValues.values()) { + deleteRole(rv.getRoleId()); + } + } + + private void deleteAccounts() throws Exception { + + for (AccountValue av1 : accValues.values()) { + deleteAccount(av1.getAccountId()); + } + } + + private String createPermission(String resName, EffectType effect) throws Exception { + List actions = PermissionFactory.createDefaultActions(); + return createPermission(resName, actions, effect); + } + + private String createPermission(String resName, List actions, EffectType effect) throws Exception { + String result = null; + + setupCreate(); + PermissionClient permClient = new PermissionClient(); + Permission permission = PermissionFactory.createPermissionInstance(resName, "default permissions for " + + resName, actions, effect, true, true, true); + Response res = permClient.create(permission); + try { + assertStatusCode(res, "CreatePermission"); + result = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + return result; + } + + private void deletePermission(String permId) throws Exception { + setupDelete(); + PermissionClient permClient = new PermissionClient(); + Response res = permClient.delete(permId); + try { + assertStatusCode(res, "DeletePermission"); + } finally { + if (res != null) { + res.close(); + } + } + } + + private String createRole(String roleName) throws Exception { + String result = null; + + setupCreate(); + RoleClient roleClient = new RoleClient(); + Role role = RoleFactory.createRoleInstance(roleName, roleName, // the + // display + // name + "role for " + roleName, true); + Response res = roleClient.create(role); + try { + assertStatusCode(res, "CreateRole"); + result = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + return result; + } + + private void deleteRole(String roleId) throws Exception { + setupDelete(); + RoleClient roleClient = new RoleClient(); + Response res = roleClient.delete(roleId); + try { + assertStatusCode(res, "DeleteRole"); + } finally { + if (res != null) { + res.close(); + } + } + } + + private String createAccount(String userName, String email) throws Exception { + String result = null; + + setupCreate(); + AccountClient accountClient = new AccountClient(); + AccountsCommon account = AccountFactory.createAccountInstance(userName, userName, userName, email, + accountClient.getTenantId(), true, false, true, true); + Response res = accountClient.create(account); + try { + assertStatusCode(res, "CreateAccount"); + result = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + return result; + } + + private void deleteAccount(String accId) throws Exception { + setupDelete(); + AccountClient accClient = new AccountClient(); + Response res = accClient.delete(accId); + try { + assertStatusCode(res, "DeleteAccount"); + } finally { + if (res != null) { + res.close(); + } + } + } + + private String createAccountRole(AccountValue av, Collection rvs) throws Exception { + String result = null; + + setupCreate(); + // Submit the request to the service and store the response. + AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(av, rvs, true, true); + AccountRoleClient client = new AccountRoleClient(); + Response res = client.create(av.getAccountId(), accRole); + try { + assertStatusCode(res, "CreateAccountRole"); + result = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + return result; + } + + private void deleteAccountRole(AccountValue av, Collection rvs) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + AccountRoleClient client = new AccountRoleClient(); + AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(av, rvs, true, true); + Response res = client.delete(av.getAccountId()); + try { + assertStatusCode(res, "DeleteAccountRole"); + } finally { + if (res != null) { + res.close(); + } + } + } + + private String createPermissionRole(PermissionValue pv, Collection rvs) throws Exception { + String result = null; + + setupCreate(); + List rvls = new ArrayList(); + rvls.addAll(rvs); + PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(pv, rvls, true, true); + PermissionRoleClient client = new PermissionRoleClient(); + Response res = client.create(pv.getPermissionId(), permRole); + try { + assertStatusCode(res, "CreatePermissionRole"); + result = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + return result; + } + + private void deletePermissionRole(PermissionValue pv, Collection rvs) throws Exception { + List rvls = new ArrayList(); + rvls.addAll(rvs); + + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + PermissionRoleClient client = new PermissionRoleClient(); + PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(pv, rvls, true, true); + Response res = client.delete(pv.getPermissionId()); + try { + assertStatusCode(res, "DeletePermissionRole"); + } finally { + if (res != null) { + res.close(); + } + } + } @Override protected Class getCommonListType() { 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 9384ea8a4..e9b4efc2c 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 @@ -130,7 +130,7 @@ public class MultiTenancyTest extends BaseServiceTest { } @BeforeClass(alwaysRun = true) - public void seedData() { + public void seedData() throws Exception { //tenant admin users are used to create accounts, roles and permissions and relationships //assumption : two tenant admin users exist before running this test tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS)); @@ -143,12 +143,12 @@ public class MultiTenancyTest extends BaseServiceTest { seedPermissionRoles(); } - private void seedAccounts() { + private void seedAccounts() throws Exception { seedAccount(TENANT_1, TENANT_1_USER); seedAccount(TENANT_2, TENANT_2_USER); } - private void seedAccount(String tenantId, String userId) { + private void seedAccount(String tenantId, String userId) throws Exception { //create account using default user in admin role but assign tenant id //create username, email and password same for simplicity String accId = createAccount(tenantId, userId, userId); @@ -163,7 +163,7 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void seedPermissions() { + private void seedPermissions() throws Exception { String resource = TEST_SERVICE_A; PermissionAction pac = new PermissionAction(); @@ -187,7 +187,7 @@ public class MultiTenancyTest extends BaseServiceTest { } private void seedPermission(String tenantId, - String resource, List testActions, EffectType effect) { + String resource, List testActions, EffectType effect) throws Exception { //create permission using default user in admin role but assign tenant id String id = createPermission(tenantId, resource, testActions, effect); PermissionValue pv = new PermissionValue(); @@ -201,14 +201,14 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void seedRoles() { + private void seedRoles() throws Exception { //create role using default user in admin role but assign tenant id //use the same role name to check constraints seedRole(TENANT_1, TEST_ROLE_NAME); seedRole(TENANT_2, TEST_ROLE_NAME); } - private void seedRole(String tenantId, String roleName) { + private void seedRole(String tenantId, String roleName) throws Exception { String rid = createRole(tenantId, roleName); RoleValue rv = new RoleValue(); rv.setRoleId(rid); @@ -219,14 +219,14 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void seedAccountRoles() { + private void seedAccountRoles() throws Exception { for (String tenantId : tenantAccounts.keySet()) { AccountValue av = (AccountValue) tenantAccounts.get(tenantId); seedAccountRole(tenantId, av.getUserId()); } } - private void seedAccountRole(String tenantId, String userId) { + private void seedAccountRole(String tenantId, String userId) throws Exception { List tenantRoleValues = new ArrayList(); tenantRoleValues.add(tenantRoles.get(tenantId)); createAccountRole(tenantId, userAccounts.get(userId), tenantRoleValues); @@ -235,14 +235,14 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void seedPermissionRoles() { + private void seedPermissionRoles() throws Exception { for (String tenantId : tenantPermissions.keySet()) { PermissionValue pv = tenantPermissions.get(tenantId); seedPermissionRole(tenantId, pv.getPermissionId()); } } - private void seedPermissionRole(String tenantId, String permId) { + private void seedPermissionRole(String tenantId, String permId) throws Exception { List tenantRoleValues = new ArrayList(); tenantRoleValues.add(tenantRoles.get(tenantId)); PermissionValue pv = permValues.get(permId); @@ -300,7 +300,7 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private String create(String testName, String userName, String tenatnId) { + private String create(String testName, String userName, String tenatnId) throws Exception { String result = null; setupCreate(); @@ -499,7 +499,7 @@ public class MultiTenancyTest extends BaseServiceTest { // Utility methods used by tests above // --------------------------------------------------------------- @AfterClass(alwaysRun = true) - public void cleanUp() { + public void cleanUp() throws Exception { setupDelete(); String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { @@ -523,7 +523,7 @@ public class MultiTenancyTest extends BaseServiceTest { deleteAccounts(); } - private void deletePermissionRoles() { + private void deletePermissionRoles() throws Exception { for (String tenantId : tenantPermissions.keySet()) { List tenantRoleValues = new ArrayList(); tenantRoleValues.add(tenantRoles.get(tenantId)); @@ -532,7 +532,7 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void deleteAccountRoles() { + private void deleteAccountRoles() throws Exception { for (String tenantId : tenantAccounts.keySet()) { List tenantRoleValues = new ArrayList(); tenantRoleValues.add(tenantRoles.get(tenantId)); @@ -541,21 +541,21 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private void deletePermissions() { + private void deletePermissions() throws Exception { for (String tenantId : tenantPermissions.keySet()) { PermissionValue pv = tenantPermissions.get(tenantId); deletePermission(tenantId, pv.getPermissionId()); } } - private void deleteRoles() { + private void deleteRoles() throws Exception { for (String tenantId : tenantRoles.keySet()) { RoleValue rv = tenantRoles.get(tenantId); deleteRole(tenantId, rv.getRoleId()); } } - private void deleteAccounts() { + private void deleteAccounts() throws Exception { for (String tenantId : tenantAccounts.keySet()) { AccountValue av = tenantAccounts.get(tenantId); deleteAccount(tenantId, av.getAccountId()); @@ -563,7 +563,7 @@ public class MultiTenancyTest extends BaseServiceTest { } private String createPermission(String tenantId, String resName, - List actions, EffectType effect) { + List actions, EffectType effect) throws Exception { String result = null; setupCreate(); @@ -587,7 +587,7 @@ public class MultiTenancyTest extends BaseServiceTest { return result; } - private void deletePermission(String tenantId, String permId) { + private void deletePermission(String tenantId, String permId) throws Exception { setupDelete(); PermissionClient permClient = new PermissionClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -602,7 +602,7 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private String createRole(String tenantId, String roleName) { + private String createRole(String tenantId, String roleName) throws Exception { String result = null; setupCreate(); @@ -626,7 +626,7 @@ public class MultiTenancyTest extends BaseServiceTest { return result; } - private void deleteRole(String tenantId, String roleId) { + private void deleteRole(String tenantId, String roleId) throws Exception { setupDelete(); RoleClient roleClient = new RoleClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -641,7 +641,7 @@ public class MultiTenancyTest extends BaseServiceTest { } } - private String createAccount(String tenantId, String userName, String email) { + private String createAccount(String tenantId, String userName, String email) throws Exception { String result = null; setupCreate(); @@ -664,7 +664,7 @@ public class MultiTenancyTest extends BaseServiceTest { return result; } - private void deleteAccount(String tenantId, String accId) { + private void deleteAccount(String tenantId, String accId) throws Exception { setupDelete(); AccountClient accClient = new AccountClient(); UserInfo ui = tenantAdminUsers.get(tenantId); @@ -680,7 +680,7 @@ public class MultiTenancyTest extends BaseServiceTest { } private String createAccountRole(String tenantId, AccountValue av, - Collection rvs) { + Collection rvs) throws Exception { String result = null; setupCreate(); @@ -704,7 +704,7 @@ public class MultiTenancyTest extends BaseServiceTest { } private void deleteAccountRole(String tenantId, AccountValue av, - List rvs) { + List rvs) throws Exception { // Perform setup. setupDelete(); @@ -725,7 +725,7 @@ public class MultiTenancyTest extends BaseServiceTest { } private String createPermissionRole(String tenantId, PermissionValue pv, - Collection rvs) { + Collection rvs) throws Exception { String result = null; setupCreate(); @@ -749,7 +749,7 @@ public class MultiTenancyTest extends BaseServiceTest { return result; } - private void deletePermissionRole(String tenantId, PermissionValue pv, List rvls) { + private void deletePermissionRole(String tenantId, PermissionValue pv, List rvls) throws Exception { // Perform setup. setupDelete(); diff --git a/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java index 09eb8e1ae..391b80953 100644 --- a/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java +++ b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java @@ -33,11 +33,11 @@ public class ServiceGroupClient extends AbstractCommonListPoxServiceClientImpl } @Override - protected CollectionSpaceClient getClientInstance() { + protected CollectionSpaceClient getClientInstance() throws Exception { return new ServiceGroupClient(); } @Override - protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { return new ServiceGroupClient(clientPropertiesFilename); } diff --git a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java index 1e5841a34..76e9a9b87 100644 --- a/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java +++ b/services/taxonomy/client/src/main/java/org/collectionspace/services/client/TaxonomyAuthorityClient.java @@ -55,11 +55,11 @@ public class TaxonomyAuthorityClient extends AuthorityClientImpl getClientInstance() { + protected CollectionSpaceClient getClientInstance() throws Exception { return new TaxonomyAuthorityClient(); } @Override - protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) { + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { return new TaxonomyAuthorityClient(clientPropertiesFilename); } @@ -280,9 +279,10 @@ public class TaxonomyAuthorityServiceTest extends AbstractAuthorityServiceTest vocabItemInfo = new HashMap(); String shortId = identifier; @@ -396,7 +396,7 @@ public class VocabularyServiceTest extends AbstractAuthorityServiceTest