From e5d7206b7eeec6266a4fcaa2e6aed0100db03c40 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Mon, 10 May 2010 23:24:39 +0000 Subject: [PATCH] CSPACE-1482 scaffolding for authorization tests, creates and deletes accounts, roles, permissions, account-role and permission-role relationships. yet to put tests that test permissions created refactoring of collectionobject, accountrole and permissionrole tests, extracted out factories added releaseConnection on the test in this checkin test: security/client M services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java A services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java M services/collectionobject/client/pom.xml M services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java M services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java M services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java A services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java M services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java A services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java D services/security/client/src/test/java/org/collectionspace/services/authentication/client/test/AuthenticationServiceTest.java A services/security/client/src/test/java/org/collectionspace/services/security A services/security/client/src/test/java/org/collectionspace/services/security/client A services/security/client/src/test/java/org/collectionspace/services/security/client/test A + services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java M services/security/client/src/test/resources/log4j.properties M services/security/client/pom.xml --- .../services/client/AccountRoleFactory.java | 78 ++++++++++++++++ .../client/test/AccountRoleServiceTest.java | 93 +++++++++---------- .../client/PermissionRoleFactory.java | 75 +++++++++++++++ .../test/PermissionRoleServiceTest.java | 35 +++---- .../client/test/PermissionServiceTest.java | 2 +- .../client/test/RoleServiceTest.java | 2 +- services/collectionobject/client/pom.xml | 2 - .../client/CollectionObjectFactory.java | 83 +++++++++++++++++ .../test/CollectionObjectServiceTest.java | 11 +-- services/security/client/pom.xml | 6 +- .../test/AuthenticationServiceTest.java | 26 ++++-- .../src/test/resources/log4j.properties | 2 +- 12 files changed, 321 insertions(+), 94 deletions(-) create mode 100644 services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java create mode 100644 services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java create mode 100644 services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java rename services/security/client/src/test/java/org/collectionspace/services/{authentication => security}/client/test/AuthenticationServiceTest.java (97%) diff --git a/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java new file mode 100644 index 000000000..b0c5c37a8 --- /dev/null +++ b/services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java @@ -0,0 +1,78 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.collectionspace.services.client; + +import java.util.ArrayList; +import java.util.Collection; +import org.collectionspace.services.authorization.AccountRole; +import org.collectionspace.services.authorization.AccountValue; +import org.collectionspace.services.authorization.RoleValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class AccountRoleFactory { + static private final Logger logger = LoggerFactory.getLogger(AccountRoleFactory.class); + + /** + * Creates the account role instance. + * + * @param pv the pv + * @param rvs the rvs + * @param usePermId the use perm id + * @param useRoleId the use role id + * @return the account role + */ + static public AccountRole createAccountRoleInstance(AccountValue pv, + Collection rvs, + boolean usePermId, + boolean useRoleId) { + + AccountRole accRole = new AccountRole(); + //service consume is not required to provide subject as it is determined + //from URI used +// accRole.setSubject(SubjectType.ROLE); + if (usePermId) { + ArrayList pvs = new ArrayList(); + pvs.add(pv); + accRole.setAccounts(pvs); + } + if (useRoleId) { + //FIXME is there a better way? + ArrayList rvas = new ArrayList(); + for (RoleValue rv : rvs) { + rvas.add(rv); + } + accRole.setRoles(rvas); + } + + return accRole; + } + + +} 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 569e537a0..d2f9d65b0 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 @@ -36,6 +36,7 @@ import org.collectionspace.services.authorization.RoleValue; import org.collectionspace.services.client.AccountClient; import org.collectionspace.services.client.AccountFactory; import org.collectionspace.services.client.AccountRoleClient; +import org.collectionspace.services.client.AccountRoleFactory; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.RoleClient; import org.collectionspace.services.client.RoleFactory; @@ -80,19 +81,19 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { @BeforeClass(alwaysRun = true) public void seedData() { - String ra = "acc-role-user1"; - String accId = createAccount(ra, "acc-role-test@cspace.org"); + String userId = "acc-role-user1"; + String accId = createAccount(userId, "acc-role-test@cspace.org"); AccountValue ava = new AccountValue(); - ava.setScreenName(ra); - ava.setUserId(ra); + ava.setScreenName(userId); + ava.setUserId(userId); ava.setAccountId(accId); accValues.put(ava.getScreenName(), ava); - String rc = "acc-role-user2"; - String coAccId = createAccount(rc, "acc-role-test@cspace.org"); + String userId2 = "acc-role-user2"; + String coAccId = createAccount(userId2, "acc-role-test@cspace.org"); AccountValue avc = new AccountValue(); - avc.setScreenName(rc); - avc.setUserId(rc); + avc.setScreenName(userId2); + avc.setUserId(userId2); avc.setAccountId(coAccId); accValues.put(avc.getScreenName(), avc); @@ -124,25 +125,25 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { */ @Override protected CollectionSpaceClient getClientInstance() { - return new AccountRoleClient(); + return new AccountRoleClient(); } - + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) */ @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - throw new UnsupportedOperationException(); + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + throw new UnsupportedOperationException(); } - - @Test(dataProvider = "testName") - @Override + + @Test(dataProvider = "testName") + @Override public void readPaginatedList(String testName) throws Exception { - //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 - } - + //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697 + } + // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -178,6 +179,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } + res.releaseConnection(); } //to not cause uniqueness violation for accRole, createList is removed @@ -185,7 +187,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { dependsOnMethods = {"create"}) @Override public void createList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes @@ -193,17 +195,17 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // See Issue CSPACE-401. @Override public void createWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } @Override public void createWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } @Override public void createWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // --------------------------------------------------------------- @@ -235,6 +237,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { AccountRole output = (AccountRole) res.getEntity(); Assert.assertNotNull(output); + res.releaseConnection(); } // Failure outcomes @@ -258,6 +261,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } // --------------------------------------------------------------- @@ -268,7 +272,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"}) public void readList(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes @@ -281,7 +285,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read", "readList", "readNonExistent"}) public void update(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // Failure outcomes @@ -289,24 +293,24 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { // See Issue CSPACE-401. @Override public void updateWithEmptyEntityBody(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } @Override public void updateWithMalformedXml(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } @Override public void updateWithWrongXmlSchema(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } @Override @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"readNonExistent", "testSubmitRequest"}) public void updateNonExistent(String testName) throws Exception { - //FIXME: Should this test really be empty? If so, please comment accordingly. + //FIXME: Should this test really be empty? If so, please comment accordingly. } // --------------------------------------------------------------- @@ -335,6 +339,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } // Failure outcomes @@ -393,23 +398,8 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { boolean usePermId, boolean useRoleId) { - AccountRole accRole = new AccountRole(); - //service consume is not required to provide subject as it is determined - //from URI used -// accRole.setSubject(SubjectType.ROLE); - if (usePermId) { - ArrayList pvs = new ArrayList(); - pvs.add(pv); - accRole.setAccounts(pvs); - } - if (useRoleId) { - //FIXME is there a better way? - ArrayList rvas = new ArrayList(); - for (RoleValue rv : rvs) { - rvas.add(rv); - } - accRole.setRoles(rvas); - } + AccountRole accRole = AccountRoleFactory.createAccountRoleInstance( + pv, rvs, usePermId, useRoleId); if (logger.isDebugEnabled()) { logger.debug("to be created, accRole common"); @@ -422,12 +412,12 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { public void cleanUp() { setupDelete("delete"); String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } @@ -443,6 +433,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } for (AccountValue pv : accValues.values()) { @@ -469,6 +460,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); return extractId(res); } @@ -484,6 +476,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } private String createRole(String roleName) { @@ -501,6 +494,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); return extractId(res); } @@ -516,5 +510,6 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } } diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java new file mode 100644 index 000000000..8797e1e5d --- /dev/null +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java @@ -0,0 +1,75 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client; + + +import java.util.ArrayList; +import java.util.Collection; +import org.collectionspace.services.authorization.PermissionRole; +import org.collectionspace.services.authorization.PermissionValue; +import org.collectionspace.services.authorization.RoleValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class PermissionRoleFactory { + + static private final Logger logger = LoggerFactory.getLogger(PermissionRoleFactory.class); + /** + * create permRolerole instance + * @param permId + * @param roleValues array of role ids + * @param userPermId + * @param useRoleId + * @return + */ + public static PermissionRole createPermissionRoleInstance(PermissionValue pv, + Collection rvs, + boolean usePermId, + boolean useRoleId) { + + PermissionRole permRole = new PermissionRole(); + //service consume is not required to provide subject as it is determined + //from URI used +// permRole.setSubject(SubjectType.ROLE); + if (usePermId) { + ArrayList pvs = new ArrayList(); + pvs.add(pv); + permRole.setPermissions(pvs); + } + if (useRoleId) { + //FIXME is there a better way? + ArrayList rvas = new ArrayList(); + for (RoleValue rv : rvs) { + rvas.add(rv); + } + permRole.setRoles(rvas); + } + + return permRole; + } +} 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 24318d2ec..d280004b0 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 @@ -39,6 +39,7 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PermissionClient; import org.collectionspace.services.client.PermissionFactory; import org.collectionspace.services.client.PermissionRoleClient; +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; @@ -168,7 +169,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - + res.releaseConnection(); // Store the ID returned from this create operation // for additional tests below. //this is is not important in case of this relationship @@ -229,6 +230,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { PermissionRole output = (PermissionRole) res.getEntity(); Assert.assertNotNull(output); + res.releaseConnection(); } // Failure outcomes @@ -252,6 +254,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } // --------------------------------------------------------------- @@ -323,6 +326,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } // Failure outcomes @@ -359,6 +363,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { } Assert.assertEquals(statusCode, EXPECTED_STATUS); + } // --------------------------------------------------------------- @@ -377,26 +382,10 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { boolean usePermId, boolean useRoleId) { - PermissionRole permRole = new PermissionRole(); - //service consume is not required to provide subject as it is determined - //from URI used -// permRole.setSubject(SubjectType.ROLE); - if (usePermId) { - ArrayList pvs = new ArrayList(); - pvs.add(pv); - permRole.setPermissions(pvs); - } - if (useRoleId) { - //FIXME is there a better way? - ArrayList rvas = new ArrayList(); - for (RoleValue rv : rvs) { - rvas.add(rv); - } - permRole.setRoles(rvas); - } - + PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance( + pv, rvs, usePermId, useRoleId); if (logger.isDebugEnabled()) { - logger.debug("to be created, permRole common"); + logger.debug("to be created, permRole"); logger.debug(objectAsXmlString(permRole, PermissionRole.class)); } return permRole; @@ -427,7 +416,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { setupCreate(); PermissionClient permClient = new PermissionClient(); List actions = PermissionFactory.createDefaultActions(); - Permission permission = PermissionServiceTest.createPermissionInstance(resName, + Permission permission = PermissionFactory.createPermissionInstance(resName, "default permissions for " + resName, actions, effect, true, true, true); ClientResponse res = permClient.create(permission); @@ -439,6 +428,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); return extractId(res); } @@ -454,6 +444,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } private String createRole(String roleName) { @@ -471,6 +462,7 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); return extractId(res); } @@ -486,5 +478,6 @@ public class PermissionRoleServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res.releaseConnection(); } } diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java index bf0c00ae6..2ced44926 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java @@ -611,7 +611,7 @@ public class PermissionServiceTest extends AbstractServiceTestImpl { useResourceName, useAction, useEffect); if (logger.isDebugEnabled()) { - logger.debug("to be created, permission common"); + logger.debug("to be created, permission"); logger.debug(objectAsXmlString(permission, Permission.class)); } return permission; diff --git a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java index 292c541c5..697faa1a8 100644 --- a/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java +++ b/services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java @@ -548,7 +548,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl { Role role = RoleFactory.createRoleInstance(roleName, description, useRoleName); if (logger.isDebugEnabled()) { - logger.debug("to be created, role common"); + logger.debug("to be created, role"); logger.debug(objectAsXmlString(role, Role.class)); } return role; diff --git a/services/collectionobject/client/pom.xml b/services/collectionobject/client/pom.xml index f4af6b07b..60054348c 100644 --- a/services/collectionobject/client/pom.xml +++ b/services/collectionobject/client/pom.xml @@ -18,12 +18,10 @@ org.slf4j slf4j-api - test org.slf4j slf4j-log4j12 - test diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java new file mode 100644 index 000000000..a5587eb3e --- /dev/null +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java @@ -0,0 +1,83 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.collectionspace.services.client; + +import javax.ws.rs.core.MediaType; +import org.collectionspace.services.collectionobject.CollectionobjectsCommon; +import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class CollectionObjectFactory { + static private final Logger logger = LoggerFactory.getLogger(CollectionObjectFactory.class); + + /** + * create account instance + * @param screenName + * @param userName + * @param passwd + * @param email + * @param useScreenName + * @param addTenant + * @param invalidTenant + * @param useUser + * @param usePassword + * @return + */ + + /** + * Creates the collection object instance. + * + * @param commonPartName the common part name + * @param collectionObject the collection object + * @param nhPartname natural history part name + * @param conh the conh + * @return the multipart output + */ + public static MultipartOutput createCollectionObjectInstance(String commonPartName, + CollectionobjectsCommon collectionObject, + String nhPartName, CollectionobjectsNaturalhistory conh) { + + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(collectionObject, + MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", commonPartName); + + if (conh != null) { + OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE); + nhPart.getHeaders().add("label", nhPartName); + } + return multipart; + + } + + +} diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index f993942db..5b645d0e1 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -29,6 +29,7 @@ import javax.ws.rs.core.Response; //import org.collectionspace.services.client.AbstractServiceClientImpl; import org.collectionspace.services.client.CollectionObjectClient; +import org.collectionspace.services.client.CollectionObjectFactory; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory; @@ -1082,11 +1083,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { private MultipartOutput createCollectionObjectInstance(String commonPartName, CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) { - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(collectionObject, - MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", commonPartName); - + MultipartOutput multipart = CollectionObjectFactory.createCollectionObjectInstance( + commonPartName, collectionObject, getNHPartName(), conh); if (logger.isDebugEnabled()) { logger.debug("to be created, collectionobject common"); logger.debug(objectAsXmlString(collectionObject, @@ -1094,9 +1092,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { } if (conh != null) { - OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE); - nhPart.getHeaders().add("label", getNHPartName()); - if (logger.isDebugEnabled()) { logger.debug("to be created, collectionobject nhistory"); logger.debug(objectAsXmlString(conh, diff --git a/services/security/client/pom.xml b/services/security/client/pom.xml index fded08294..6dac20c73 100644 --- a/services/security/client/pom.xml +++ b/services/security/client/pom.xml @@ -12,7 +12,7 @@ org.collectionspace.services org.collectionspace.services.security.client services.security.client - + @@ -34,12 +34,12 @@ org.collectionspace.services - org.collectionspace.services.authentication.client + org.collectionspace.services.account.client ${project.version} org.collectionspace.services - org.collectionspace.services.account.client + org.collectionspace.services.authorization-mgt.client ${project.version} diff --git a/services/security/client/src/test/java/org/collectionspace/services/authentication/client/test/AuthenticationServiceTest.java b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java similarity index 97% rename from services/security/client/src/test/java/org/collectionspace/services/authentication/client/test/AuthenticationServiceTest.java rename to services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java index 7a84785be..f47b5fe0e 100644 --- a/services/security/client/src/test/java/org/collectionspace/services/authentication/client/test/AuthenticationServiceTest.java +++ b/services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java @@ -20,17 +20,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.collectionspace.services.authentication.client.test; +package org.collectionspace.services.security.client.test; import java.util.List; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; //import org.apache.commons.codec.binary.Base64; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.Test; @@ -42,6 +40,7 @@ import org.collectionspace.services.account.Status; import org.collectionspace.services.client.AccountFactory; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.client.CollectionObjectClient; +import org.collectionspace.services.client.CollectionObjectFactory; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.test.AbstractServiceTestImpl; import org.collectionspace.services.client.test.BaseServiceTest; @@ -132,6 +131,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": barneyAccountId=" + barneyAccountId); } + res.releaseConnection(); } @@ -168,7 +168,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testName + ": georgeAccountId=" + georgeAccountId); } - + res.releaseConnection(); //deactivate setupUpdate(testName); account.setStatus(Status.INACTIVE); @@ -188,6 +188,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + res1.releaseConnection(); } @@ -228,6 +229,8 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { // Store the ID returned from this create operation for additional tests // below. knownResourceId = extractId(res); + res.releaseConnection(); + } @Test(dataProvider = "testName", dependsOnMethods = {"createInactiveAccount"}) @@ -258,6 +261,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(res.getStatus(), Response.Status.FORBIDDEN.getStatusCode(), "expected " + Response.Status.FORBIDDEN.getStatusCode()); + res.releaseConnection(); } /** @@ -288,6 +292,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": status = " + res.getStatus()); } Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode()); + res.releaseConnection(); } /** @@ -319,6 +324,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": status = " + res.getStatus()); } Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode()); + res.releaseConnection(); } /** @@ -350,6 +356,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": status = " + res.getStatus()); } Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode()); + res.releaseConnection(); } /** @@ -382,6 +389,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { + res.getStatus()); } Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode()); + res.releaseConnection(); } /** @@ -414,6 +422,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { + res.getStatus()); } Assert.assertEquals(res.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "expected " + Response.Status.UNAUTHORIZED.getStatusCode()); + res.releaseConnection(); } /* (non-Javadoc) @@ -449,6 +458,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } Assert.assertEquals(res.getStatus(), Response.Status.OK.getStatusCode(), "expected " + Response.Status.OK.getStatusCode()); + res.releaseConnection(); } @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, @@ -481,6 +491,7 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { } Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + res.releaseConnection(); } // --------------------------------------------------------------- @@ -514,10 +525,9 @@ public class AuthenticationServiceTest extends AbstractServiceTestImpl { collectionObject.setObjectNumber(objectNumber); collectionObject.setObjectName(objectName); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(collectionObject, - MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", commonPartName); + MultipartOutput multipart = + CollectionObjectFactory.createCollectionObjectInstance( + commonPartName, collectionObject, null, null); if (logger.isDebugEnabled()) { logger.debug("to be created, collectionobject common ", diff --git a/services/security/client/src/test/resources/log4j.properties b/services/security/client/src/test/resources/log4j.properties index 5d288d87d..18c510350 100644 --- a/services/security/client/src/test/resources/log4j.properties +++ b/services/security/client/src/test/resources/log4j.properties @@ -20,4 +20,4 @@ log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n log4j.logger.org.collectionspace=DEBUG log4j.logger.org.apache=INFO log4j.logger.httpclient=INFO -log4j.logger.org.jboss.resteasy=WARN +log4j.logger.org.jboss.resteasy=INFO -- 2.47.3