moving unit tests from .testsuite -> .aop
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -28,7 +28,7 @@ import org.xml.sax.SAXParseException;
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
*/
|
||||
public class AopNamespaceAdviceTypeTests extends TestCase {
|
||||
public class AopNamespaceAdviceTypeTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -40,10 +40,12 @@ public class AopNamespaceAdviceTypeTests extends TestCase {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingOfAdviceTypes() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingOfAdviceTypesWithError() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -26,7 +27,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
*/
|
||||
public class AopNamespaceHandlerArgNamesTests extends TestCase {
|
||||
public class AopNamespaceHandlerArgNamesTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -38,10 +39,12 @@ public class AopNamespaceHandlerArgNamesTests extends TestCase {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgNamesOK() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgNamesError() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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 org.springframework.aop.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanReference;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.parsing.CollectingReaderEventListener;
|
||||
import org.springframework.beans.factory.parsing.ComponentDefinition;
|
||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AopNamespaceHandlerEventTests extends TestCase {
|
||||
|
||||
private CollectingReaderEventListener eventListener = new CollectingReaderEventListener();
|
||||
|
||||
private XmlBeanDefinitionReader reader;
|
||||
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
this.reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||
this.reader.setEventListener(this.eventListener);
|
||||
}
|
||||
|
||||
public void testPointcutEvents() throws Exception {
|
||||
loadBeansFrom("aopNamespaceHandlerPointcutEventTests.xml");
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
PointcutComponentDefinition pcd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
if (componentDefinition instanceof PointcutComponentDefinition) {
|
||||
pcd = (PointcutComponentDefinition) componentDefinition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull("PointcutComponentDefinition not found", pcd);
|
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
||||
}
|
||||
|
||||
public void testAdvisorEventsWithPointcutRef() throws Exception {
|
||||
loadBeansFrom("aopNamespaceHandlerAdvisorWithPointcutRefEventTests.xml");
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length);
|
||||
AdvisorComponentDefinition acd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
if (componentDefinition instanceof AdvisorComponentDefinition) {
|
||||
acd = (AdvisorComponentDefinition) componentDefinition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull("AdvisorComponentDefinition not found", acd);
|
||||
assertEquals(1, acd.getBeanDefinitions().length);
|
||||
assertEquals(2, acd.getBeanReferences().length);
|
||||
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
|
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
|
||||
assertEquals("countingAdvice", adviceDef.getBeanName());
|
||||
}
|
||||
|
||||
public void testAdvisorEventsWithDirectPointcut() throws Exception {
|
||||
loadBeansFrom("aopNamespaceHandlerAdvisorWithDirectPointcutEventTests.xml");
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
AdvisorComponentDefinition acd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
if (componentDefinition instanceof AdvisorComponentDefinition) {
|
||||
acd = (AdvisorComponentDefinition) componentDefinition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull("AdvisorComponentDefinition not found", acd);
|
||||
assertEquals(2, acd.getBeanDefinitions().length);
|
||||
assertEquals(1, acd.getBeanReferences().length);
|
||||
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
|
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
|
||||
assertEquals("countingAdvice", adviceDef.getBeanName());
|
||||
}
|
||||
|
||||
public void testAspectEvent() throws Exception {
|
||||
loadBeansFrom("aopNamespaceHandlerAspectEventTests.xml");
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
|
||||
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
AspectComponentDefinition acd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
if (componentDefinition instanceof AspectComponentDefinition) {
|
||||
acd = (AspectComponentDefinition) componentDefinition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull("AspectComponentDefinition not found", acd);
|
||||
BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
|
||||
assertEquals(5, beanDefinitions.length);
|
||||
BeanReference[] beanReferences = acd.getBeanReferences();
|
||||
assertEquals(6, beanReferences.length);
|
||||
|
||||
Set expectedReferences = new HashSet();
|
||||
expectedReferences.add("pc");
|
||||
expectedReferences.add("countingAdvice");
|
||||
for (int i = 0; i < beanReferences.length; i++) {
|
||||
BeanReference beanReference = beanReferences[i];
|
||||
expectedReferences.remove(beanReference.getBeanName());
|
||||
}
|
||||
assertEquals("Incorrect references found", 0, expectedReferences.size());
|
||||
|
||||
for (int i = 1; i < componentDefinitions.length; i++) {
|
||||
assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition);
|
||||
}
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
|
||||
assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length);
|
||||
assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition);
|
||||
PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
|
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
||||
}
|
||||
|
||||
private void loadBeansFrom(String path) {
|
||||
this.reader.loadBeanDefinitions(new ClassPathResource(path, getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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 org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class AopNamespaceHandlerPointcutErrorTests extends TestCase {
|
||||
|
||||
public void testDuplicatePointcutConfig() {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource(
|
||||
"org/springframework/aop/config/aopNamespaceHandlerPointcutDuplicationTests.xml"));
|
||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void testMissingPointcutConfig() {
|
||||
try {
|
||||
new XmlBeanFactory(new ClassPathResource(
|
||||
"org/springframework/aop/config/aopNamespaceHandlerPointcutMissingTests.xml"));
|
||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.ITestBean;
|
||||
|
||||
@@ -24,6 +27,7 @@ import org.springframework.beans.ITestBean;
|
||||
*/
|
||||
public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testIsClassProxy() {
|
||||
ITestBean bean = getTestBean();
|
||||
assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean));
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -27,7 +28,7 @@ import org.xml.sax.SAXParseException;
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
*/
|
||||
public class AopNamespaceHandlerReturningTests extends TestCase {
|
||||
public class AopNamespaceHandlerReturningTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -39,10 +40,12 @@ public class AopNamespaceHandlerReturningTests extends TestCase {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturningOnReturningAdvice() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseReturningOnOtherAdviceType() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.ITestBean;
|
||||
@@ -33,10 +35,11 @@ import org.springframework.web.context.support.XmlWebApplicationContext;
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AopNamespaceHandlerScopeTests extends TestCase {
|
||||
public class AopNamespaceHandlerScopeTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
||||
wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml"});
|
||||
@@ -44,6 +47,7 @@ public class AopNamespaceHandlerScopeTests extends TestCase {
|
||||
this.context = wac;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestScoping() throws Exception {
|
||||
MockHttpServletRequest oldRequest = new MockHttpServletRequest();
|
||||
MockHttpServletRequest newRequest = new MockHttpServletRequest();
|
||||
@@ -71,6 +75,7 @@ public class AopNamespaceHandlerScopeTests extends TestCase {
|
||||
assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionScoping() throws Exception {
|
||||
MockHttpSession oldSession = new MockHttpSession();
|
||||
MockHttpSession newSession = new MockHttpSession();
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.CountingBeforeAdvice;
|
||||
@@ -28,10 +31,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class AopNamespaceHandlerTests extends TestCase {
|
||||
public class AopNamespaceHandlerTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.context = new ClassPathXmlApplicationContext(getConfigLocation());
|
||||
}
|
||||
@@ -40,6 +44,7 @@ public class AopNamespaceHandlerTests extends TestCase {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerTests.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsProxy() throws Exception {
|
||||
ITestBean bean = getTestBean();
|
||||
|
||||
@@ -52,6 +57,7 @@ public class AopNamespaceHandlerTests extends TestCase {
|
||||
assertTrue("Advisors should not be empty", advisors.length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdviceInvokedCorrectly() throws Exception {
|
||||
CountingBeforeAdvice getAgeCounter = (CountingBeforeAdvice) this.context.getBean("getAgeCounter");
|
||||
CountingBeforeAdvice getNameCounter = (CountingBeforeAdvice) this.context.getBean("getNameCounter");
|
||||
@@ -72,6 +78,7 @@ public class AopNamespaceHandlerTests extends TestCase {
|
||||
assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectApplied() throws Exception {
|
||||
ITestBean testBean = getTestBean();
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -27,7 +28,7 @@ import org.xml.sax.SAXParseException;
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
*/
|
||||
public class AopNamespaceHandlerThrowingTests extends TestCase {
|
||||
public class AopNamespaceHandlerThrowingTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -39,10 +40,12 @@ public class AopNamespaceHandlerThrowingTests extends TestCase {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrowingOnThrowingAdvice() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseThrowingOnOtherAdviceType() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.mock.easymock.AbstractScalarMockTemplate;
|
||||
@@ -28,21 +30,24 @@ import org.springframework.test.AssertThrows;
|
||||
/**
|
||||
* @author Rick Evans
|
||||
*/
|
||||
public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
public final class MethodLocatingFactoryBeanTests {
|
||||
|
||||
private static final String BEAN_NAME = "string";
|
||||
|
||||
|
||||
@Test
|
||||
public void testIsSingleton() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
assertTrue(factory.isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectType() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
assertEquals(Method.class, factory.getObjectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNullTargetBeanName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
@@ -57,6 +62,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyTargetBeanName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
@@ -72,6 +78,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNullTargetMethodName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
@@ -86,6 +93,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyTargetMethodName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
@@ -101,6 +109,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetBeanClassCannotBeResolved() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
@@ -120,6 +129,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDayPath() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
@@ -140,6 +150,7 @@ public final class MethodLocatingFactoryBeanTests extends TestCase {
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereMethodCannotBeResolved() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class PrototypeProxyTests extends TestCase {
|
||||
public class PrototypeProxyTests {
|
||||
|
||||
@Test
|
||||
public void testInjectionBeforeWrappingCheckDoesNotKickInForPrototypeProxy() {
|
||||
new ClassPathXmlApplicationContext("prototypeProxy.xml", getClass());
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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 org.springframework.aop.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* Tests that the <aop:config/> element can be used as a top level element.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public final class TopLevelAopTagTests extends TestCase {
|
||||
|
||||
public void testParse() throws Exception {
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("topLevelAop.xml", getClass()));
|
||||
|
||||
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="countingAdvice" pointcut="within(org.springframework..*)"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:pointcut id="pc" expression="within(org.springframework..*)"/>
|
||||
<aop:advisor advice-ref="countingAdvice" pointcut-ref="pc"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice">
|
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/>
|
||||
<aop:before pointcut-ref="pc" method="myBeforeAdvice" />
|
||||
<aop:after pointcut-ref="pc" method="myAfterAdvice" />
|
||||
<aop:after-returning pointcut-ref="pc" method="myAfterReturningAdvice" returning="age"/>
|
||||
<aop:after-throwing pointcut-ref="pc" method="myAfterThrowingAdvice" throwing="ex"/>
|
||||
<aop:around pointcut-ref="pc" method="myAroundAdvice"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice">
|
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/>
|
||||
<aop:before pointcut-ref="pc" pointcut="execution(* getAge())" method="myBeforeAdvice"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:pointcut id="myPointcut" expression="within(org.springframework..*)"/>
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<aop:config>
|
||||
<aop:aspect id="countAgeCalls" ref="countingAdvice">
|
||||
<aop:pointcut id="pc" expression="execution(* getAge())"/>
|
||||
<aop:before method="myBeforeAdvice" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.config.CountingAspectJAdvice"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,12 +0,0 @@
|
||||
<config xmlns="http://www.springframework.org/schema/aop"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<pointcut id="testPointcut" expression="execution(* foo(..)) and within(springbank.dao.AccountDao+)"/>
|
||||
<pointcut id="testPointcut1" expression="execution(* springbank.dao.AccountDao.foo(..))"/>
|
||||
|
||||
<aspect ref="myAspect">
|
||||
<after method="foo" pointcut-ref="testPointcut"/>
|
||||
</aspect>
|
||||
|
||||
</config>
|
||||
Reference in New Issue
Block a user