소스 검색

SEC-679: Removed use of MockApplicationContext and improved use of ehcache (shutting down cache managers after tests are run). Upgraded ehcache version to 1.3 as used in Spring pom.

Luke Taylor 17 년 전
부모
커밋
5187f89fe8

+ 1 - 1
acl/pom.xml

@@ -37,7 +37,7 @@
         <dependency>
             <groupId>net.sf.ehcache</groupId>
             <artifactId>ehcache</artifactId>
-            <version>1.2.4</version>
+            <version>1.3.0</version>
             <optional>true</optional>
         </dependency>
         <dependency>

+ 20 - 6
acl/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java

@@ -4,19 +4,19 @@ import java.util.Map;
 
 import junit.framework.Assert;
 import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
 
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.springframework.context.ApplicationContext;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
-import org.springframework.security.MockApplicationContext;
 import org.springframework.security.TestDataSource;
 import org.springframework.security.acls.Acl;
 import org.springframework.security.acls.AuditableAccessControlEntry;
@@ -45,7 +45,14 @@ public class BasicLookupStrategyTests {
 
     private static TestDataSource dataSource;
 
-    // ~ Methods ========================================================================================================
+    private static CacheManager cacheManager;
+
+    //~ Methods ========================================================================================================
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
+    }
 
     @BeforeClass
     public static void createDatabase() throws Exception {
@@ -62,6 +69,12 @@ public class BasicLookupStrategyTests {
         dataSource.destroy();
     }
 
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
+    }
+
     @Before
     public void populateDatabase() {
         String query = "INSERT INTO acl_sid(ID,PRINCIPAL,SID) VALUES (1,1,'ben');"
@@ -96,8 +109,9 @@ public class BasicLookupStrategyTests {
     }
 
     private Ehcache getCache() {
-        ApplicationContext ctx = MockApplicationContext.getContext();
-        return (Ehcache) ctx.getBean("eHCacheBackend");
+        Ehcache cache = cacheManager.getCache("basiclookuptestcache");
+        cache.removeAll();
+        return cache;
     }
 
     @Test
@@ -202,7 +216,7 @@ public class BasicLookupStrategyTests {
         Assert.assertEquals(child.getEntries()[0].getSid(), new PrincipalSid("ben"));
         Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditFailure());
         Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isAuditSuccess());
-        Assert.assertFalse(((AuditableAccessControlEntry) child.getEntries()[0]).isGranting());
+        Assert.assertFalse((child.getEntries()[0]).isGranting());
     }
     
     @Test

+ 63 - 53
acl/src/test/java/org/springframework/security/acls/jdbc/EhCacheBasedAclCacheTests.java

@@ -2,16 +2,13 @@ package org.springframework.security.acls.jdbc;
 
 import java.io.Serializable;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.CacheManager;
 
-import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.security.Authentication;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
-import org.springframework.security.MockApplicationContext;
 import org.springframework.security.acls.MutableAcl;
 import org.springframework.security.acls.domain.AclAuthorizationStrategy;
 import org.springframework.security.acls.domain.AclAuthorizationStrategyImpl;
@@ -22,93 +19,105 @@ import org.springframework.security.acls.objectidentity.ObjectIdentityImpl;
 import org.springframework.security.context.SecurityContextHolder;
 import org.springframework.security.providers.TestingAuthenticationToken;
 
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
 /**
  * Tests {@link EhCacheBasedAclCache}
  *
  * @author Andrei Stefan
  */
-public class EhCacheBasedAclCacheTests extends TestCase {
+public class EhCacheBasedAclCacheTests {
     //~ Instance fields ================================================================================================
-    
-    AbstractXmlApplicationContext ctx;
+    private static CacheManager cacheManager;
 
     //~ Methods ========================================================================================================
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("ehcachebasedacltests", 500, false, false, 30, 30));
+    }
 
-    private Ehcache getCache() {
-        this.ctx = (AbstractXmlApplicationContext) MockApplicationContext.getContext();
-
-        return (Ehcache) ctx.getBean("eHCacheBackend");
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
     }
