Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.as.test.integration.management.rbac;
  
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ACCESS_CONTROL;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTRIBUTES;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_DESCRIPTION_OPERATION;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE;
  import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
 import static org.jboss.as.test.integration.management.rbac.RbacUtil.executeOperation;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 

Author(s):
Ladislav Thon <lthon@redhat.com>
 
 public class PermissionsCoverageTestUtil {
     public static void assertTheEntireDomainTreeHasPermissionsDefined(ModelControllerClient clientthrows IOException {
         operation.get().set(true);
         ModelNode resource = executeOperation(clientoperation.).get();
 
         operation.get().set(true);
         operation.get().set("combined-descriptions");
         ModelNode resourceDescription = executeOperation(clientoperation.).get();
 
         verify(resourceresourceDescription."");
     }
 
     // "children" alternates with "model-description"
     private static enum DescriptionContainer {
         CHILDREN(.true"/"),
         MODEL_DESCRIPTION(.false"=");
 
         public final String name;
         public final boolean shouldHaveAccessControlSibling// "children" must always have a "access-control" sibling
         public final String pathSeparator;
 
         private DescriptionContainer(String nameboolean shouldHaveAccessControlSiblingString pathSeparator) {
             this. = name;
             this. = shouldHaveAccessControlSibling;
             this. = pathSeparator;
         }
 
         public DescriptionContainer next() {
             return this ==  ?  : ;
         }
 
         @Override
         public String toString() {
             return .toUpperCase(.);
         }
     }
 
     private static void verify(ModelNode resourceModelNode resourceDescription,
                                DescriptionContainer descriptionContainerString currentPath) {
 
         if (!resource.isDefined()) {
             return;
         }
         assert resource.getType() == .;
 
         ..println("Verifying " + (currentPath.isEmpty() ? "<root>" : currentPath));
 
         if (descriptionContainer.shouldHaveAccessControlSibling) {
             assertTrue(resourceDescription.has());
             ModelNode accessControl = resourceDescription.get();
 
             assertTrue(accessControl.has());
             ModelNode defaultAccessControl = accessControl.get();
 
             assertTrue(defaultAccessControl.has("read"));
             assertEquals(.defaultAccessControl.get("read").getType());
             assertTrue(defaultAccessControl.has("write"));
             assertEquals(.defaultAccessControl.get("write").getType());
         }
 
         for (String key : resource.keys()) {
             if (resourceDescription.get().has(key)) {
                 // not interesting
             } else if (resourceDescription.get(descriptionContainer.name).has(key)) {
                 ModelNode child = resource.get(key);
                 ModelNode childDescription = resourceDescription.get(descriptionContainer.namekey);
                 verify(childchildDescriptiondescriptionContainer.next(), currentPath + descriptionContainer.pathSeparator + key);
             } else if (resourceDescription.get(descriptionContainer.name).has("*")) {
                 ModelNode child = resource.get(key);
                 ModelNode childDescription = resourceDescription.get(descriptionContainer.name"*");
                verify(childchildDescriptiondescriptionContainer.next(), currentPath + descriptionContainer.pathSeparator + key);
            } else {
                fail("No description for key " + key);
            }
        }
    }
New to GrepCode? Check out our FAQ X