]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3442: Added /roles/{csid}/accountroles/ resource to the "authorization" servic...
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 5 Oct 2011 22:17:03 +0000 (22:17 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 5 Oct 2011 22:17:03 +0000 (22:17 +0000)
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/RoleClient.java
services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleProxy.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java

index 159e0f4049f5b044cb9382897215578c2f6a6aaa..0a1485124e166e3e3660ef15b444a916f36a5273 100644 (file)
@@ -348,6 +348,72 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
             res.releaseConnection();
         }
     }
+    
+    /*
+     * In this test, for setup, we associate both test roles ("ROLE_CO1", "ROLE_CO2") with the test account "acc-role-user2".
+     * After we've performed this setup, our call to "/role/{csid}/accountroles" should contain an AccountRole that has
+     * a list of 1 account -the test user account we associated during setup.
+     */
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+           dependsOnMethods = {"delete"})
+    public void readRoleAccounts(String testName) throws Exception {
+
+        if (logger.isDebugEnabled()) {
+            testBanner(testName, CLASS_NAME);
+        }
+
+               /*
+                * Setup a temp local scope for local variables that we need to create the AccountRole for
+                * the setup of the read tests.
+                */
+        {
+               setupCreate();
+
+               // Associate "acc-role-user2" with all the roles.
+               AccountValue av = accValues.get("acc-role-user2");
+               AccountRole accRole = createAccountRoleInstance(av,
+                       roleValues.values(), true, true);
+               AccountRoleClient client = new AccountRoleClient();
+               ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
+               int statusCode = res.getStatus();
+               Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                       invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+               Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        }
+
+        //
+        // Now read the list of accounts associated with the role "ROLE_CO1".
+        // There should be just the "acc-role-user2" account.
+        //
+        setupRead();        
+        RoleClient roleClient = new RoleClient();
+        
+        // Submit the request to the service and store the response.
+        ClientResponse<AccountRole> res = roleClient.readRoleAccounts(
+                       roleValues.get("ROLE_CO1").getRoleId());
+        int statusCode = res.getStatus();
+        try {
+            // Check the status code of the response: does it match
+            // the expected response(s)?
+            if (logger.isDebugEnabled()) {
+                logger.debug(testName + ": status = " + statusCode);
+            }
+            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+            AccountRole output = res.getEntity();
+            
+            // Now verify that the role has 2 accounts associate to it.
+            Assert.assertEquals(output.getAccounts().size(), 1);
+
+            String sOutput = objectAsXmlString(output, AccountRole.class);
+            if(logger.isDebugEnabled()) {
+                logger.debug(testName + " received " + sOutput);
+            }
+        } finally {
+            res.releaseConnection();
+        }
+    }    
 
     // ---------------------------------------------------------------
     // CRUD tests : READ_LIST tests
index 1d888e91823523d6b638de7950757bf237ba46c9..78d1f48de99caa1630b668506820b9433e1d98ca 100644 (file)
@@ -29,6 +29,7 @@ package org.collectionspace.services.client;
 import javax.ws.rs.core.Response;
 
 
+import org.collectionspace.services.authorization.AccountRole;
 import org.collectionspace.services.authorization.Role;
 import org.collectionspace.services.authorization.RolesList;
 import org.jboss.resteasy.client.ClientResponse;
@@ -71,6 +72,10 @@ public class RoleClient extends AbstractServiceClientImpl<RolesList, RoleProxy>
     public ClientResponse<Role> read(String csid) {
         return getProxy().read(csid);
     }
+    
+    public ClientResponse<AccountRole> readRoleAccounts(String csid) {
+       return getProxy().readRoleAccounts(csid);
+    }
 
     /**
      * Creates the.
index 8360bee9526603bf3a5bad71ac5ec267c7c14724..176b764f40a562c75bfab40eaedd1674301db82a 100644 (file)
@@ -37,6 +37,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
 
+import org.collectionspace.services.authorization.AccountRole;
 import org.collectionspace.services.authorization.Role;
 import org.collectionspace.services.authorization.RolesList;
 import org.jboss.resteasy.client.ClientResponse;
@@ -64,6 +65,11 @@ public interface RoleProxy extends CollectionSpaceProxy<RolesList> {
     @GET
     @Path("/{csid}")
     ClientResponse<Role> read(@PathParam("csid") String csid);
+    
+    //(R)ead accounts associate with this role
+    @GET
+    @Path("{csid}/accountroles")
+    ClientResponse<AccountRole> readRoleAccounts(@PathParam("csid") String csid);
 
     //(U)pdate
     @PUT
index 7a8d04bc934b8221a74c53fbc309b88d822254a7..8bbd027a9703e6821a9ffd6ea4cc9a9dcfeae8ac 100644 (file)
@@ -95,6 +95,28 @@ public class RoleResource extends SecurityResourceBase {
     public Role getRole(@PathParam("csid") String csid) {
         return (Role)get(csid, Role.class);
     }
+    
+    /*
+     * Get a list of accounts associated with this role.
+     */
+    @GET
+    @Path("{csid}/accountroles")
+    public AccountRole getRoleAccounts(
+            @PathParam("csid") String accCsid) {
+        logger.debug("getAccountRole with accCsid=" + accCsid);
+        ensureCSID(accCsid, ServiceMessages.GET_FAILED+ "accountroles role ");
+        AccountRole result = null;
+        try {
+            AccountRoleSubResource subResource =
+                    new AccountRoleSubResource(AccountRoleSubResource.ACCOUNT_ACCOUNTROLE_SERVICE);
+            //get relationships for a role
+            result = subResource.getAccountRole(accCsid, SubjectType.ACCOUNT);
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.GET_FAILED, accCsid);
+        }
+        checkResult(result, accCsid, ServiceMessages.GET_FAILED);
+        return result;
+    }
 
     @GET
     @Produces("application/xml")