-    
-    protected void tearDown() throws Exception {
-        super.tearDown();
+
+    @After
+    public void clearContext() {
         SecurityContextHolder.clearContext();
-        if (ctx != null) {
-            ctx.close();
-        }
     }
 
-    public void testConstructorRejectsNullParameters() throws Exception {
-        try {
-            AclCache aclCache = new EhCacheBasedAclCache(null);
-            Assert.fail("It should have thrown IllegalArgumentException");
-        }
-        catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
-        }
+    private Ehcache getCache() {
+        Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
+        cache.removeAll();
+
+        return cache;
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void constructorRejectsNullParameters() throws Exception {
+        AclCache aclCache = new EhCacheBasedAclCache(null);
+        fail("It should have thrown IllegalArgumentException");
     }
 
-    public void testMethodsRejectNullParameters() throws Exception {
+    @Test
+    public void methodsRejectNullParameters() throws Exception {
         Ehcache cache = new MockEhcache();
         EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
 
         try {
             Serializable id = null;
             myCache.evictFromCache(id);
-            Assert.fail("It should have thrown IllegalArgumentException");
+            fail("It should have thrown IllegalArgumentException");
         }
         catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
+            assertTrue(true);
         }
 
         try {
             ObjectIdentity obj = null;
             myCache.evictFromCache(obj);
-            Assert.fail("It should have thrown IllegalArgumentException");
+            fail("It should have thrown IllegalArgumentException");
         }
         catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
+            assertTrue(true);
         }
 
         try {
             Serializable id = null;
             myCache.getFromCache(id);
-            Assert.fail("It should have thrown IllegalArgumentException");
+            fail("It should have thrown IllegalArgumentException");
         }
         catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
+            assertTrue(true);
         }
 
         try {
             ObjectIdentity obj = null;
             myCache.getFromCache(obj);
-            Assert.fail("It should have thrown IllegalArgumentException");
+            fail("It should have thrown IllegalArgumentException");
         }
         catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
+            assertTrue(true);
         }
 
         try {
             MutableAcl acl = null;
             myCache.putInCache(acl);
-            Assert.fail("It should have thrown IllegalArgumentException");
+            fail("It should have thrown IllegalArgumentException");
         }
         catch (IllegalArgumentException expected) {
-            Assert.assertTrue(true);
+            assertTrue(true);
         }
     }
 
