]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1649 partial update for permission fixed to take into account the action list
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 29 Apr 2010 00:32:17 +0000 (00:32 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 29 Apr 2010 00:32:17 +0000 (00:32 +0000)
minor messages fixes
test: authorization-mgt (added updateactions test), service tests

M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java
M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java
M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java
M    services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java
M    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/PermissionServiceTest.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java

index 24a1e5e8f00f8ab24858286dbb040d726f3cd4fc..bd4de6a24771e673e32e22ae2f024656fb3a1b21 100644 (file)
@@ -375,9 +375,57 @@ public class PermissionServiceTest extends AbstractServiceTestImpl {
                 "Data in updated object did not match submitted data.");
     }
 
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"update"})
+    public void updateActions(String testName) throws Exception {
+
+        // Perform setup.
+        setupUpdate(testName);
+
+        Permission permToUpdate = new Permission();
+        permToUpdate.setCsid(knownResourceId);
+        // Update the content of this resource.
+        List<PermissionAction> actions = PermissionFactory.createDefaultActions();
+        int default_actions = actions.size();
+        actions.remove(0);
+        actions.remove(0);
+        int toUpdate_actions = actions.size();
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + " no. of actions default=" + default_actions
+                    + " to update =" + toUpdate_actions);
+        }
+        permToUpdate.setActions(actions);
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + " updated object\n"
+                    + objectAsXmlString(permToUpdate, Permission.class));
+        }
+        PermissionClient client = new PermissionClient();
+        // Submit the request to the service and store the response.
+        ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
+        int statusCode = res.getStatus();
+        // Check the status code of the response: does it match the expected response(s)?
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+        Permission permUpdated = (Permission) res.getEntity();
+        Assert.assertNotNull(permUpdated);
+        int updated_actions = permToUpdate.getActions().size();
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + " no. of actions to update=" + toUpdate_actions
+                    + " updated =" + updated_actions);
+        }
+        Assert.assertEquals(toUpdate_actions,
+                updated_actions,
+                "Data in updated object did not match submitted data.");
+    }
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
+
     @Override
     public void updateWithEmptyEntityBody(String testName) throws Exception {
     }
@@ -431,7 +479,7 @@ public class PermissionServiceTest extends AbstractServiceTestImpl {
     // Success outcomes
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
-    dependsOnMethods = {"update"})
+    dependsOnMethods = {"updateActions"})
     public void delete(String testName) throws Exception {
 
         // Perform setup.
@@ -537,17 +585,16 @@ public class PermissionServiceTest extends AbstractServiceTestImpl {
         return permission;
     }
 
-
     @AfterClass(alwaysRun = true)
     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 ...");
         }
index 328205a9f76700266221669ce4857c0180d0add7..8a266d0ca183c883f139f0d7134282f3d1c785df 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.UUID;
 
 import org.collectionspace.services.authorization.Permission;
+import org.collectionspace.services.authorization.PermissionAction;
 import org.collectionspace.services.authorization.PermissionsList;
 
 import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;
@@ -88,8 +89,11 @@ public class PermissionDocumentHandler
         if (from.getEffect() != null) {
             to.setEffect(from.getEffect());
         }
-
-        //fixme update on actions
+        List<PermissionAction> fromActions = from.getActions();
+        if(!fromActions.isEmpty()) {
+            //override the whole list, no reconcilliation by design
+            to.setActions(fromActions);
+        }
 
         if (logger.isDebugEnabled()) {
             logger.debug("merged permission=" + JaxbUtils.toString(to, Permission.class));
index 5f5da1cdcc92a8b40155d0847c1a7c8d8e747e30..8fc460f121521285a49c43c410e59dd598a436ab 100644 (file)
@@ -57,13 +57,13 @@ public class PermissionValidatorHandler implements ValidatorHandler {
                 //create specific validation here
                 if (permission.getResourceName() == null || permission.getResourceName().isEmpty()) {
                     invalid = true;
-                    msgBldr.append("\npermissionName : missing");
+                    msgBldr.append("\nresourceName : missing or empty");
                 }
             } else if (action.equals(Action.UPDATE)) {
                 //update specific validation here
                 if (permission.getResourceName() != null && permission.getResourceName().isEmpty()) {
                     invalid = true;
-                    msgBldr.append("\npermissionName : cannot be changed!");
+                    msgBldr.append("\nresourceName : cannot be empty");
                 }
             }
             if (invalid) {
index 08788cf2e99529899f06a8ed95ab0dbb6fc6dc13..c55b5c4e68a995c973d68f698f1ad27afe38034a 100644 (file)
@@ -54,6 +54,8 @@ public class RoleDocumentHandler
         String id = UUID.randomUUID().toString();
         Role role = wrapDoc.getWrappedObject();
         role.setCsid(id);
+        //FIXME: if admin updating the role is a CS admin rather than
+        //the tenant admin, tenant id should be retrieved from the request
         role.setTenantId(getServiceContext().getTenantId());
     }
 
index 70dbb1c21540a9aa3f745639f83c020b4107cec2..71533a90934c259ed43ab7cbe6eeb3193f0c9082 100644 (file)
@@ -58,13 +58,13 @@ public class RoleValidatorHandler implements ValidatorHandler {
                 //create specific validation here
                 if (role.getRoleName() == null || role.getRoleName().isEmpty()) {
                     invalid = true;
-                    msgBldr.append("\nroleName : missing");
+                    msgBldr.append("\nroleName : missing or empty");
                 }
             } else if (action.equals(Action.UPDATE)) {
                 //update specific validation here
                 if (role.getRoleName() != null && role.getRoleName().isEmpty()) {
                     invalid = true;
-                    msgBldr.append("\nroleName : cannot be changed!");
+                    msgBldr.append("\nroleName : cannot be empty");
                 }
             }
             if (invalid) {