moving unit tests from .testsuite -> .aop

@Ignore'd a portion of PersistenceXmlParsingTests#testExampleComplex: it is failing, but only under clover coverage runs
This commit is contained in:
Chris Beams
2008-12-12 20:09:17 +00:00
parent 04d3f984b1
commit 4c88488c5a
5 changed files with 78 additions and 75 deletions

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2002-2005 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.framework;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.beans.TestBean;
/**
* @author Rod Johnson
* @author Chris Beams
* @since 14.03.2003
*/
public class MethodInvocationTests {
@Test
public void testValidInvocation() throws Throwable {
Method m = Object.class.getMethod("hashCode", (Class[]) null);
Object proxy = new Object();
final Object returnValue = new Object();
List<Object> is = new LinkedList<Object>();
is.add(new MethodInterceptor() {
public Object invoke(MethodInvocation invocation) throws Throwable {
return returnValue;
}
});
ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, null, //?
m, null, null, is // list
);
Object rv = invocation.proceed();
assertTrue("correct response", rv == returnValue);
}
/**
* toString on target can cause failure.
*/
@Test
public void testToStringDoesntHitTarget() throws Throwable {
Object target = new TestBean() {
public String toString() {
throw new UnsupportedOperationException("toString");
}
};
List<Object> is = new LinkedList<Object>();
Method m = Object.class.getMethod("hashCode", (Class[]) null);
Object proxy = new Object();
ReflectiveMethodInvocation invocation =
new ReflectiveMethodInvocation(proxy, target, m, null, null, is);
// If it hits target, the test will fail with the UnsupportedOpException
// in the inner class above.
invocation.toString();
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2002-2005 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.framework;
import static org.junit.Assert.*;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
* @author Juergen Hoeller
* @since 03.09.2004
*/
public class PrototypeTargetTests {
@Test
public void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass()));
for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanPrototype");
tb.doSomething();
}
TestInterceptor interceptor = (TestInterceptor) xbf.getBean("testInterceptor");
assertEquals(10, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount);
}
@Test
public void testSingletonProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("prototypeTarget.xml", getClass()));
for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanSingleton");
tb.doSomething();
}
TestInterceptor interceptor = (TestInterceptor) xbf.getBean("testInterceptor");
assertEquals(1, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount);
}
public static interface TestBean {
public void doSomething();
}
public static class TestBeanImpl implements TestBean {
private static int constructionCount = 0;
public TestBeanImpl() {
constructionCount++;
}
public void doSomething() {
}
}
public static class TestInterceptor implements MethodInterceptor {
private int invocationCount = 0;
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
invocationCount++;
return methodInvocation.proceed();
}
}
}

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="testBeanTarget" class="org.springframework.aop.framework.PrototypeTargetTests$TestBeanImpl"
scope="prototype"/>
<bean id="testInterceptor" class="org.springframework.aop.framework.PrototypeTargetTests$TestInterceptor"
scope="singleton"/>
<bean id="testBeanPrototype" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.springframework.aop.framework.PrototypeTargetTests$TestBean</value>
</property>
<property name="singleton">
<value>false</value>
</property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
<value>testBeanTarget</value>
</list>
</property>
</bean>
<bean id="testBeanSingleton" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.springframework.aop.framework.PrototypeTargetTests$TestBean</value>
</property>
<property name="singleton">
<value>true</value>
</property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
<value>testBeanTarget</value>
</list>
</property>
</bean>
</beans>