directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 56464 - in incubator/directory/janus/trunk: . sandbox/src/java/org/apache/janus/authorization sandbox/src/java/org/apache/janus/authorization/effect sandbox/src/test/org/apache/janus/authorization sandbox/src/test/org/apache/janus/authorization/effect
Date Wed, 03 Nov 2004 03:46:20 GMT
Author: vtence
Date: Tue Nov  2 19:46:15 2004
New Revision: 56464

Added:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/AbstractCombinedEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/Effects.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/SomePermission.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/DenyOverridesEffectTest.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/FirstApplicableEffectTest.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/LastApplicableEffectTest.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/PermitOverridesEffectTest.java
Modified:
   incubator/directory/janus/trunk/project.xml
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/PolicyTest.java
Log:
o Added more test cases
o Cleaned up things a bit

Modified: incubator/directory/janus/trunk/project.xml
==============================================================================
--- incubator/directory/janus/trunk/project.xml	(original)
+++ incubator/directory/janus/trunk/project.xml	Tue Nov  2 19:46:15 2004
@@ -27,7 +27,7 @@
         <dependency>
             <groupId>jmock</groupId>
             <artifactId>jmock</artifactId>
-            <version>1.0.0</version>
+            <version>1.0.1</version>
         </dependency>
     </dependencies>
 

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
Tue Nov  2 19:46:15 2004
@@ -16,7 +16,7 @@
  */
 package org.apache.janus.authorization;
 
-import org.apache.janus.authorization.effect.NotApplicableEffect;
+import org.apache.janus.authorization.effect.Effects;
 
 import javax.security.auth.Subject;
 
