(no commit message)
[utils] / security / impl / src / test / java / org / wamblee / security / authorization / UrlAuthorizationRuleTest.java
index 1f7b63697ff63187509e83d531e9aa38d3491142..335a606e3f83672dc3e331e483f3e78c1f26ef13 100644 (file)
  */ 
 package org.wamblee.security.authorization;
 
+import static org.wamblee.security.authorization.AuthorizationResult.*;
 import junit.framework.TestCase;
-import static org.wamblee.security.authorization.AuthorizationResult.GRANTED;
-import static org.wamblee.security.authorization.AuthorizationResult.UNDECIDED;
-import static org.wamblee.security.authorization.AuthorizationResult.UNSUPPORTED_RESOURCE;
-
-import org.wamblee.security.authentication.User;
 
 /**
  * Tests for the {@link org.wamblee.security.authorization.UrlAuthorizationRule}
@@ -29,6 +25,14 @@ import org.wamblee.security.authentication.User;
  * @author Erik Brakkee
  */
 public class UrlAuthorizationRuleTest extends TestCase {
+    
+    private TestUserAccessor userAccessor; 
+    
+    public void setUp() { 
+        userAccessor = new TestUserAccessor(); 
+        
+    }
+    
     /**
      * Constructs the rule with a result of UNDECIDED. Verifies that an
      * IllegalArgumentException is thrown.
@@ -64,14 +68,16 @@ public class UrlAuthorizationRuleTest extends TestCase {
     public void testUnsupportedObject() {
         AuthorizationRule rule = new TestAuthorizationRule(GRANTED, "users",
             "/path", ReadOperation.class);
+        rule.setUserAdministration(userAccessor.getUserAdmin());
         assertEquals(UNSUPPORTED_RESOURCE, rule.isAllowed("hello",
-            new ReadOperation(), new TestUserAccessor().getCurrentUser()));
+            new ReadOperation(), userAccessor.getCurrentUser()));
     }
 
     public void testMatchingScenarios() {
         AuthorizationRule rule = new TestAuthorizationRule(GRANTED, "users",
             "/path/", ReadOperation.class);
-        User user = new TestUserAccessor().getCurrentUser();
+        rule.setUserAdministration(userAccessor.getUserAdmin());
+        String user = userAccessor.getCurrentUser();
 
         // everything matches
         assertEquals(GRANTED, rule.isAllowed(new TestResource("/path/a"),
@@ -90,6 +96,7 @@ public class UrlAuthorizationRuleTest extends TestCase {
         // group does not match.
         AuthorizationRule rule2 = new TestAuthorizationRule(GRANTED, "users2",
             "/path/", ReadOperation.class);
+        rule2.setUserAdministration(userAccessor.getUserAdmin());
         assertEquals(UNDECIDED, rule2.isAllowed(new TestResource("/path/a"),
             new ReadOperation(), user));
     }