polishing .aop tests
This commit is contained in:
parent
4671fd7141
commit
6966099d85
|
|
@ -19,13 +19,14 @@ package org.springframework.aop.aspectj;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.autoproxy.CountingTestBean;
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
|
||||||
|
import test.beans.CountingTestBean;
|
||||||
import test.beans.IOther;
|
import test.beans.IOther;
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
import test.beans.TestBean;
|
import test.beans.TestBean;
|
||||||
|
import test.beans.subpkg.DeepBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the {@link TypePatternClassFilter} class.
|
* Unit tests for the {@link TypePatternClassFilter} class.
|
||||||
|
|
@ -48,7 +49,7 @@ public final class TypePatternClassFilterTests {
|
||||||
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
|
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
|
||||||
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
|
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
|
||||||
assertTrue("Must match: in package", tpcf.matches(IOther.class));
|
assertTrue("Must match: in package", tpcf.matches(IOther.class));
|
||||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(CountingTestBean.class));
|
assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class));
|
||||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class));
|
assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class));
|
||||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class));
|
assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.aop.config;
|
package org.springframework.aop.config;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
@ -30,7 +31,7 @@ import org.springframework.beans.factory.parsing.ComponentDefinition;
|
||||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.parsing.CollectingReaderEventListener;
|
import test.parsing.CollectingReaderEventListener;
|
||||||
|
|
||||||
|
|
@ -42,12 +43,11 @@ import test.parsing.CollectingReaderEventListener;
|
||||||
public final class AopNamespaceHandlerEventTests {
|
public final class AopNamespaceHandlerEventTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = AopNamespaceHandlerEventTests.class;
|
private static final Class<?> CLASS = AopNamespaceHandlerEventTests.class;
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
|
||||||
|
|
||||||
private static final String CONTEXT = CLASSNAME + "-context.xml";
|
private static final Resource CONTEXT = qualifiedResource(CLASS, "context.xml");
|
||||||
private static final String POINTCUT_EVENTS_CONTEXT = CLASSNAME + "-pointcutEvents.xml";
|
private static final Resource POINTCUT_EVENTS_CONTEXT = qualifiedResource(CLASS, "pointcutEvents.xml");
|
||||||
private static final String POINTCUT_REF_CONTEXT = CLASSNAME + "-pointcutRefEvents.xml";
|
private static final Resource POINTCUT_REF_CONTEXT = qualifiedResource(CLASS, "pointcutRefEvents.xml");
|
||||||
private static final String DIRECT_POINTCUT_EVENTS_CONTEXT = CLASSNAME + "-directPointcutEvents.xml";
|
private static final Resource DIRECT_POINTCUT_EVENTS_CONTEXT = qualifiedResource(CLASS, "directPointcutEvents.xml");
|
||||||
|
|
||||||
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ public final class AopNamespaceHandlerEventTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPointcutEvents() throws Exception {
|
public void testPointcutEvents() throws Exception {
|
||||||
loadBeansFrom(POINTCUT_EVENTS_CONTEXT);
|
this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
|
||||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||||
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
|
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
|
||||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||||
|
|
@ -89,7 +89,7 @@ public final class AopNamespaceHandlerEventTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdvisorEventsWithPointcutRef() throws Exception {
|
public void testAdvisorEventsWithPointcutRef() throws Exception {
|
||||||
loadBeansFrom(POINTCUT_REF_CONTEXT);
|
this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT);
|
||||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ public final class AopNamespaceHandlerEventTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdvisorEventsWithDirectPointcut() throws Exception {
|
public void testAdvisorEventsWithDirectPointcut() throws Exception {
|
||||||
loadBeansFrom(DIRECT_POINTCUT_EVENTS_CONTEXT);
|
this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
|
||||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ public final class AopNamespaceHandlerEventTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAspectEvent() throws Exception {
|
public void testAspectEvent() throws Exception {
|
||||||
loadBeansFrom(CONTEXT);
|
this.reader.loadBeanDefinitions(CONTEXT);
|
||||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||||
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
|
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
|
||||||
|
|
||||||
|
|
@ -192,8 +192,4 @@ public final class AopNamespaceHandlerEventTests {
|
||||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBeansFrom(String path) {
|
|
||||||
this.reader.loadBeanDefinitions(new ClassPathResource(path, getClass()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
package org.springframework.aop.config;
|
package org.springframework.aop.config;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
|
@ -30,19 +30,10 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
*/
|
*/
|
||||||
public final class AopNamespaceHandlerPointcutErrorTests {
|
public final class AopNamespaceHandlerPointcutErrorTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = AopNamespaceHandlerPointcutErrorTests.class;
|
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
|
||||||
|
|
||||||
private static final ClassPathResource DUPLICATION_CONTEXT =
|
|
||||||
new ClassPathResource(CLASSNAME + "-pointcutDuplication.xml", CLASS);
|
|
||||||
|
|
||||||
private static final ClassPathResource MISSING_CONTEXT =
|
|
||||||
new ClassPathResource(CLASSNAME + "-pointcutMissing.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDuplicatePointcutConfig() {
|
public void testDuplicatePointcutConfig() {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(DUPLICATION_CONTEXT);
|
new XmlBeanFactory(qualifiedResource(getClass(), "pointcutDuplication.xml"));
|
||||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||||
}
|
}
|
||||||
catch (BeanDefinitionStoreException ex) {
|
catch (BeanDefinitionStoreException ex) {
|
||||||
|
|
@ -53,7 +44,7 @@ public final class AopNamespaceHandlerPointcutErrorTests {
|
||||||
@Test
|
@Test
|
||||||
public void testMissingPointcutConfig() {
|
public void testMissingPointcutConfig() {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(MISSING_CONTEXT);
|
new XmlBeanFactory(qualifiedResource(getClass(), "pointcutMissing.xml"));
|
||||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||||
}
|
}
|
||||||
catch (BeanDefinitionStoreException ex) {
|
catch (BeanDefinitionStoreException ex) {
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@
|
||||||
package org.springframework.aop.config;
|
package org.springframework.aop.config;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the <aop:config/> element can be used as a top level element.
|
* Tests that the <aop:config/> element can be used as a top level element.
|
||||||
|
|
@ -31,9 +32,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
*/
|
*/
|
||||||
public final class TopLevelAopTagTests {
|
public final class TopLevelAopTagTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = TopLevelAopTagTests.class;
|
private static final Resource CONTEXT = qualifiedResource(TopLevelAopTagTests.class, "context.xml");
|
||||||
private static final ClassPathResource CONTEXT =
|
|
||||||
new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParse() throws Exception {
|
public void testParse() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.aop.framework;
|
package org.springframework.aop.framework;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
@ -32,9 +32,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
*/
|
*/
|
||||||
public final class PrototypeTargetTests {
|
public final class PrototypeTargetTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = PrototypeTargetTests.class;
|
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml");
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
|
||||||
private static final ClassPathResource CONTEXT = new ClassPathResource(CLASSNAME + "-context.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrototypeProxyWithPrototypeTarget() {
|
public void testPrototypeProxyWithPrototypeTarget() {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.aop.interceptor;
|
package org.springframework.aop.interceptor;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import junit.framework.TestCase;
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
import test.beans.TestBean;
|
import test.beans.TestBean;
|
||||||
|
|
@ -33,11 +33,10 @@ import test.beans.TestBean;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ExposeInvocationInterceptorTests {
|
public final class ExposeInvocationInterceptorTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = ExposeInvocationInterceptorTests.class;
|
private static final Resource CONTEXT =
|
||||||
private static final ClassPathResource CONTEXT =
|
qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml");
|
||||||
new ClassPathResource(CLASS.getSimpleName() + "-context.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlConfig() {
|
public void testXmlConfig() {
|
||||||
|
|
@ -72,8 +71,8 @@ abstract class ExposedInvocationTestBean extends TestBean {
|
||||||
|
|
||||||
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||||
protected void assertions(MethodInvocation invocation) {
|
protected void assertions(MethodInvocation invocation) {
|
||||||
TestCase.assertTrue(invocation.getThis() == this);
|
assertTrue(invocation.getThis() == this);
|
||||||
TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||||
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
|
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,11 @@
|
||||||
package org.springframework.aop.scope;
|
package org.springframework.aop.scope;
|
||||||
|
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
|
@ -29,12 +30,9 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
public final class ScopedProxyAutowireTests {
|
public final class ScopedProxyAutowireTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = ScopedProxyAutowireTests.class;
|
private static final Class<?> CLASS = ScopedProxyAutowireTests.class;
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
|
||||||
|
|
||||||
private static final ClassPathResource SCOPED_AUTOWIRE_TRUE_CONTEXT =
|
private static final Resource SCOPED_AUTOWIRE_TRUE_CONTEXT = qualifiedResource(CLASS, "scopedAutowireTrue.xml");
|
||||||
new ClassPathResource(CLASSNAME + "-scopedAutowireTrue.xml", CLASS);
|
private static final Resource SCOPED_AUTOWIRE_FALSE_CONTEXT = qualifiedResource(CLASS, "scopedAutowireFalse.xml");
|
||||||
private static final ClassPathResource SCOPED_AUTOWIRE_FALSE_CONTEXT =
|
|
||||||
new ClassPathResource(CLASSNAME + "-scopedAutowireFalse.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScopedProxyInheritsAutowireCandidateFalse() {
|
public void testScopedProxyInheritsAutowireCandidateFalse() {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ public final class NameMatchMethodPointcutTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an empty pointcut, populating instance variables.
|
* Create an empty pointcut, populating instance variables.
|
||||||
* @see junit.framework.TestCase#setUp()
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.aop.NopInterceptor;
|
import test.aop.NopInterceptor;
|
||||||
import test.aop.SerializableNopInterceptor;
|
import test.aop.SerializableNopInterceptor;
|
||||||
|
|
@ -37,11 +38,8 @@ import test.util.SerializationTestUtils;
|
||||||
*/
|
*/
|
||||||
public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
public final class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = RegexpMethodPointcutAdvisorIntegrationTests.class;
|
private static final Resource CONTEXT =
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml");
|
||||||
|
|
||||||
private static final ClassPathResource CONTEXT =
|
|
||||||
new ClassPathResource(CLASSNAME + "-context.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSinglePattern() throws Throwable {
|
public void testSinglePattern() throws Throwable {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
|
|
||||||
|
|
@ -32,12 +33,15 @@ import test.beans.ITestBean;
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public final class CommonsPoolTargetSourceProxyTests {
|
public final class CommonsPoolTargetSourceProxyTests {
|
||||||
|
|
||||||
|
private static final Resource CONTEXT =
|
||||||
|
qualifiedResource(CommonsPoolTargetSourceProxyTests.class, "context.xml");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProxy() throws Exception {
|
public void testProxy() throws Exception {
|
||||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("CommonsPoolTargetSourceProxyTests-context.xml", getClass()));
|
reader.loadBeanDefinitions(CONTEXT);
|
||||||
beanFactory.preInstantiateSingletons();
|
beanFactory.preInstantiateSingletons();
|
||||||
ITestBean bean = (ITestBean)beanFactory.getBean("testBean");
|
ITestBean bean = (ITestBean)beanFactory.getBean("testBean");
|
||||||
assertTrue(AopUtils.isAopProxy(bean));
|
assertTrue(AopUtils.isAopProxy(bean));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
@ -25,7 +26,7 @@ import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.aop.SerializableNopInterceptor;
|
import test.aop.SerializableNopInterceptor;
|
||||||
import test.beans.Person;
|
import test.beans.Person;
|
||||||
|
|
@ -39,6 +40,8 @@ import test.util.SerializationTestUtils;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class HotSwappableTargetSourceTests {
|
public final class HotSwappableTargetSourceTests {
|
||||||
|
|
||||||
|
private static final Resource CONTEXT = qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml");
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
@ -47,8 +50,7 @@ public final class HotSwappableTargetSourceTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new XmlBeanFactory(
|
this.beanFactory = new XmlBeanFactory(CONTEXT);
|
||||||
new ClassPathResource("HotSwappableTargetSourceTests-context.xml", getClass()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
|
|
||||||
|
|
@ -35,14 +36,10 @@ import test.beans.ITestBean;
|
||||||
public final class LazyInitTargetSourceTests {
|
public final class LazyInitTargetSourceTests {
|
||||||
|
|
||||||
private static final Class<?> CLASS = LazyInitTargetSourceTests.class;
|
private static final Class<?> CLASS = LazyInitTargetSourceTests.class;
|
||||||
private static final String CLASSNAME = CLASS.getSimpleName();
|
|
||||||
|
|
||||||
private static final ClassPathResource SINGLETON_CONTEXT =
|
private static final Resource SINGLETON_CONTEXT = qualifiedResource(CLASS, "singleton.xml");
|
||||||
new ClassPathResource(CLASSNAME + "-singleton.xml", CLASS);
|
private static final Resource CUSTOM_TARGET_CONTEXT = qualifiedResource(CLASS, "customTarget.xml");
|
||||||
private static final ClassPathResource CUSTOM_TARGET_CONTEXT =
|
private static final Resource FACTORY_BEAN_CONTEXT = qualifiedResource(CLASS, "factoryBean.xml");
|
||||||
new ClassPathResource(CLASSNAME + "-customTarget.xml", CLASS);
|
|
||||||
private static final ClassPathResource FACTORY_BEAN_CONTEXT =
|
|
||||||
new ClassPathResource(CLASSNAME + "-factoryBean.xml", CLASS);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLazyInitSingletonTargetSource() {
|
public void testLazyInitSingletonTargetSource() {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.beans.SideEffectBean;
|
import test.beans.SideEffectBean;
|
||||||
|
|
||||||
|
|
@ -33,8 +34,7 @@ import test.beans.SideEffectBean;
|
||||||
*/
|
*/
|
||||||
public final class PrototypeTargetSourceTests {
|
public final class PrototypeTargetSourceTests {
|
||||||
|
|
||||||
private static final ClassPathResource CONTEXT =
|
private static final Resource CONTEXT = qualifiedResource(PrototypeTargetSourceTests.class, "context.xml");
|
||||||
new ClassPathResource("PrototypeTargetSourceTests-context.xml", PrototypeTargetSourceTests.class);
|
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static test.util.TestResourceUtils.qualifiedResource;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
import test.beans.SideEffectBean;
|
import test.beans.SideEffectBean;
|
||||||
|
|
@ -33,8 +34,7 @@ import test.beans.SideEffectBean;
|
||||||
*/
|
*/
|
||||||
public class ThreadLocalTargetSourceTests {
|
public class ThreadLocalTargetSourceTests {
|
||||||
|
|
||||||
private static final ClassPathResource CONTEXT =
|
private static final Resource CONTEXT = qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml");
|
||||||
new ClassPathResource("ThreadLocalTargetSourceTests-context.xml", ThreadLocalTargetSourceTests.class);
|
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.aop.framework.autoproxy;
|
package test.beans;
|
||||||
|
|
||||||
import test.beans.TestBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
/*
|
/*
|
||||||
* The Spring Framework is published under the terms
|
* Copyright 2002-2008 the original author or authors.
|
||||||
* of the Apache Software License.
|
*
|
||||||
|
* 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 test.util;
|
package test.util;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2008 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.
|
||||||
|
* 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 test.util;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience utilities for common operations with test resources.
|
||||||
|
*
|
||||||
|
* @author Chris Beams
|
||||||
|
*/
|
||||||
|
public class TestResourceUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a {@link ClassPathResource} qualified by the simple name of clazz,
|
||||||
|
* and relative to the package for clazz.
|
||||||
|
*
|
||||||
|
* <p>Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml',
|
||||||
|
* this method will return a ClassPathResource representing com/foo/BarTests-context.xml
|
||||||
|
*
|
||||||
|
* <p>Intended for use loading context configuration XML files within JUnit tests.
|
||||||
|
*
|
||||||
|
* @param clazz
|
||||||
|
* @param resourceSuffix
|
||||||
|
*/
|
||||||
|
public static ClassPathResource qualifiedResource(Class<?> clazz, String resourceSuffix) {
|
||||||
|
return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 the original author or authors.
|
* Copyright 2002-2008 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue