diff --git a/acl/pom.xml b/acl/pom.xml
index 495630fcf4..6b75e73370 100644
--- a/acl/pom.xml
+++ b/acl/pom.xml
@@ -37,7 +37,7 @@
net.sf.ehcache
ehcache
- 1.2.4
+ 1.3.0
true
diff --git a/acl/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java b/acl/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java
index a2a6bd943d..059b50552b 100644
--- a/acl/src/test/java/org/springframework/security/acls/jdbc/BasicLookupStrategyTests.java
+++ b/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
diff --git a/acl/src/test/java/org/springframework/security/acls/jdbc/EhCacheBasedAclCacheTests.java b/acl/src/test/java/org/springframework/security/acls/jdbc/EhCacheBasedAclCacheTests.java
index 993d7e1943..e518c01ce4 100644
--- a/acl/src/test/java/org/springframework/security/acls/jdbc/EhCacheBasedAclCacheTests.java
+++ b/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));
+ }
+
+ @AfterClass
+ public static void shutdownCacheManager() {
+ cacheManager.removalAll();
+ cacheManager.shutdown();
+ }
+
+ @After
+ public void clearContext() {
+ SecurityContextHolder.clearContext();
+ }
private Ehcache getCache() {
- this.ctx = (AbstractXmlApplicationContext) MockApplicationContext.getContext();
+ Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
+ cache.removeAll();
- return (Ehcache) ctx.getBean("eHCacheBackend");
+ return cache;
}
- protected void tearDown() throws Exception {
- super.tearDown();
- SecurityContextHolder.clearContext();
- if (ctx != null) {
- ctx.close();
- }
+ @Test(expected=IllegalArgumentException.class)
+ public void constructorRejectsNullParameters() throws Exception {
+ AclCache aclCache = new EhCacheBasedAclCache(null);
+ fail("It should have thrown IllegalArgumentException");
}
- public void testConstructorRejectsNullParameters() throws Exception {
- try {
- AclCache aclCache = new EhCacheBasedAclCache(null);
- Assert.fail("It should have thrown IllegalArgumentException");
- }
- catch (IllegalArgumentException expected) {
- Assert.assertTrue(true);
- }
- }
-
- 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 ==================================================================================================
diff --git a/cas/cas-client/src/test/java/org/springframework/security/providers/cas/cache/EhCacheBasedTicketCacheTests.java b/cas/cas-client/src/test/java/org/springframework/security/providers/cas/cache/EhCacheBasedTicketCacheTests.java
index 216468db2c..b6b0223a6a 100644
--- a/cas/cas-client/src/test/java/org/springframework/security/providers/cas/cache/EhCacheBasedTicketCacheTests.java
+++ b/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
diff --git a/core/src/test/java/org/springframework/security/MockApplicationContext.java b/core/src/test/java/org/springframework/security/MockApplicationContext.java
deleted file mode 100644
index 398750ee84..0000000000
--- a/core/src/test/java/org/springframework/security/MockApplicationContext.java
+++ /dev/null
@@ -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 ApplicationContext which has a couple of ApplicationEvent listeners.
- *
- * @author Ben Alex
- * @version $Id$
- */
-public class MockApplicationContext {
- //~ Methods ========================================================================================================
-
- public static ConfigurableApplicationContext getContext() {
- return new ClassPathXmlApplicationContext("org/springframework/security/applicationContext.xml");
- }
-}
diff --git a/core/src/test/java/org/springframework/security/acl/basic/cache/EhCacheBasedAclEntryCacheTests.java b/core/src/test/java/org/springframework/security/acl/basic/cache/EhCacheBasedAclEntryCacheTests.java
index 1f80ec05db..168750a475 100644
--- a/core/src/test/java/org/springframework/security/acl/basic/cache/EhCacheBasedAclEntryCacheTests.java
+++ b/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 ===================================================================================================
-
- public EhCacheBasedAclEntryCacheTests() {
- super();
- }
-
- public EhCacheBasedAclEntryCacheTests(String arg0) {
- super(arg0);
- }
+ private static CacheManager cacheManager;
//~ Methods ========================================================================================================
+ @BeforeClass
+ public static void initCacheManaer() {
+ cacheManager = new CacheManager();
+ cacheManager.addCache(new Cache("ehcachebasedacltests", 500, false, false, 30, 30));
+ }
+
+ @AfterClass
+ public static void shutdownCacheManager() {
+ cacheManager.removalAll();
+ cacheManager.shutdown();
+ }
+
private Ehcache getCache() {
- ApplicationContext ctx = MockApplicationContext.getContext();
+ Ehcache cache = cacheManager.getCache("ehcachebasedacltests");
+ cache.removeAll();
- return (Ehcache) ctx.getBean("eHCacheBackend");
+ return cache;
}
- public final void setUp() throws Exception {
- super.setUp();
- }
-
- 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 {
diff --git a/core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java b/core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java
index ce84556d32..ade24bed97 100644
--- a/core/src/test/java/org/springframework/security/intercept/method/aspectj/AspectJSecurityInterceptorTests.java
+++ b/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());
diff --git a/core/src/test/java/org/springframework/security/intercept/web/FilterSecurityInterceptorTests.java b/core/src/test/java/org/springframework/security/intercept/web/FilterSecurityInterceptorTests.java
index e237d296ed..f91b94509c 100644
--- a/core/src/test/java/org/springframework/security/intercept/web/FilterSecurityInterceptorTests.java
+++ b/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");
diff --git a/core/src/test/java/org/springframework/security/providers/dao/cache/EhCacheBasedUserCacheTests.java b/core/src/test/java/org/springframework/security/providers/dao/cache/EhCacheBasedUserCacheTests.java
index f4ae7af3c0..33210aea30 100644
--- a/core/src/test/java/org/springframework/security/providers/dao/cache/EhCacheBasedUserCacheTests.java
+++ b/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 EhCacheBasedUserCacheTests() {
- }
-
- public EhCacheBasedUserCacheTests(String arg0) {
- super(arg0);
- }
+public class EhCacheBasedUserCacheTests {
+ private static CacheManager cacheManager;
//~ Methods ========================================================================================================
+ @BeforeClass
+ public static void initCacheManaer() {
+ cacheManager = new CacheManager();
+ cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30));
+ }
+
+ @AfterClass
+ public static void shutdownCacheManager() {
+ cacheManager.removalAll();
+ cacheManager.shutdown();
+ }
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);
diff --git a/core/src/test/java/org/springframework/security/providers/x509/cache/EhCacheBasedX509UserCacheTests.java b/core/src/test/java/org/springframework/security/providers/x509/cache/EhCacheBasedX509UserCacheTests.java
index 50e430701e..1c5f9173da 100644
--- a/core/src/test/java/org/springframework/security/providers/x509/cache/EhCacheBasedX509UserCacheTests.java
+++ b/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 EhCacheBasedX509UserCacheTests() {
- }
-
- public EhCacheBasedX509UserCacheTests(String arg0) {
- super(arg0);
- }
+public class EhCacheBasedX509UserCacheTests {
+ private static CacheManager cacheManager;
//~ Methods ========================================================================================================
- private Ehcache getCache() {
- ApplicationContext ctx = MockApplicationContext.getContext();
+ @BeforeClass
+ public static void initCacheManaer() {
+ cacheManager = new CacheManager();
+ cacheManager.addCache(new Cache("x509cachetests", 500, false, false, 30, 30));
+ }
- return (Ehcache) ctx.getBean("eHCacheBackend");
+ @AfterClass
+ public static void shutdownCacheManager() {
+ cacheManager.removalAll();
+ cacheManager.shutdown();
+ }
+
+ private Ehcache getCache() {
+ Ehcache cache = cacheManager.getCache("x509cachetests");
+ cache.removeAll();
+
+ 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();
diff --git a/core/src/test/java/org/springframework/security/util/FilterChainProxyTests.java b/core/src/test/java/org/springframework/security/util/FilterChainProxyTests.java
index 85709396c0..f3c03b59de 100644
--- a/core/src/test/java/org/springframework/security/util/FilterChainProxyTests.java
+++ b/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
diff --git a/core/src/test/resources/org/springframework/security/applicationContext.xml b/core/src/test/resources/org/springframework/security/applicationContext.xml
deleted file mode 100644
index 1b9098f760..0000000000
--- a/core/src/test/resources/org/springframework/security/applicationContext.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pom.xml b/pom.xml
index e4c6ae63cb..5ac886e417 100644
--- a/pom.xml
+++ b/pom.xml
@@ -602,7 +602,7 @@
log4j
log4j
- 1.2.9
+ 1.2.13
true
runtime
diff --git a/portlet/pom.xml b/portlet/pom.xml
index cd2e363b38..9eacdb1be6 100644
--- a/portlet/pom.xml
+++ b/portlet/pom.xml
@@ -47,7 +47,7 @@
net.sf.ehcache
ehcache
- 1.2.4
+ 1.3.0
diff --git a/portlet/src/test/java/org/springframework/security/providers/portlet/cache/EhCacheBasedUserCacheTests.java b/portlet/src/test/java/org/springframework/security/providers/portlet/cache/EhCacheBasedUserCacheTests.java
index 5f4f284e0e..a9d20f78ea 100644
--- a/portlet/src/test/java/org/springframework/security/providers/portlet/cache/EhCacheBasedUserCacheTests.java
+++ b/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 {
+public class EhCacheBasedUserCacheTests {
+ //~ Static fields/initializers =====================================================================================
- //~ Static fields/initializers =====================================================================================
+ private static CacheManager cacheManager;
- private static EhCacheFactoryBean cacheFactory;
+ @BeforeClass
+ public static void initCacheManaer() {
+ cacheManager = new CacheManager();
+ cacheManager.addCache(new Cache("portletusercachetests", 500, false, false, 30, 30));
+ }
- static {
- cacheFactory = new EhCacheFactoryBean();
- cacheFactory.setCacheName("portletUserCache");
- try {
- cacheFactory.afterPropertiesSet();
- } catch (IOException e) {
- throw new RuntimeException("unable to initialize cache factory", e);
- }
- }
+ @AfterClass
+ public static void shutdownCacheManager() {
+ cacheManager.removalAll();
+ cacheManager.shutdown();
+ }
- //~ Constructors ===================================================================================================
+ private Cache getCache() {
+ Cache cache = cacheManager.getCache("portletusercachetests");
+ cache.removeAll();
- public EhCacheBasedUserCacheTests() {
- super();
- }
+ return cache;
+ }
- public EhCacheBasedUserCacheTests(String arg0) {
- super(arg0);
- }
-
- //~ Methods ========================================================================================================
-
- public final void setUp() throws Exception {
- super.setUp();
- }
-
- private Cache getCache() {
- return (Cache)cacheFactory.getObject();
- }
-
- 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);