(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Apr 2010 22:08:51 +0000 (22:08 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Apr 2010 22:08:51 +0000 (22:08 +0000)
security/impl/src/test/java/org/wamblee/security/authorization/AuthorizationServiceTest.java

index 78cf3f5982e89291504528a8d07131708f0c1d8d..8be34f9da74d5204f4c5275984f5be6a77161f8d 100644 (file)
@@ -27,11 +27,11 @@ import org.wamblee.usermgt.UserAccessor;
  * @author Erik Brakkee
  */
 public class AuthorizationServiceTest extends TestCase {
-    private AuthorizationRule rule1;
+    private AbstractAuthorizationRule rule1;
 
-    private AuthorizationRule rule2;
+    private AbstractAuthorizationRule rule2;
 
-    private AuthorizationRule rule3;
+    private AbstractAuthorizationRule rule3;
 
     private AuthorizationService service;
 
@@ -80,13 +80,15 @@ public class AuthorizationServiceTest extends TestCase {
         return service;
     }
 
-    protected AuthorizationRule createRule(AuthorizationResult aResult,
+    protected AbstractAuthorizationRule createRule(AuthorizationResult aResult,
         String aGroup, String aPath, Class<? extends Operation> aOperation) {
         return new TestAuthorizationRule(aResult, aGroup, aPath, aOperation);
     }
 
     protected void checkMatchCount(int aCount, AuthorizationRule aRule) {
-        assertEquals(aCount, ((TestAuthorizationRule) aRule).getMatchCount());
+        TestAuthorizationRule testRule = (TestAuthorizationRule) aRule;
+        assertEquals(aCount, testRule.getMatchCount());
+        testRule.reset();
     }
 
     protected Object createResource(String aPath) {
@@ -103,18 +105,18 @@ public class AuthorizationServiceTest extends TestCase {
     public void testFirstRuleGrants() {
         assertTrue(service.isAllowed(createResource("/oni/xyz.jpg"),
             new ReadOperation()));
-        checkMatchCount(1, rule1);
+        checkMatchCount(1, service.getRules()[0]);
         assertTrue(service.isAllowed(createResource("/oni/xyz.jpg"),
             new WriteOperation()));
-        checkMatchCount(2, rule1);
+        checkMatchCount(1, service.getRules()[0]);
         assertTrue(service.isAllowed(createResource("/oni/xyz.jpg"),
             new DeleteOperation()));
-        checkMatchCount(3, rule1);
+        checkMatchCount(1, service.getRules()[0]);
         assertTrue(service.isAllowed(createResource("/oni/xyz.jpg"),
             new CreateOperation()));
-        checkMatchCount(4, rule1);
-        checkMatchCount(0, rule2);
-        checkMatchCount(0, rule3);
+        checkMatchCount(1, service.getRules()[0]);
+        checkMatchCount(0, service.getRules()[1]);
+        checkMatchCount(0, service.getRules()[2]);
     }
 
     /**
@@ -124,9 +126,9 @@ public class AuthorizationServiceTest extends TestCase {
     public void testSecondRuleDenies() {
         assertFalse(service.isAllowed(createResource("/abc/xyz.jpg"),
             new ReadOperation()));
-        checkMatchCount(0, rule1);
-        checkMatchCount(1, rule2);
-        checkMatchCount(0, rule3);
+        checkMatchCount(0, service.getRules()[0]);
+        checkMatchCount(1, service.getRules()[1]);
+        checkMatchCount(0, service.getRules()[2]);
     }
 
     /**
@@ -136,9 +138,9 @@ public class AuthorizationServiceTest extends TestCase {
     public void testThirdRuleGrants() {
         assertTrue(service.isAllowed(createResource("/abc/xyz.jpg"),
             new WriteOperation()));
-        checkMatchCount(0, rule1);
-        checkMatchCount(0, rule2);
-        checkMatchCount(1, rule3);
+        checkMatchCount(0, service.getRules()[0]);
+        checkMatchCount(0, service.getRules()[1]);
+        checkMatchCount(1, service.getRules()[2]);
     }
 
     /**
@@ -182,8 +184,8 @@ public class AuthorizationServiceTest extends TestCase {
     public void testNoRulesSupportResource() {
         assertFalse(service.isAllowed(createResource("/xyxyxyxy"),
             new ReadOperation()));
-        checkMatchCount(0, rule1);
-        checkMatchCount(0, rule2);
-        checkMatchCount(0, rule3);
+        checkMatchCount(0, service.getRules()[0]);
+        checkMatchCount(0, service.getRules()[1]);
+        checkMatchCount(0, service.getRules()[2]);
     }
 }