Browse Source

Refined AspectJ caching tests

Issue: SPR-14413
pull/1095/head
Juergen Hoeller 10 years ago
parent
commit
37e42e68e8
  1. 5
      spring-aspects/src/main/java/org/springframework/cache/aspectj/AspectJCachingConfiguration.java
  2. 43
      spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJEnableCachingIsolatedTests.java
  3. 3
      spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJEnableCachingTests.java

5
spring-aspects/src/main/java/org/springframework/cache/aspectj/AspectJCachingConfiguration.java vendored

@ -24,10 +24,11 @@ import org.springframework.context.annotation.Configuration; @@ -24,10 +24,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
/**
* {@code @Configuration} class that registers the Spring infrastructure beans necessary
* to enable AspectJ-based annotation-driven cache management.
* {@code @Configuration} class that registers the Spring infrastructure beans
* necessary to enable AspectJ-based annotation-driven cache management.
*
* @author Chris Beams
* @author Stephane Nicoll
* @since 3.1
* @see org.springframework.cache.annotation.EnableCaching
* @see org.springframework.cache.annotation.CachingConfigurationSelector

43
spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJEnableCachingIsolatedTests.java vendored

@ -31,7 +31,6 @@ import org.springframework.cache.config.DefaultCacheableService; @@ -31,7 +31,6 @@ import org.springframework.cache.config.DefaultCacheableService;
import org.springframework.cache.config.SomeCustomKeyGenerator;
import org.springframework.cache.config.SomeKeyGenerator;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.NamedCacheResolver;
@ -47,13 +46,17 @@ import org.springframework.context.annotation.Configuration; @@ -47,13 +46,17 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
*
* @author Stephane Nicoll
*/
public class AspectJEnableCachingIsolatedTests {
private ConfigurableApplicationContext ctx;
private void load(Class<?>... config) {
this.ctx = new AnnotationConfigApplicationContext(config);
}
@After
public void closeContext() {
if (this.ctx != null) {
@ -61,6 +64,7 @@ public class AspectJEnableCachingIsolatedTests { @@ -61,6 +64,7 @@ public class AspectJEnableCachingIsolatedTests {
}
}
@Test
public void testKeyStrategy() {
load(EnableCachingConfig.class);
@ -75,22 +79,21 @@ public class AspectJEnableCachingIsolatedTests { @@ -75,22 +79,21 @@ public class AspectJEnableCachingIsolatedTests {
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), aspect.getErrorHandler());
}
// --- local tests -------
@Test
public void singleCacheManagerBean() throws Throwable {
public void singleCacheManagerBean() {
load(SingleCacheManagerConfig.class);
}
@Test(expected = IllegalStateException.class)
public void multipleCacheManagerBeans() throws Throwable {
@Test
public void multipleCacheManagerBeans() {
try {
load(MultiCacheManagerConfig.class);
}
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
assertTrue(root.getMessage().contains("beans of type CacheManager"));
throw root;
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("bean of type CacheManager"));
}
}
@ -99,27 +102,25 @@ public class AspectJEnableCachingIsolatedTests { @@ -99,27 +102,25 @@ public class AspectJEnableCachingIsolatedTests {
load(MultiCacheManagerConfigurer.class); // does not throw
}
@Test(expected = IllegalStateException.class)
public void multipleCachingConfigurers() throws Throwable {
@Test
public void multipleCachingConfigurers() {
try {
load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
}
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
assertTrue(root.getMessage().contains("implementations of CachingConfigurer"));
throw root;
assertTrue(root instanceof IllegalStateException);
assertTrue(ex.getMessage().contains("implementations of CachingConfigurer"));
}
}
@Test(expected = IllegalStateException.class)
public void noCacheManagerBeans() throws Throwable {
@Test
public void noCacheManagerBeans() {
try {
load(EmptyConfig.class);
}
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
assertTrue(root.getMessage().contains("No bean of type CacheManager"));
throw root;
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("No bean of type CacheManager"));
}
}
@ -143,10 +144,6 @@ public class AspectJEnableCachingIsolatedTests { @@ -143,10 +144,6 @@ public class AspectJEnableCachingIsolatedTests {
assertSame(this.ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
}
private void load(Class<?>... config) {
this.ctx = new AnnotationConfigApplicationContext(config);
}
@Configuration
@EnableCaching(mode = AdviceMode.ASPECTJ)

3
spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJEnableCachingTests.java vendored

@ -36,17 +36,16 @@ import org.springframework.context.annotation.Bean; @@ -36,17 +36,16 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author Stephane Nicoll
*/
public class AspectJEnableCachingTests extends AbstractCacheAnnotationTests {
/** hook into superclass suite of tests */
@Override
protected ConfigurableApplicationContext getApplicationContext() {
return new AnnotationConfigApplicationContext(EnableCachingConfig.class);
}
@Configuration
@EnableCaching(mode = AdviceMode.ASPECTJ)
static class EnableCachingConfig extends CachingConfigurerSupport {

Loading…
Cancel
Save