Tidying test class

This commit is contained in:
Luke Taylor 2009-07-13 23:47:33 +00:00
parent a61aca1abf
commit 3e393c9df6

View File

@ -35,15 +35,6 @@ import java.util.Vector;
* @version $Id$ * @version $Id$
*/ */
public class AffirmativeBasedTests extends TestCase { public class AffirmativeBasedTests extends TestCase {
//~ Constructors ===================================================================================================
public AffirmativeBasedTests() {
super();
}
public AffirmativeBasedTests(String arg0) {
super(arg0);
}
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
@ -53,25 +44,24 @@ public class AffirmativeBasedTests extends TestCase {
private AffirmativeBased makeDecisionManager() { private AffirmativeBased makeDecisionManager() {
AffirmativeBased decisionManager = new AffirmativeBased(); AffirmativeBased decisionManager = new AffirmativeBased();
RoleVoter roleVoter = new RoleVoter();
DenyVoter denyForSureVoter = new DenyVoter();
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
List voters = new Vector(); List voters = new Vector();
voters.add(roleVoter); voters.add(new RoleVoter());
voters.add(denyForSureVoter); voters.add(new DenyVoter());
voters.add(denyAgainForSureVoter); voters.add(new DenyAgainVoter());
decisionManager.setDecisionVoters(voters); decisionManager.setDecisionVoters(voters);
return decisionManager; return decisionManager;
} }
private TestingAuthenticationToken makeTestToken() { private TestingAuthenticationToken makeTestToken() {
return new TestingAuthenticationToken("somebody", "password", return new TestingAuthenticationToken("somebody", "password", "ROLE_1","ROLE_2");
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_1"), new GrantedAuthorityImpl("ROLE_2")});
} }
public final void setUp() throws Exception { public void testOneAffirmativeGrantsAccess(){
super.setUp(); AffirmativeBased mgr = makeDecisionManager();
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"});
mgr.decide(new TestingAuthenticationToken("somebody", "password", "ROLE_1"), new Object(), config);
} }
public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccess() public void testOneAffirmativeVoteOneDenyVoteOneAbstainVoteGrantsAccess()
@ -82,7 +72,6 @@ public class AffirmativeBasedTests extends TestCase {
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"}); ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "DENY_FOR_SURE"});
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
assertTrue(true);
} }
public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess() public void testOneAffirmativeVoteTwoAbstainVotesGrantsAccess()
@ -93,7 +82,6 @@ public class AffirmativeBasedTests extends TestCase {
ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_2"); ConfigAttributeDefinition config = new ConfigAttributeDefinition("ROLE_2");
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
assertTrue(true);
} }
public void testOneDenyVoteTwoAbstainVotesDeniesAccess() public void testOneDenyVoteTwoAbstainVotesDeniesAccess()
@ -107,7 +95,6 @@ public class AffirmativeBasedTests extends TestCase {
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
fail("Should have thrown AccessDeniedException"); fail("Should have thrown AccessDeniedException");
} catch (AccessDeniedException expected) { } catch (AccessDeniedException expected) {
assertTrue(true);
} }
} }
@ -124,7 +111,6 @@ public class AffirmativeBasedTests extends TestCase {
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
fail("Should have thrown AccessDeniedException"); fail("Should have thrown AccessDeniedException");
} catch (AccessDeniedException expected) { } catch (AccessDeniedException expected) {
assertTrue(true);
} }
} }
@ -138,10 +124,9 @@ public class AffirmativeBasedTests extends TestCase {
ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL"); ConfigAttributeDefinition config = new ConfigAttributeDefinition("IGNORED_BY_ALL");
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
assertTrue(true);
} }
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() public void testOneAffirmativeVotesTwoAbstainVotesGrantsAccess()
throws Exception { throws Exception {
TestingAuthenticationToken auth = makeTestToken(); TestingAuthenticationToken auth = makeTestToken();
AffirmativeBased mgr = makeDecisionManager(); AffirmativeBased mgr = makeDecisionManager();
@ -149,6 +134,5 @@ public class AffirmativeBasedTests extends TestCase {
ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"}); ConfigAttributeDefinition config = new ConfigAttributeDefinition(new String[]{"ROLE_1", "ROLE_2"});
mgr.decide(auth, new Object(), config); mgr.decide(auth, new Object(), config);
assertTrue(true);
} }
} }