Refactor cache support test hierarchy

Refactored getConfig => getApplicationContext such that subclasses have
control over the type of ApplicationContext used by the base class
tests. Done in anticipation of @EnableCaching tests that will favor use
of AnnotationConfigApplicationContext

Also updated all use of ClassPathXmlApplictionContext to
GenericXmlApplicationContext, which is generally preferred.
This commit is contained in:
Chris Beams
2011-11-16 04:20:39 +00:00
parent b7f9bf2e1c
commit 96200b690c
4 changed files with 30 additions and 10 deletions

View File

@@ -16,7 +16,13 @@
package org.springframework.cache.config;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collection;
import java.util.UUID;
@@ -27,12 +33,12 @@ import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Abstract annotation test (containing several reusable methods).
*
* @author Costin Leau
* @author Chris Beams
*/
public abstract class AbstractAnnotationTests {
@@ -44,11 +50,12 @@ public abstract class AbstractAnnotationTests {
protected CacheManager cm;
protected abstract String getConfig();
/** @return a refreshed application context */
protected abstract ApplicationContext getApplicationContext();
@Before
public void setup() {
ctx = new ClassPathXmlApplicationContext(getConfig());
ctx = getApplicationContext();
cs = ctx.getBean("service", CacheableService.class);
ccs = ctx.getBean("classService", CacheableService.class);
cm = ctx.getBean(CacheManager.class);

View File

@@ -20,15 +20,19 @@ import junit.framework.Assert;
import org.junit.Test;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
* @author Costin Leau
* @author Chris Beams
*/
public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
@Override
protected String getConfig() {
return "/org/springframework/cache/config/annotationDrivenCacheNamespace.xml";
protected ApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheNamespace.xml");
}
@Test

View File

@@ -16,13 +16,18 @@
package org.springframework.cache.config;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
* @author Costin Leau
* @author Chris Beams
*/
public class AnnotationTests extends AbstractAnnotationTests {
@Override
protected String getConfig() {
return "/org/springframework/cache/config/annotationDrivenCacheConfig.xml";
protected ApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheConfig.xml");
}
}

View File

@@ -19,15 +19,19 @@ package org.springframework.cache.config;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
* @author Costin Leau
* @author Chris Beams
*/
public class CacheAdviceNamespaceTests extends AbstractAnnotationTests {
@Override
protected String getConfig() {
return "/org/springframework/cache/config/cache-advice.xml";
protected ApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext(
"/org/springframework/cache/config/cache-advice.xml");
}
@Test