Rearranged cache test class names across several modules

This commit is contained in:
Juergen Hoeller 2015-11-26 16:30:44 +01:00
parent 331e739255
commit dd647659b3
11 changed files with 57 additions and 44 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.config.AbstractAnnotationTests;
import org.springframework.cache.config.AbstractCacheAnnotationTests;
import org.springframework.cache.config.CacheableService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
@ -30,17 +30,18 @@ import static org.junit.Assert.*;
/**
* @author Costin Leau
*/
public class AspectJAnnotationTests extends AbstractAnnotationTests {
public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
@Override
protected ConfigurableApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml");
return new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotation-cache-aspectj.xml");
}
@Test
public void testKeyStrategy() throws Exception {
AnnotationCacheAspect aspect = ctx.getBean("org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
AnnotationCacheAspect aspect = ctx.getBean(
"org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
}

View File

@ -33,6 +33,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
protected abstract Object getNativeCache();
@Test
public void testCacheName() throws Exception {
assertEquals(CACHE_NAME, getCache().getName());
@ -105,6 +106,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
assertNull(cache.get("enescu"));
}
private String createRandomKey() {
return UUID.randomUUID().toString();
}

View File

@ -28,7 +28,7 @@ import org.junit.Test;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.config.AbstractAnnotationTests;
import org.springframework.cache.config.AbstractCacheAnnotationTests;
import org.springframework.cache.config.AnnotatedClassCacheableService;
import org.springframework.cache.config.CacheableService;
import org.springframework.cache.config.DefaultCacheableService;
@ -43,7 +43,7 @@ import org.springframework.context.annotation.Configuration;
/**
* @author Stephane Nicoll
*/
public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests {
public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
private CacheManager jCacheManager;
@ -58,6 +58,10 @@ public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests {
return context;
}
protected CachingProvider getCachingProvider() {
return Caching.getCachingProvider();
}
@After
public void shutdown() {
if (jCacheManager != null) {
@ -73,11 +77,6 @@ public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests {
}
protected CachingProvider getCachingProvider() {
return Caching.getCachingProvider();
}
@Configuration
@EnableCaching
static class EnableCachingConfig extends CachingConfigurerSupport {

View File

@ -30,7 +30,7 @@ import org.springframework.cache.AbstractCacheTests;
/**
* @author Stephane Nicoll
*/
public class JCacheEhCacheTests extends AbstractCacheTests<JCacheCache> {
public class JCacheEhCacheApiTests extends AbstractCacheTests<JCacheCache> {
private CacheManager cacheManager;
@ -38,19 +38,27 @@ public class JCacheEhCacheTests extends AbstractCacheTests<JCacheCache> {
private JCacheCache cache;
@Before
public void setUp() {
public void setup() {
this.cacheManager = getCachingProvider().getCacheManager();
this.cacheManager.createCache(CACHE_NAME, new MutableConfiguration<>());
this.nativeCache = this.cacheManager.getCache(CACHE_NAME);
this.cache = new JCacheCache(this.nativeCache);
}
@After
public void shutdownCacheManager() {
this.cacheManager.close();
protected CachingProvider getCachingProvider() {
return Caching.getCachingProvider();
}
@After
public void shutdown() {
if (this.cacheManager != null) {
this.cacheManager.close();
}
}
@Override
protected JCacheCache getCache() {
return this.cache;
@ -61,8 +69,4 @@ public class JCacheEhCacheTests extends AbstractCacheTests<JCacheCache> {
return this.nativeCache;
}
protected CachingProvider getCachingProvider() {
return Caching.getCachingProvider();
}
}

View File

@ -34,14 +34,14 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Abstract annotation test (containing several reusable methods).
* Abstract cache annotation tests (containing several reusable methods).
*
* @author Costin Leau
* @author Chris Beams
* @author Phillip Webb
* @author Stephane Nicoll
*/
public abstract class AbstractAnnotationTests {
public abstract class AbstractCacheAnnotationTests {
protected ConfigurableApplicationContext ctx;
@ -72,7 +72,7 @@ public abstract class AbstractAnnotationTests {
}
@After
public void tearDown() {
public void close() {
if (ctx != null) {
ctx.close();
}
@ -128,7 +128,8 @@ public abstract class AbstractAnnotationTests {
assertSame(r1, r2);
try {
service.evictEarly(o1);
} catch (RuntimeException ex) {
}
catch (RuntimeException ex) {
// expected
}
@ -147,7 +148,8 @@ public abstract class AbstractAnnotationTests {
assertSame(r1, r2);
try {
service.evictWithException(o1);
} catch (RuntimeException ex) {
}
catch (RuntimeException ex) {
// expected
}
// exception occurred, eviction skipped, data should still be in the cache
@ -179,7 +181,8 @@ public abstract class AbstractAnnotationTests {
try {
service.invalidateEarly(o1, null);
} catch (Exception ex) {
}
catch (Exception ex) {
// expected
}
Object r3 = service.cache(o1);
@ -290,7 +293,8 @@ public abstract class AbstractAnnotationTests {
try {
service.throwChecked(arg);
fail("Excepted exception");
} catch (Exception ex) {
}
catch (Exception ex) {
assertEquals("Wrong exception type", IOException.class, ex.getClass());
assertEquals(arg, ex.getMessage());
}
@ -300,7 +304,8 @@ public abstract class AbstractAnnotationTests {
try {
service.throwUnchecked(Long.valueOf(1));
fail("Excepted exception");
} catch (RuntimeException ex) {
}
catch (RuntimeException ex) {
assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass());
assertEquals("1", ex.getMessage());
}
@ -623,7 +628,8 @@ public abstract class AbstractAnnotationTests {
Object param = new Object();
cs.unknownCustomKeyGenerator(param);
fail("should have failed with NoSuchBeanDefinitionException");
} catch (NoSuchBeanDefinitionException e) {
}
catch (NoSuchBeanDefinitionException ex) {
// expected
}
}
@ -645,7 +651,8 @@ public abstract class AbstractAnnotationTests {
Object param = new Object();
cs.unknownCustomCacheManager(param);
fail("should have failed with NoSuchBeanDefinitionException");
} catch (NoSuchBeanDefinitionException e) {
}
catch (NoSuchBeanDefinitionException ex) {
// expected
}
}

View File

@ -23,7 +23,7 @@ import org.springframework.context.support.GenericXmlApplicationContext;
* @author Costin Leau
* @author Chris Beams
*/
public class AnnotationTests extends AbstractAnnotationTests {
public class AnnotationDrivenCacheConfigTests extends AbstractCacheAnnotationTests {
@Override
protected ConfigurableApplicationContext getApplicationContext() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,7 +30,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @author Stephane Nicoll
*/
public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests {
@Override
protected ConfigurableApplicationContext getApplicationContext() {
@ -40,8 +40,8 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
@Test
public void testKeyStrategy() {
CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0",
CacheInterceptor.class);
CacheInterceptor ci = ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator());
}
@ -67,8 +67,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0",
CacheInterceptor.class);
CacheInterceptor ci = ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,7 +27,7 @@ import org.springframework.context.support.GenericXmlApplicationContext;
* @author Costin Leau
* @author Chris Beams
*/
public class CacheAdviceNamespaceTests extends AbstractAnnotationTests {
public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
@Override
protected ConfigurableApplicationContext getApplicationContext() {

View File

@ -44,7 +44,7 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @author Stephane Nicoll
*/
public class EnableCachingTests extends AbstractAnnotationTests {
public class EnableCachingTests extends AbstractCacheAnnotationTests {
/** hook into superclass suite of tests */
@Override

View File

@ -24,7 +24,6 @@ import javax.cache.spi.CachingProvider;
* runs against EhCache 2.x with the EhCache-JCache add-on.
*
* @author Juergen Hoeller
* @since 4.2.1
*/
public class JCacheEhCache3AnnotationTests extends JCacheEhCacheAnnotationTests {

View File

@ -25,7 +25,7 @@ import javax.cache.spi.CachingProvider;
*
* @author Stephane Nicoll
*/
public class JCacheEhcache3Tests extends JCacheEhCacheTests {
public class JCacheEhCache3ApiTests extends JCacheEhCacheApiTests {
@Override
protected CachingProvider getCachingProvider() {