-    public void testCacheOperationsAclWithoutParent() throws Exception {
+    @Test
+    public void cacheOperationsAclWithoutParent() throws Exception {
         Ehcache cache = getCache();
         EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
 
@@ -119,36 +128,37 @@ public class EhCacheBasedAclCacheTests extends TestCase {
         MutableAcl acl = new AclImpl(identity, new Long(1), aclAuthorizationStrategy, new ConsoleAuditLogger());
 
         myCache.putInCache(acl);
-        Assert.assertEquals(cache.getSize(), 2);
+        assertEquals(cache.getSize(), 2);
 
         // Check we can get from cache the same objects we put in
-        Assert.assertEquals(myCache.getFromCache(new Long(1)), acl);
-        Assert.assertEquals(myCache.getFromCache(identity), acl);
+        assertEquals(myCache.getFromCache(new Long(1)), acl);
+        assertEquals(myCache.getFromCache(identity), acl);
 
         // Put another object in cache
         ObjectIdentity identity2 = new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(101));
         MutableAcl acl2 = new AclImpl(identity2, new Long(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
 
         myCache.putInCache(acl2);
-        Assert.assertEquals(cache.getSize(), 4);
+        assertEquals(cache.getSize(), 4);
 
         // Try to evict an entry that doesn't exist
         myCache.evictFromCache(new Long(3));
         myCache.evictFromCache(new ObjectIdentityImpl("org.springframework.security.TargetObject", new Long(102)));
-        Assert.assertEquals(cache.getSize(), 4);
+        assertEquals(cache.getSize(), 4);
 
         myCache.evictFromCache(new Long(1));
-        Assert.assertEquals(cache.getSize(), 2);
+        assertEquals(cache.getSize(), 2);
 
         // Check the second object inserted
-        Assert.assertEquals(myCache.getFromCache(new Long(2)), acl2);
-        Assert.assertEquals(myCache.getFromCache(identity2), acl2);
+        assertEquals(myCache.getFromCache(new Long(2)), acl2);
+        assertEquals(myCache.getFromCache(identity2), acl2);
 
         myCache.evictFromCache(identity2);
-        Assert.assertEquals(cache.getSize(), 0);
+        assertEquals(cache.getSize(), 0);
     }
-    
-    public void testCacheOperationsAclWithParent() throws Exception {
+
+    @Test
+    public void cacheOperationsAclWithParent() throws Exception {
         Ehcache cache = getCache();
         EhCacheBasedAclCache myCache = new EhCacheBasedAclCache(cache);
         
@@ -168,13 +178,13 @@ public class EhCacheBasedAclCacheTests extends TestCase {
         acl.setParent(parentAcl);
 
         myCache.putInCache(acl);
-        Assert.assertEquals(cache.getSize(), 4);
+        assertEquals(cache.getSize(), 4);
 
         // Check we can get from cache the same objects we put in
-        Assert.assertEquals(myCache.getFromCache(new Long(1)), acl);
-        Assert.assertEquals(myCache.getFromCache(identity), acl);
-        Assert.assertEquals(myCache.getFromCache(new Long(2)), parentAcl);
-        Assert.assertEquals(myCache.getFromCache(identityParent), parentAcl);
+        assertEquals(myCache.getFromCache(new Long(1)), acl);
+        assertEquals(myCache.getFromCache(identity), acl);
+        assertEquals(myCache.getFromCache(new Long(2)), parentAcl);
+        assertEquals(myCache.getFromCache(identityParent), parentAcl);
     }
 
     //~ Inner Classes ==================================================================================================

+ 1 - 1
cas/cas-client/src/test/java/org/springframework/security/providers/cas/cache/EhCacheBasedTicketCacheTests.java

@@ -41,7 +41,7 @@ import static org.junit.Assert.*;
  * @version $Id$
  */
 public class EhCacheBasedTicketCacheTests {
-    static CacheManager cacheManager;
+    private static CacheManager cacheManager;
 
     //~ Methods ========================================================================================================
     @BeforeClass

+ 0 - 34
core/src/test/java/org/springframework/security/MockApplicationContext.java

@@ -1,34 +0,0 @@
-/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
- *
- * 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.springframework.security;
-
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-
-/**
- * Simply returns an <code>ApplicationContext</code> which has a couple of <code>ApplicationEvent</code> listeners.
- *
- * @author Ben Alex
- * @version $Id$
- */
-public class MockApplicationContext {
-    //~ Methods ========================================================================================================
-
-    public static ConfigurableApplicationContext getContext() {
-        return new ClassPathXmlApplicationContext("org/springframework/security/applicationContext.xml");
-    }
-}

+ 25 - 21
core/src/test/java/org/springframework/security/acl/basic/cache/EhCacheBasedAclEntryCacheTests.java

@@ -15,18 +15,19 @@
 
 package org.springframework.security.acl.basic.cache;
 
-import junit.framework.TestCase;
-
 import net.sf.ehcache.Ehcache;
-
-import org.springframework.security.MockApplicationContext;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
 
 import org.springframework.security.acl.basic.AclObjectIdentity;
 import org.springframework.security.acl.basic.BasicAclEntry;
 import org.springframework.security.acl.basic.NamedEntityObjectIdentity;
 import org.springframework.security.acl.basic.SimpleAclEntry;
 
-import org.springframework.context.ApplicationContext;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
 
 /**
@@ -35,7 +36,7 @@ import org.springframework.context.ApplicationContext;
  * @author Ben Alex
  * @version $Id$
  */
-public class EhCacheBasedAclEntryCacheTests extends TestCase {
+public class EhCacheBasedAclEntryCacheTests {
     //~ Static fields/initializers =====================================================================================
 
     private static final AclObjectIdentity OBJECT_100 = new NamedEntityObjectIdentity("OBJECT", "100");
@@ -44,29 +45,31 @@ public class EhCacheBasedAclEntryCacheTests extends TestCase {
     private static final BasicAclEntry OBJECT_100_SCOTT = new SimpleAclEntry("scott", OBJECT_100, null, 4);
     private static final BasicAclEntry OBJECT_200_PETER = new SimpleAclEntry("peter", OBJECT_200, null, 4);
 
-    //~ Constructors ===================================================================================================
+    private static CacheManager cacheManager;
 
-    public EhCacheBasedAclEntryCacheTests() {
-        super();
-    }
+    //~ Methods ========================================================================================================
 
-    public EhCacheBasedAclEntryCacheTests(String arg0) {
-        super(arg0);
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("ehcachebasedacltests", 500, false, false, 30, 30));
     }
 
-    //~ Methods ========================================================================================================
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
+    }
 
     private Ehcache getCache() {
-        ApplicationContext ctx = MockApplicationContext.getContext();
-
-        return (Ehcache) ctx.getBean("eHCacheBackend");
-    }
+        Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
+        cache.removeAll();
 
-    public final void setUp() throws Exception {
-        super.setUp();
+        return cache;
     }
 
-    public void testCacheOperation() throws Exception {
+    @Test
+    public void cacheOperationSucceeds() throws Exception {
         EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
         cache.setCache(getCache());
         cache.afterPropertiesSet();
@@ -85,7 +88,8 @@ public class EhCacheBasedAclEntryCacheTests extends TestCase {
         assertNull(cache.getEntriesFromCache(new NamedEntityObjectIdentity("OBJECT", "100")));
     }
 
-    public void testStartupDetectsMissingCache() throws Exception {
+    @Test
+    public void startupDetectsMissingCache() throws Exception {
         EhCacheBasedAclEntryCache cache = new EhCacheBasedAclEntryCache();
 
         try {

+ 3 - 3
core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java

@@ -21,11 +21,11 @@ import org.springframework.security.AccessDeniedException;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
 import org.springframework.security.MockAccessDecisionManager;
-import org.springframework.security.MockApplicationContext;
 import org.springframework.security.MockAuthenticationManager;
 import org.springframework.security.MockJoinPoint;
 import org.springframework.security.MockRunAsManager;
 import org.springframework.security.TargetObject;
+import org.springframework.security.MockApplicationEventPublisher;
 
 import org.springframework.security.context.SecurityContextHolder;
 
@@ -66,7 +66,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
 
     public void testCallbackIsInvokedWhenPermissionGranted() throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
-        si.setApplicationEventPublisher(MockApplicationContext.getContext());
+        si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
         si.setAccessDecisionManager(new MockAccessDecisionManager());
         si.setAuthenticationManager(new MockAuthenticationManager());
         si.setRunAsManager(new MockRunAsManager());
@@ -97,7 +97,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
 
     public void testCallbackIsNotInvokedWhenPermissionDenied() throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
-        si.setApplicationEventPublisher(MockApplicationContext.getContext());
+        si.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
         si.setAccessDecisionManager(new MockAccessDecisionManager());
         si.setAuthenticationManager(new MockAuthenticationManager());
         si.setRunAsManager(new MockRunAsManager());

+ 3 - 3
core/src/test/java/org/springframework/security/intercept/web/FilterSecurityInterceptorTests.java

@@ -25,10 +25,10 @@ import org.springframework.security.ConfigAttributeDefinition;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
 import org.springframework.security.MockAccessDecisionManager;
-import org.springframework.security.MockApplicationContext;
 import org.springframework.security.MockAuthenticationManager;
 import org.springframework.security.MockRunAsManager;
 import org.springframework.security.RunAsManager;
+import org.springframework.security.MockApplicationEventPublisher;
 import org.springframework.security.util.AntUrlPathMatcher;
 import org.springframework.security.util.RegexUrlPathMatcher;
 import org.springframework.security.context.SecurityContextHolder;
@@ -141,7 +141,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
         interceptor.setAuthenticationManager(new MockAuthenticationManager());
         interceptor.setRunAsManager(new MockRunAsManager());
-        interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
+        interceptor.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
 
         // Setup a mock config attribute definition
         ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");
@@ -194,7 +194,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
         interceptor.setAuthenticationManager(new MockAuthenticationManager());
         interceptor.setRunAsManager(new MockRunAsManager());
-        interceptor.setApplicationEventPublisher(MockApplicationContext.getContext());
+        interceptor.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
 
         // Setup a mock config attribute definition
         ConfigAttributeDefinition def = new ConfigAttributeDefinition("MOCK_OK");

+ 26 - 25
core/src/test/java/org/springframework/security/providers/dao/cache/EhCacheBasedUserCacheTests.java

@@ -15,18 +15,20 @@
 
 package org.springframework.security.providers.dao.cache;
 
-import junit.framework.TestCase;
 
 import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
 
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
-import org.springframework.security.MockApplicationContext;
 
 import org.springframework.security.userdetails.User;
 
-import org.springframework.context.ApplicationContext;
-
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
 /**
  * Tests {@link EhCacheBasedUserCache}.
@@ -34,22 +36,27 @@ import org.springframework.context.ApplicationContext;
  * @author Ben Alex
  * @version $Id$
  */
-public class EhCacheBasedUserCacheTests extends TestCase {
-    //~ Constructors ===================================================================================================
+public class EhCacheBasedUserCacheTests {
+    private static CacheManager cacheManager;
 
-    public EhCacheBasedUserCacheTests() {
+    //~ Methods ========================================================================================================
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30));
     }
 
-    public EhCacheBasedUserCacheTests(String arg0) {
-        super(arg0);
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
     }
 
-    //~ Methods ========================================================================================================
-
     private Ehcache getCache() {
-        ApplicationContext ctx = MockApplicationContext.getContext();
+        Ehcache cache = cacheManager.getCache("ehcacheusercachetests");
+        cache.removeAll();
 
-        return (Ehcache) ctx.getBean("eHCacheBackend");
+        return cache;
     }
 
     private User getUser() {
@@ -57,11 +64,8 @@ public class EhCacheBasedUserCacheTests extends TestCase {
             new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
     }
 
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
-
-    public void testCacheOperation() throws Exception {
+    @Test
+    public void cacheOperationsAreSuccessful() throws Exception {
         EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
         cache.setCache(getCache());
         cache.afterPropertiesSet();
@@ -79,15 +83,12 @@ public class EhCacheBasedUserCacheTests extends TestCase {
         assertNull(cache.getUserFromCache("UNKNOWN_USER"));
     }
 
-    public void testStartupDetectsMissingCache() throws Exception {
+    @Test(expected = IllegalArgumentException.class)
+    public void startupDetectsMissingCache() throws Exception {
         EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
 
-        try {
-            cache.afterPropertiesSet();
-            fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException expected) {
-            assertTrue(true);
-        }
+        cache.afterPropertiesSet();
+        fail("Should have thrown IllegalArgumentException");
 
         Ehcache myCache = getCache();
         cache.setCache(myCache);

+ 24 - 18
core/src/test/java/org/springframework/security/providers/x509/cache/EhCacheBasedX509UserCacheTests.java

@@ -15,20 +15,23 @@
 
 package org.springframework.security.providers.x509.cache;
 
-import junit.framework.TestCase;
-
 import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
 
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
-import org.springframework.security.MockApplicationContext;
 
 import org.springframework.security.providers.x509.X509TestUtils;
 
 import org.springframework.security.userdetails.User;
 import org.springframework.security.userdetails.UserDetails;
 
-import org.springframework.context.ApplicationContext;
+
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
 
 /**
@@ -37,22 +40,28 @@ import org.springframework.context.ApplicationContext;
  * @author Luke Taylor
  * @version $Id$
  */
-public class EhCacheBasedX509UserCacheTests extends TestCase {
-    //~ Constructors ===================================================================================================
+public class EhCacheBasedX509UserCacheTests {
+    private static CacheManager cacheManager;
 
-    public EhCacheBasedX509UserCacheTests() {
-    }
+    //~ Methods ========================================================================================================
 
-    public EhCacheBasedX509UserCacheTests(String arg0) {
-        super(arg0);
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("x509cachetests", 500, false, false, 30, 30));
     }
 
-    //~ Methods ========================================================================================================
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
+    }
 
     private Ehcache getCache() {
-        ApplicationContext ctx = MockApplicationContext.getContext();
+        Ehcache cache = cacheManager.getCache("x509cachetests");
+        cache.removeAll();
 
-        return (Ehcache) ctx.getBean("eHCacheBackend");
+        return cache;
     }
 
     private UserDetails getUser() {
@@ -60,11 +69,8 @@ public class EhCacheBasedX509UserCacheTests extends TestCase {
             new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
     }
 
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
-
-    public void testCacheOperation() throws Exception {
+    @Test
+    public void cacheOperationsAreSucessful() throws Exception {
         EhCacheBasedX509UserCache cache = new EhCacheBasedX509UserCache();
         cache.setCache(getCache());
         cache.afterPropertiesSet();

+ 16 - 21
core/src/test/java/org/springframework/security/util/FilterChainProxyTests.java

@@ -15,27 +15,26 @@
 
 package org.springframework.security.util;
 
-
-import org.junit.After;
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.security.ConfigAttribute;
 import org.springframework.security.ConfigAttributeDefinition;
-import org.springframework.security.MockApplicationContext;
 import org.springframework.security.MockFilterConfig;
 import org.springframework.security.context.HttpSessionContextIntegrationFilter;
 import org.springframework.security.intercept.web.MockFilterInvocationDefinitionSource;
 import org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource;
 import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
 
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.StaticApplicationContext;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import org.junit.After;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
 import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
 
 /**
  * Tests {@link FilterChainProxy}.
@@ -64,7 +63,7 @@ public class FilterChainProxyTests {
     @Test
     public void testDetectsFilterInvocationDefinitionSourceThatDoesNotReturnAllConfigAttributes() throws Exception {
         FilterChainProxy filterChainProxy = new FilterChainProxy();
-        filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
+        filterChainProxy.setApplicationContext(new StaticApplicationContext());
 
         try {
             filterChainProxy.setFilterInvocationDefinitionSource(new MockFilterInvocationDefinitionSource(false, false));
@@ -77,7 +76,7 @@ public class FilterChainProxyTests {
     @Test
     public void testDetectsIfConfigAttributeDoesNotReturnValueForGetAttributeMethod() throws Exception {
         FilterChainProxy filterChainProxy = new FilterChainProxy();
-        filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
+        filterChainProxy.setApplicationContext(new StaticApplicationContext());
 
         ConfigAttributeDefinition cad = new ConfigAttributeDefinition(new MockConfigAttribute());
 
@@ -95,16 +94,12 @@ public class FilterChainProxyTests {
         }
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testDetectsMissingFilterInvocationDefinitionSource() throws Exception {
         FilterChainProxy filterChainProxy = new FilterChainProxy();
-        filterChainProxy.setApplicationContext(MockApplicationContext.getContext());
+        filterChainProxy.setApplicationContext(new StaticApplicationContext());
 
-        try {
-            filterChainProxy.afterPropertiesSet();
-            fail("Should have thrown IllegalArgumentException");
-        } catch (IllegalArgumentException expected) {
-        }
+        filterChainProxy.afterPropertiesSet();
     }
 
     @Test

+ 0 - 42
core/src/test/resources/org/springframework/security/applicationContext.xml

@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
-<!--
- * Copyright 2004 Acegi Technology Pty Limited
- *
- * 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.
- *
- * $Id$
--->
-
-<beans>
-
-   <!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider -->
-   <bean id="authenticationLoggerListener" class="org.springframework.security.event.authentication.LoggerListener"/>
-
-   <!-- Automatically receives AuthenticationEvent messages from AbstractSecurityInterceptor -->
-   <bean id="secureObjectLoggerListener" class="org.springframework.security.event.authorization.LoggerListener"/>
-
-   <!-- Setup a cache we can use in tests of the caching layer -->
-   <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
-      <property name="configLocation" value="classpath:/ehcache-failsafe.xml"/>
-   </bean>
-
-   <bean id="eHCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
-      <property name="cacheManager">
-         <ref local="cacheManager"/>
-      </property>
-      <property name="cacheName" value="testingCache"/>
-   </bean>
-
-
-</beans>

+ 1 - 1
pom.xml

@@ -602,7 +602,7 @@
             <dependency>
                 <groupId>log4j</groupId>
                 <artifactId>log4j</artifactId>
-                <version>1.2.9</version>
+                <version>1.2.13</version>
                 <optional>true</optional>
                 <scope>runtime</scope>
             </dependency>

+ 1 - 1
portlet/pom.xml

@@ -47,7 +47,7 @@
         <dependency>
           <groupId>net.sf.ehcache</groupId>
           <artifactId>ehcache</artifactId>
-          <version>1.2.4</version>
+          <version>1.3.0</version>
         </dependency>
     </dependencies>
 

+ 28 - 38
portlet/src/test/java/org/springframework/security/providers/portlet/cache/EhCacheBasedUserCacheTests.java

@@ -16,58 +16,49 @@
 
 package org.springframework.security.providers.portlet.cache;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
 import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
 
 import org.springframework.security.providers.portlet.PortletTestUtils;
-import org.springframework.cache.ehcache.EhCacheFactoryBean;
+
+import org.junit.Test;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import static org.junit.Assert.*;
 
 /**
- * Tests for {@link EhCacheBasedPortletUserCache}.
+ * Tests for {@link EhCacheBasedUserCache}.
  *
  * @author John A. Lewis
  * @since 2.0
  * @version $Id$
  */
-public class EhCacheBasedUserCacheTests extends TestCase {
-
-	//~ Static fields/initializers =====================================================================================
+public class EhCacheBasedUserCacheTests {
+    //~ Static fields/initializers =====================================================================================
 
-	private static EhCacheFactoryBean cacheFactory;
+    private static CacheManager cacheManager;
 
-	static {
-		cacheFactory = new EhCacheFactoryBean();
-		cacheFactory.setCacheName("portletUserCache");
-		try {
-			cacheFactory.afterPropertiesSet();
-		} catch (IOException e) {
-			throw new RuntimeException("unable to initialize cache factory", e);
-		}
-	}
+    @BeforeClass
+    public static void initCacheManaer() {
+        cacheManager = new CacheManager();
+        cacheManager.addCache(new Cache("portletusercachetests", 500, false, false, 30, 30));
+    }
 
-	//~ Constructors ===================================================================================================
+    @AfterClass
+    public static void shutdownCacheManager() {
+        cacheManager.removalAll();
+        cacheManager.shutdown();
+    }
 
-	public EhCacheBasedUserCacheTests() {
-		super();
-	}
+    private Cache getCache() {
+        Cache cache = cacheManager.getCache("portletusercachetests");
+        cache.removeAll();
 
-	public EhCacheBasedUserCacheTests(String arg0) {
-		super(arg0);
-	}
-
-	//~ Methods ========================================================================================================
-
-	public final void setUp() throws Exception {
-		super.setUp();
-	}
-
-	private Cache getCache() {
-		return (Cache)cacheFactory.getObject();
-	}
+        return cache;
+    }
 
-	public void testCacheOperation() throws Exception {
+    @Test
+    public void testCacheOperation() throws Exception {
 
 		// Create the cache
 		EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
@@ -76,8 +67,7 @@ public class EhCacheBasedUserCacheTests extends TestCase {
 
 		// Check it gets stored in the cache
 		cache.putUserInCache(PortletTestUtils.createUser());
-		assertEquals(PortletTestUtils.TESTCRED,
-				cache.getUserFromCache(PortletTestUtils.TESTUSER).getPassword());
+		assertEquals(PortletTestUtils.TESTCRED, cache.getUserFromCache(PortletTestUtils.TESTUSER).getPassword());
 
 		// Check it gets removed from the cache
 		cache.removeUserFromCache(PortletTestUtils.TESTUSER);