polishing

This commit is contained in:
Stephane Nicoll 2014-05-26 13:39:38 +02:00
parent 05041ff39a
commit bb6e07bd3a
2 changed files with 12 additions and 42 deletions

View File

@ -36,16 +36,15 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
/**
*
@ -112,42 +111,27 @@ public class JCacheErrorHandlerTests {
@Configuration
@EnableCaching
static class Config {
static class Config extends JCacheConfigurerSupport {
@Bean(name = "jCacheInterceptor")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheInterceptor cacheInterceptor() {
JCacheInterceptor interceptor = new JCacheInterceptor();
interceptor.setCacheOperationSource(cacheOperationSource());
interceptor.setErrorHandler(errorHandler());
return interceptor;
@Bean
@Override
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(mockCache()));
return cacheManager;
}
@Bean
@Override
public CacheErrorHandler errorHandler() {
return mock(CacheErrorHandler.class);
}
@Bean(name = "jCacheOperationSource")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheOperationSource cacheOperationSource() {
DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
source.setCacheManager(cacheManager());
return source;
}
@Bean
public SimpleService simpleService() {
return new SimpleService();
}
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(mockCache()));
return cacheManager;
}
@Bean
public Cache mockCache() {
Cache cache = mock(Cache.class);

View File

@ -34,11 +34,11 @@ import org.junit.rules.ExpectedException;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.AnnotationCacheOperationSource;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.cache.support.SimpleValueWrapper;
@ -172,28 +172,14 @@ public class CacheErrorHandlerTests {
@Configuration
@EnableCaching
static class Config {
@Bean
public CacheInterceptor cacheInterceptor() {
CacheInterceptor cacheInterceptor = new CacheInterceptor();
cacheInterceptor.setCacheManager(cacheManager());
cacheInterceptor.setCacheOperationSources(cacheOperationSource());
cacheInterceptor.setErrorHandler(errorHandler());
return cacheInterceptor;
}
static class Config extends CachingConfigurerSupport {
@Bean
@Override
public CacheErrorHandler errorHandler() {
return mock(CacheErrorHandler.class);
}
@Bean
public CacheOperationSource cacheOperationSource() {
return new AnnotationCacheOperationSource();
}
@Bean
public SimpleService simpleService() {
return new SimpleService();