reverted to junit 3

This commit is contained in:
Andrei Stefan 2008-01-25 15:04:29 +00:00
parent 630efbf536
commit 0f32b3fc40
2 changed files with 26 additions and 32 deletions

View File

@ -1,10 +1,8 @@
package org.springframework.security.acls.domain; package org.springframework.security.acls.domain;
import junit.framework.Assert; import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.security.AccessDeniedException; import org.springframework.security.AccessDeniedException;
import org.springframework.security.Authentication; import org.springframework.security.Authentication;
import org.springframework.security.GrantedAuthority; import org.springframework.security.GrantedAuthority;
@ -24,15 +22,19 @@ import org.springframework.security.providers.TestingAuthenticationToken;
* *
* @author Andrei Stefan * @author Andrei Stefan
*/ */
public class AclImplementationSecurityCheckTests { public class AclImplementationSecurityCheckTests extends TestCase {
@Before
@After //~ Methods ========================================================================================================
public void clearContext() {
protected void setUp() throws Exception {
SecurityContextHolder.clearContext(); SecurityContextHolder.clearContext();
} }
@Test protected void tearDown() throws Exception {
public void securityCheckNoACEs() { SecurityContextHolder.clearContext();
}
public void testSecurityCheckNoACEs() {
Authentication auth = new TestingAuthenticationToken("user", "password", new GrantedAuthority[] { Authentication auth = new TestingAuthenticationToken("user", "password", new GrantedAuthority[] {
new GrantedAuthorityImpl("ROLE_GENERAL"), new GrantedAuthorityImpl("ROLE_AUDITING"), new GrantedAuthorityImpl("ROLE_GENERAL"), new GrantedAuthorityImpl("ROLE_AUDITING"),
new GrantedAuthorityImpl("ROLE_OWNERSHIP") }); new GrantedAuthorityImpl("ROLE_OWNERSHIP") });
@ -96,8 +98,7 @@ public class AclImplementationSecurityCheckTests {
} }
} }
@Test public void testSecurityCheckWithMultipleACEs() {
public void securityCheckWithMultipleACEs() {
// Create a simple authentication with ROLE_GENERAL // Create a simple authentication with ROLE_GENERAL
Authentication auth = new TestingAuthenticationToken("user", "password", Authentication auth = new TestingAuthenticationToken("user", "password",
new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_GENERAL") }); new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_GENERAL") });
@ -198,8 +199,7 @@ public class AclImplementationSecurityCheckTests {
} }
} }
@Test public void testSecurityCheckWithInheritableACEs() {
public void securityCheckWithInheritableACEs() {
// Create a simple authentication with ROLE_GENERAL // Create a simple authentication with ROLE_GENERAL
Authentication auth = new TestingAuthenticationToken("user", "password", Authentication auth = new TestingAuthenticationToken("user", "password",
new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_GENERAL") }); new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_GENERAL") });
@ -257,8 +257,7 @@ public class AclImplementationSecurityCheckTests {
} }
} }
@Test public void testSecurityCheckPrincipalOwner() {
public void securityCheckPrincipalOwner() {
Authentication auth = new TestingAuthenticationToken("user", "password", new GrantedAuthority[] { Authentication auth = new TestingAuthenticationToken("user", "password", new GrantedAuthority[] {
new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_ONE"),
new GrantedAuthorityImpl("ROLE_ONE") }); new GrantedAuthorityImpl("ROLE_ONE") });

View File

@ -5,10 +5,8 @@ import java.io.PrintStream;
import java.io.Serializable; import java.io.Serializable;
import junit.framework.Assert; import junit.framework.Assert;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.security.acls.AccessControlEntry; import org.springframework.security.acls.AccessControlEntry;
import org.springframework.security.acls.Acl; import org.springframework.security.acls.Acl;
import org.springframework.security.acls.AuditableAccessControlEntry; import org.springframework.security.acls.AuditableAccessControlEntry;
@ -20,24 +18,25 @@ import org.springframework.security.acls.sid.Sid;
* *
* @author Andrei Stefan * @author Andrei Stefan
*/ */
public class AuditLoggerTests { public class AuditLoggerTests extends TestCase {
//~ Instance fields ================================================================================================
private PrintStream console; private PrintStream console;
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); private ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@Before //~ Methods ========================================================================================================
public void onSetUp() {
public void setUp() throws Exception {
console = System.out; console = System.out;
System.setOut(new PrintStream(bytes)); System.setOut(new PrintStream(bytes));
} }
@After public void tearDown() throws Exception {
public void onTearDown() {
System.setOut(console); System.setOut(console);
} }
@Test public void testLoggingTests() {
public void loggingTests() {
ConsoleAuditLogger logger = new ConsoleAuditLogger(); ConsoleAuditLogger logger = new ConsoleAuditLogger();
MockAccessControlEntryImpl auditableAccessControlEntry = new MockAccessControlEntryImpl(); MockAccessControlEntryImpl auditableAccessControlEntry = new MockAccessControlEntryImpl();
@ -68,9 +67,8 @@ public class AuditLoggerTests {
Assert.assertTrue(bytes.size() == 0); Assert.assertTrue(bytes.size() == 0);
} }
/** //~ Inner Classes ==================================================================================================
* Mock {@link AuditableAccessControlEntry}.
*/
private class MockAccessControlEntryImpl implements AuditableAccessControlEntry { private class MockAccessControlEntryImpl implements AuditableAccessControlEntry {
private boolean auditFailure = false; private boolean auditFailure = false;
@ -113,9 +111,6 @@ public class AuditLoggerTests {
} }
} }
/**
* Mock {@link AccessControlEntry}.
*/
private class MockAccessControlEntry implements AccessControlEntry { private class MockAccessControlEntry implements AccessControlEntry {
public Acl getAcl() { public Acl getAcl() {