]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1482 scaffolding for authorization tests, creates and deletes accounts, roles...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 10 May 2010 23:24:39 +0000 (23:24 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 10 May 2010 23:24:39 +0000 (23:24 +0000)
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

12 files changed:
services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleFactory.java [new file with mode: 0644]
services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java
services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/PermissionRoleFactory.java [new file with mode: 0644]
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionRoleServiceTest.java
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/PermissionServiceTest.java
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java
services/collectionobject/client/pom.xml
services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectFactory.java [new file with mode: 0644]
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/security/client/pom.xml
services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java [moved from services/security/client/src/test/java/org/collectionspace/services/authentication/client/test/AuthenticationServiceTest.java with 97% similarity]
services/security/client/src/test/resources/log4j.properties

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 (file)
index 0000000..b0c5c37
--- /dev/null
@@ -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<RoleValue> 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<AccountValue> pvs = new ArrayList<AccountValue>();
+            pvs.add(pv);
+            accRole.setAccounts(pvs);
+        }
+        if (useRoleId) {
+            //FIXME is there a better way?
+            ArrayList<RoleValue> rvas = new ArrayList<RoleValue>();
+            for (RoleValue rv : rvs) {
+                rvas.add(rv);
+            }
+            accRole.setRoles(rvas);
+        }
+
+        return accRole;
+    }
+
+
+}
index 569e537a0e55112c28469de5d7e0574385a5886b..d2f9d65b04dbd859ca1968257984e1b99b8cf50c 100644 (file)
@@ -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<AbstractCommonList> response) {
-       //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
-       throw new UnsupportedOperationException();
+    protected AbstractCommonList getAbstractCommonList(
+            ClientResponse<AbstractCommonList> 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<AccountValue> pvs = new ArrayList<AccountValue>();
-            pvs.add(pv);
-            accRole.setAccounts(pvs);
-        }
-        if (useRoleId) {
-            //FIXME is there a better way?
-            ArrayList<RoleValue> rvas = new ArrayList<RoleValue>();
-            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 (file)
index 0000000..8797e1e
--- /dev/null
@@ -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<RoleValue> 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<PermissionValue> pvs = new ArrayList<PermissionValue>();
+            pvs.add(pv);
+            permRole.setPermissions(pvs);
+        }
+        if (useRoleId) {
+            //FIXME is there a better way?
+            ArrayList<RoleValue> rvas = new ArrayList<RoleValue>();
+            for (RoleValue rv : rvs) {
+                rvas.add(rv);
+            }
+            permRole.setRoles(rvas);
+        }
+
+        return permRole;
+    }
+}
index 24318d2ec6e37a490a9c17b41f52a3bc95ef4fd2..d280004b04a57b52a9045e83f8070d26b5ae2e15 100644 (file)
@@ -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<PermissionValue> pvs = new ArrayList<PermissionValue>();
-            pvs.add(pv);
-            permRole.setPermissions(pvs);
-        }
-        if (useRoleId) {
-            //FIXME is there a better way?
-            ArrayList<RoleValue> rvas = new ArrayList<RoleValue>();
-            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<PermissionAction> actions = PermissionFactory.createDefaultActions();
-        Permission permission = PermissionServiceTest.createPermissionInstance(resName,
+        Permission permission = PermissionFactory.createPermissionInstance(resName,
                 "default permissions for " + resName,
                 actions, effect, true, true, true);
         ClientResponse<Response> 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();
     }
 }
index bf0c00ae66f73f592c5fdf56f9a8a85cbf95fc7f..2ced449268009080364e28f855573fc598e99647 100644 (file)
@@ -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;
index 292c541c5dfc0ff28a92a10c5e378f0acc850c25..697faa1a8aed0c9d1fcecb418f2d56197616febf 100644 (file)
@@ -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;
index f4af6b07b1f4f61adaf18a2c17afb90cda042456..60054348ce34f409418a2957bae0494fffdba635 100644 (file)
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-api</artifactId>\r
-            <scope>test</scope>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-log4j12</artifactId>\r
-            <scope>test</scope>\r
         </dependency>\r
         <!-- CollectionSpace dependencies -->\r
         <dependency>\r
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 (file)
index 0000000..a5587eb
--- /dev/null
@@ -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;
+
+    }
+
+
+}
index f993942dbcc62e480b64b165e57bf5eb9d3d3bdf..5b645d0e1baaf27f0a38944487a02d0a7435613a 100644 (file)
@@ -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,
index fded08294cb8895f1961eb001d0cd648495b93eb..6dac20c73de450e1c985937d368ee33278f13203 100644 (file)
@@ -12,7 +12,7 @@
     <groupId>org.collectionspace.services</groupId>\r
     <artifactId>org.collectionspace.services.security.client</artifactId>\r
     <name>services.security.client</name>\r
-    \r
+\r
     <dependencies>\r
         <!-- keep slf4j dependencies on the top -->\r
         <dependency>\r
         <!-- authentication tests use CollectionObject service and Account service -->\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.authentication.client</artifactId>\r
+            <artifactId>org.collectionspace.services.account.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.account.client</artifactId>\r
+            <artifactId>org.collectionspace.services.authorization-mgt.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
         <dependency>\r
  *  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 ",
index 5d288d87d8e3024d3b87bf197cb5fab920725791..18c510350fd16aa0b59d63d387ee5634a4d3fea1 100644 (file)
@@ -20,4 +20,4 @@ log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n
 log4j.logger.org.collectionspace=DEBUG\r
 log4j.logger.org.apache=INFO\r
 log4j.logger.httpclient=INFO\r
-log4j.logger.org.jboss.resteasy=WARN\r
+log4j.logger.org.jboss.resteasy=INFO\r