@@ -42,6 +42,6 @@
     {
         if ( m_subjectPredicate.evaluate( s ) ) return m_effect;
 
-        return new NotApplicableEffect();
+        return Effects.NOT_APPLICABLE;
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
Tue Nov  2 19:46:15 2004
@@ -21,13 +21,13 @@
  */
 public interface Effect
 {
-    Effect integrate( Effect effect );
+    Effect add( Effect effect );
 
-    Effect derive( Effect effect );
+    Effect applyTo( Effect effect );
 
     Effect permit();
 
     Effect deny();
 
-    Effect indeterminate();
+    Effect reduce();
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
Tue Nov  2 19:46:15 2004
@@ -48,7 +48,7 @@
         {
             Rule rule = ( Rule ) it.next();
             Effect effect = rule.evaluate( s, p );
-            decision = decision.integrate( effect );
+            decision = decision.add( effect );
         }
 
         return decision;

Added: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/AbstractCombinedEffect.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/AbstractCombinedEffect.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,39 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+
+public abstract class AbstractCombinedEffect implements Effect
+{
+    protected final Effect m_effect;
+
+    protected AbstractCombinedEffect( Effect effect )
+    {
+        m_effect = effect;
+    }
+
+    public Effect add( Effect effect )
+    {
+        return effect.applyTo( this );
+    }
+
+    public Effect reduce()
+    {
+        return m_effect;
+    }
+}

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
Tue Nov  2 19:46:15 2004
@@ -23,12 +23,16 @@
  */
 public final class DenyEffect implements Effect
 {
-    public Effect integrate( Effect effect )
+    DenyEffect()
+    {
+    }
+
+    public Effect add( Effect effect )
     {
         return this;
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
         return effect.deny();
     }
@@ -43,7 +47,7 @@
         return this;
     }
 
-    public Effect indeterminate()
+    public Effect reduce()
     {
         return this;
     }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
Tue Nov  2 19:46:15 2004
@@ -21,42 +21,30 @@
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
-public class DenyOverridesEffect implements Effect
+public class DenyOverridesEffect extends AbstractCombinedEffect
 {
-    private final Effect m_effect;
-
     public DenyOverridesEffect()
     {
-        this( new DenyEffect() );
-    }
-
-    protected DenyOverridesEffect( Effect effect )
-    {
-        m_effect = effect;
+        this( Effects.NOT_APPLICABLE );
     }
 
-    public Effect integrate( Effect effect )
+    public DenyOverridesEffect( Effect effect )
     {
-        return effect.derive( this );
+        super( effect );
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
-        return m_effect.derive( effect );
+        return m_effect.applyTo( effect );
     }
 
     public Effect permit()
     {
-        return new DenyOverridesEffect( new GrantEffect() );
+        return new DenyOverridesEffect( Effects.GRANT );
     }
 
     public Effect deny()
     {
-        return new DenyEffect();
-    }
-
-    public Effect indeterminate()
-    {
-        return new DenyOverridesEffect( new IndeterminateEffect() );
+        return Effects.DENY;
     }
 }

Added: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/Effects.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/Effects.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,26 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+
+public class Effects
+{
+    public static final Effect GRANT = new GrantEffect();
+    public static final Effect DENY = new DenyEffect();
+    public static final Effect NOT_APPLICABLE = new NotApplicableEffect();
+}

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
Tue Nov  2 19:46:15 2004
@@ -21,42 +21,30 @@
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
-public class FirstApplicableEffect implements Effect
+public class FirstApplicableEffect extends AbstractCombinedEffect
 {
-    private final Effect m_effect;
-
     public FirstApplicableEffect()
     {
-        this( new NotApplicableEffect() );
+        this( Effects.NOT_APPLICABLE );
     }
 
     protected FirstApplicableEffect( Effect effect )
     {
-        m_effect = effect;
-    }
-
-    public Effect integrate( Effect effect )
-    {
-        return effect.derive( this );
+        super( effect );
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
-        return m_effect.derive( effect );
+        return m_effect.applyTo( effect );
     }
 
     public Effect permit()
     {
-        return new GrantEffect();
+        return Effects.GRANT;
     }
 
     public Effect deny()
     {
-        return new DenyEffect();
-    }
-
-    public Effect indeterminate()
-    {
-        return new IndeterminateEffect();
+        return Effects.DENY;
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
Tue Nov  2 19:46:15 2004
@@ -23,12 +23,16 @@
  */
 public final class GrantEffect implements Effect
 {
-    public Effect integrate( Effect effect )
+    GrantEffect()
+    {
+    }
+
+    public Effect add( Effect effect )
     {
         return this;
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
         return effect.permit();
     }
@@ -43,7 +47,7 @@
         return this;
     }
 
-    public Effect indeterminate()
+    public Effect reduce()
     {
         return this;
     }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
Tue Nov  2 19:46:15 2004
@@ -21,42 +21,30 @@
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
-public class LastApplicableEffect implements Effect
+public class LastApplicableEffect extends AbstractCombinedEffect
 {
-    private final Effect m_effect;
-
     public LastApplicableEffect()
     {
-        this( new NotApplicableEffect() );
+        this( Effects.NOT_APPLICABLE );
     }
 
     protected LastApplicableEffect( Effect effect )
     {
-        m_effect = effect;
-    }
-
-    public Effect integrate( Effect effect )
-    {
-        return effect.derive( this );
+        super( effect );
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
-        return m_effect.derive( effect );
+        return m_effect.applyTo( effect );
     }
 
     public Effect permit()
     {
-        return new LastApplicableEffect( new GrantEffect() );
+        return new LastApplicableEffect( Effects.GRANT );
     }
 
     public Effect deny()
     {
-        return new LastApplicableEffect( new DenyEffect() );
-    }
-
-    public Effect indeterminate()
-    {
-        return new LastApplicableEffect( new IndeterminateEffect() );
+        return new LastApplicableEffect( Effects.DENY );
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
Tue Nov  2 19:46:15 2004
@@ -23,16 +23,20 @@
  */
 public final class NotApplicableEffect implements Effect
 {
-    public Effect integrate( Effect effect )
+    NotApplicableEffect()
     {
-        return this;
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
         return effect;
     }
 
+    public Effect add( Effect effect )
+    {
+        return this;
+    }
+
     public Effect permit()
     {
         return this;
@@ -43,7 +47,7 @@
         return this;
     }
 
-    public Effect indeterminate()
+    public Effect reduce()
     {
         return this;
     }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
Tue Nov  2 19:46:15 2004
@@ -21,43 +21,30 @@
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
-public class PermitOverridesEffect implements Effect
+public class PermitOverridesEffect extends AbstractCombinedEffect
 {
-    private final Effect m_effect;
-
     public PermitOverridesEffect()
     {
-        this( new NotApplicableEffect() );
+        this( Effects.NOT_APPLICABLE );
     }
 
     protected PermitOverridesEffect( Effect effect )
     {
-        m_effect = effect;
-    }
-
-    public Effect integrate( Effect effect )
-    {
-        return effect.derive( this );
+        super( effect );
     }
 
-    public Effect derive( Effect effect )
+    public Effect applyTo( Effect effect )
     {
-        return m_effect.derive( effect );
+        return m_effect.applyTo( effect );
     }
 
     public Effect permit()
     {
-        return new GrantEffect();
+        return Effects.GRANT;
     }
 
     public Effect deny()
     {
-        return new PermitOverridesEffect( new DenyEffect() );
+        return new PermitOverridesEffect( Effects.DENY );
     }
-
-    public Effect indeterminate()
-    {
-        return new PermitOverridesEffect( new IndeterminateEffect() );
-    }
-
 }

Modified: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
Tue Nov  2 19:46:15 2004
@@ -17,6 +17,7 @@
 package org.apache.janus.authorization;
 
 import org.apache.janus.authentication.realm.UsernamePrincipal;
+import org.apache.janus.authorization.effect.Effects;
 import org.apache.janus.authorization.effect.GrantEffect;
 import org.apache.janus.authorization.effect.NotApplicableEffect;
 import org.apache.janus.authorization.predicate.FalsePredicate;
@@ -54,14 +55,14 @@
 
     public void testValidConditionOnSubject()
     {
-        m_rule = new DefaultRule( new GrantEffect() );
+        m_rule = new DefaultRule( Effects.GRANT );
         m_rule.setSubjectCondition( new HasPrincipalPredicate( new UsernamePrincipal( "johnDoe"
) ) );
         assertTrue( m_rule.evaluate( john() ) instanceof GrantEffect );
     }
 
     public void testIsNotApplicableIfSubjectConditionIsNotVerified()
     {
-        m_rule = new DefaultRule( new GrantEffect() );
+        m_rule = new DefaultRule( Effects.GRANT );
         m_rule.setSubjectCondition( new FalsePredicate() );
         assertTrue( m_rule.evaluate( john() ) instanceof NotApplicableEffect );
     }

Modified: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/PolicyTest.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/PolicyTest.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/PolicyTest.java
Tue Nov  2 19:46:15 2004
@@ -3,38 +3,26 @@
  */
 package org.apache.janus.authorization;
 
-import org.apache.janus.authorization.effect.DenyEffect;
-import org.apache.janus.authorization.effect.GrantEffect;
-import org.jmock.Mock;
-import org.jmock.MockObjectTestCase;
+import junit.framework.TestCase;
+import org.apache.janus.authorization.effect.Effects;
+import org.apache.janus.authorization.effect.PermitOverridesEffect;
 
 import javax.security.auth.Subject;
 
-public class PolicyTest extends MockObjectTestCase
+public class PolicyTest extends TestCase
 {
-    public void testEmptyPolicyResolvesToDefaultDecision()
+    public void testRendersDefaultDecisionWhenEmpty()
     {
-        Policy policy = new Policy( new GrantEffect() );
-        assertTrue( policy.evaluate( new Subject(), new BasicPermission("doSomething") )
instanceof GrantEffect );
+        Policy policy = new Policy( new PermitOverridesEffect() );
+        assertEquals( Effects.NOT_APPLICABLE, policy.evaluate( new Subject(), new SomePermission()
).reduce() );
     }
 
-    public void testPolicyIsEvaluatedByCombiningRuleDecisions()
+    public void testCombinesResultOfContainedRulesEvaluation()
     {
-        Mock mockEffect = new Mock( Effect.class );
-        Policy policy = new Policy( effect(mockEffect) );
+        Policy policy = new Policy( new PermitOverridesEffect() );
+        policy.addRule( new PrimitiveRule( Effects.DENY ) );
+        policy.addRule( new PrimitiveRule( Effects.GRANT ) );
 
-        policy.addRule( new PrimitiveRule( new GrantEffect() ));
-        policy.addRule( new PrimitiveRule( new DenyEffect() ));
-
-        mockEffect.expects( once() ).method( "integrate" ).with( isA(GrantEffect.class) ).will(
returnValue( effect(mockEffect) ));
-        mockEffect.expects( once() ).method( "integrate" ).with( isA(DenyEffect.class) ).will(
returnValue( effect(mockEffect) ));
-
-        policy.evaluate( new Subject(), new BasicPermission( "doSomething" ) );
-        mockEffect.verify();
-    }
-
-    private Effect effect( Mock mock )
-    {
-        return (Effect) mock.proxy();
+        assertEquals( Effects.GRANT, policy.evaluate( new Subject(), new SomePermission()
).reduce() );
     }
 }

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/SomePermission.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/SomePermission.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,25 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization;
+
+public class SomePermission extends BasicPermission
+{
+    public SomePermission()
+    {
+        super( "something" );
+    }
+}

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/DenyOverridesEffectTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/DenyOverridesEffectTest.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,44 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+import org.jmock.MockObjectTestCase;
+
+public class DenyOverridesEffectTest extends MockObjectTestCase
+{
+    public void testDefaultsToNotApplicable()
+    {
+        Effect effect = new DenyOverridesEffect();
+        assertEquals( Effects.NOT_APPLICABLE, effect.reduce() );
+    }
+
+    public void testCombinedResultIsDenyIfSingleDenyIsEncountered()
+    {
+        Effect effect = new DenyOverridesEffect();
+        effect = effect.deny();
+        effect = effect.permit();
+        assertEquals( Effects.DENY, effect.reduce() );
+    }
+
+    public void testCombinedResultIsPermitIfNoDenyAndAtLeastAPermitIsEncountered()
+    {
+        Effect effect = new DenyOverridesEffect();
+        effect = effect.permit();
+        assertEquals( Effects.GRANT, effect.reduce() );
+    }
+}

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/FirstApplicableEffectTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/FirstApplicableEffectTest.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+import org.jmock.MockObjectTestCase;
+
+public class FirstApplicableEffectTest extends MockObjectTestCase
+{
+    public void testDefaultsToNotApplicable()
+    {
+        Effect effect = new FirstApplicableEffect();
+        assertEquals( Effects.NOT_APPLICABLE, effect.reduce() );
+    }
+
+    public void testCombinedResultIsFirstApplicableEffect()
+    {
+        Effect effect = new FirstApplicableEffect();
+        effect = effect.deny();
+        effect = effect.permit();
+        effect = effect.deny();
+        assertEquals( Effects.DENY, effect.reduce() );
+    }
+}

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/LastApplicableEffectTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/LastApplicableEffectTest.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+import org.jmock.MockObjectTestCase;
+
+public class LastApplicableEffectTest extends MockObjectTestCase
+{
+    public void testDefaultsToNotApplicable()
+    {
+        Effect effect = new LastApplicableEffect();
+        assertEquals( Effects.NOT_APPLICABLE, effect.reduce() );
+    }
+
+    public void testCombinedResultIsLastApplicableEffect()
+    {
+        Effect effect = new LastApplicableEffect();
+        effect = effect.deny();
+        effect = effect.permit();
+        effect = effect.deny();
+        assertEquals( Effects.DENY, effect.reduce() );
+    }
+}

Added: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/PermitOverridesEffectTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/effect/PermitOverridesEffectTest.java
Tue Nov  2 19:46:15 2004
@@ -0,0 +1,44 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.authorization.effect;
+
+import org.apache.janus.authorization.Effect;
+import org.jmock.MockObjectTestCase;
+
+public class PermitOverridesEffectTest extends MockObjectTestCase
+{
+    public void testDefaultsToNotApplicable()
+    {
+        Effect effect = new PermitOverridesEffect();
+        assertEquals( Effects.NOT_APPLICABLE, effect.reduce() );
+    }
+
+    public void testCombinedResultIsPermitIfSinglePermitIsEncountered()
+    {
+        Effect effect = new PermitOverridesEffect();
+        effect = effect.permit();
+        effect = effect.deny();
+        assertEquals( Effects.GRANT, effect.reduce() );
+    }
+
+    public void testCombinedResultIsDenyIfNoPermitAndAtLeastADenyIsEncountered()
+    {
+        Effect effect = new PermitOverridesEffect();
+        effect = effect.deny();
+        assertEquals( Effects.DENY, effect.reduce() );
+    }
+}

Mime
View raw message