moving unit tests from .testsuite -> .aop

This commit is contained in:
Chris Beams 2008-12-12 18:57:46 +00:00
parent 56908e32cd
commit 5cb1b1d17c
9 changed files with 371 additions and 63 deletions

View File

@ -144,7 +144,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
private final Set<Object> nonAdvisedBeans = Collections.synchronizedSet(new HashSet<Object>()); private final Set<Object> nonAdvisedBeans = Collections.synchronizedSet(new HashSet<Object>());
private final Map<Object, Class> proxyTypes = new ConcurrentHashMap<Object, Class>(); private final Map<Object, Class<?>> proxyTypes = new ConcurrentHashMap<Object, Class<?>>();
/** /**
@ -253,12 +253,12 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
} }
public Class predictBeanType(Class beanClass, String beanName) { public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
Object cacheKey = getCacheKey(beanClass, beanName); Object cacheKey = getCacheKey(beanClass, beanName);
return this.proxyTypes.get(cacheKey); return this.proxyTypes.get(cacheKey);
} }
public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
return null; return null;
} }
@ -268,7 +268,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
return wrapIfNecessary(bean, beanName, cacheKey); return wrapIfNecessary(bean, beanName, cacheKey);
} }
public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
Object cacheKey = getCacheKey(beanClass, beanName); Object cacheKey = getCacheKey(beanClass, beanName);
if (!this.targetSourcedBeans.contains(cacheKey)) { if (!this.targetSourcedBeans.contains(cacheKey)) {
@ -332,7 +332,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @param beanName the bean name * @param beanName the bean name
* @return the cache key for the given class and name * @return the cache key for the given class and name
*/ */
protected Object getCacheKey(Class beanClass, String beanName) { protected Object getCacheKey(Class<?> beanClass, String beanName) {
return beanClass.getName() + "_" + beanName; return beanClass.getName() + "_" + beanName;
} }
@ -379,7 +379,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see org.aopalliance.intercept.MethodInterceptor * @see org.aopalliance.intercept.MethodInterceptor
* @see #shouldSkip * @see #shouldSkip
*/ */
protected boolean isInfrastructureClass(Class beanClass) { protected boolean isInfrastructureClass(Class<?> beanClass) {
boolean retVal = Advisor.class.isAssignableFrom(beanClass) || boolean retVal = Advisor.class.isAssignableFrom(beanClass) ||
Advice.class.isAssignableFrom(beanClass) || Advice.class.isAssignableFrom(beanClass) ||
AopInfrastructureBean.class.isAssignableFrom(beanClass); AopInfrastructureBean.class.isAssignableFrom(beanClass);
@ -398,7 +398,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @param beanName the name of the bean * @param beanName the name of the bean
* @return whether to skip the given bean * @return whether to skip the given bean
*/ */
protected boolean shouldSkip(Class beanClass, String beanName) { protected boolean shouldSkip(Class<?> beanClass, String beanName) {
return false; return false;
} }
@ -412,7 +412,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @return a TargetSource for this bean * @return a TargetSource for this bean
* @see #setCustomTargetSourceCreators * @see #setCustomTargetSourceCreators
*/ */
protected TargetSource getCustomTargetSource(Class beanClass, String beanName) { protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName) {
// We can't create fancy target sources for directly registered singletons. // We can't create fancy target sources for directly registered singletons.
if (this.customTargetSourceCreators != null && if (this.customTargetSourceCreators != null &&
this.beanFactory != null && this.beanFactory.containsBean(beanName)) { this.beanFactory != null && this.beanFactory.containsBean(beanName)) {
@ -445,7 +445,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see #buildAdvisors * @see #buildAdvisors
*/ */
protected Object createProxy( protected Object createProxy(
Class beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) { Class<?> beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) {
ProxyFactory proxyFactory = new ProxyFactory(); ProxyFactory proxyFactory = new ProxyFactory();
// Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
@ -454,8 +454,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
if (!shouldProxyTargetClass(beanClass, beanName)) { if (!shouldProxyTargetClass(beanClass, beanName)) {
// Must allow for introductions; can't just set interfaces to // Must allow for introductions; can't just set interfaces to
// the target's interfaces only. // the target's interfaces only.
Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass, this.proxyClassLoader); Class<?>[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass, this.proxyClassLoader);
for (Class targetInterface : targetInterfaces) { for (Class<?> targetInterface : targetInterfaces) {
proxyFactory.addInterface(targetInterface); proxyFactory.addInterface(targetInterface);
} }
} }
@ -487,7 +487,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @return whether the given bean should be proxied with its target class * @return whether the given bean should be proxied with its target class
* @see AutoProxyUtils#shouldProxyTargetClass * @see AutoProxyUtils#shouldProxyTargetClass
*/ */
protected boolean shouldProxyTargetClass(Class beanClass, String beanName) { protected boolean shouldProxyTargetClass(Class<?> beanClass, String beanName) {
return (isProxyTargetClass() || return (isProxyTargetClass() ||
(this.beanFactory instanceof ConfigurableListableBeanFactory && (this.beanFactory instanceof ConfigurableListableBeanFactory &&
AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName))); AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName)));
@ -591,6 +591,6 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS * @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
*/ */
protected abstract Object[] getAdvicesAndAdvisorsForBean( protected abstract Object[] getAdvicesAndAdvisorsForBean(
Class beanClass, String beanName, TargetSource customTargetSource) throws BeansException; Class<?> beanClass, String beanName, TargetSource customTargetSource) throws BeansException;
} }

View File

@ -16,105 +16,115 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import static org.junit.Assert.*;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import org.junit.Test;
import org.springframework.aop.SpringProxy; import org.springframework.aop.SpringProxy;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
*/ */
public class AopProxyUtilsTests extends TestCase { public class AopProxyUtilsTests {
@Test
public void testCompleteProxiedInterfacesWorksWithNull() { public void testCompleteProxiedInterfacesWorksWithNull() {
AdvisedSupport as = new AdvisedSupport(); AdvisedSupport as = new AdvisedSupport();
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as); Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(2, completedInterfaces.length); assertEquals(2, completedInterfaces.length);
List ifaces = Arrays.asList(completedInterfaces); List<?> ifaces = Arrays.asList(completedInterfaces);
assertTrue(ifaces.contains(Advised.class)); assertTrue(ifaces.contains(Advised.class));
assertTrue(ifaces.contains(SpringProxy.class)); assertTrue(ifaces.contains(SpringProxy.class));
} }
@Test
public void testCompleteProxiedInterfacesWorksWithNullOpaque() { public void testCompleteProxiedInterfacesWorksWithNullOpaque() {
AdvisedSupport as = new AdvisedSupport(); AdvisedSupport as = new AdvisedSupport();
as.setOpaque(true); as.setOpaque(true);
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as); Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(1, completedInterfaces.length); assertEquals(1, completedInterfaces.length);
} }
@Test
public void testCompleteProxiedInterfacesAdvisedNotIncluded() { public void testCompleteProxiedInterfacesAdvisedNotIncluded() {
AdvisedSupport as = new AdvisedSupport(); AdvisedSupport as = new AdvisedSupport();
as.addInterface(ITestBean.class); as.addInterface(ITestBean.class);
as.addInterface(Comparable.class); as.addInterface(Comparable.class);
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as); Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(4, completedInterfaces.length); assertEquals(4, completedInterfaces.length);
// Can't assume ordering for others, so use a list // Can't assume ordering for others, so use a list
List l = Arrays.asList(completedInterfaces); List<?> l = Arrays.asList(completedInterfaces);
assertTrue(l.contains(Advised.class)); assertTrue(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class)); assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class)); assertTrue(l.contains(Comparable.class));
} }
@Test
public void testCompleteProxiedInterfacesAdvisedIncluded() { public void testCompleteProxiedInterfacesAdvisedIncluded() {
AdvisedSupport as = new AdvisedSupport(); AdvisedSupport as = new AdvisedSupport();
as.addInterface(ITestBean.class); as.addInterface(ITestBean.class);
as.addInterface(Comparable.class); as.addInterface(Comparable.class);
as.addInterface(Advised.class); as.addInterface(Advised.class);
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as); Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(4, completedInterfaces.length); assertEquals(4, completedInterfaces.length);
// Can't assume ordering for others, so use a list // Can't assume ordering for others, so use a list
List l = Arrays.asList(completedInterfaces); List<?> l = Arrays.asList(completedInterfaces);
assertTrue(l.contains(Advised.class)); assertTrue(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class)); assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class)); assertTrue(l.contains(Comparable.class));
} }
@Test
public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() { public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() {
AdvisedSupport as = new AdvisedSupport(); AdvisedSupport as = new AdvisedSupport();
as.setOpaque(true); as.setOpaque(true);
as.addInterface(ITestBean.class); as.addInterface(ITestBean.class);
as.addInterface(Comparable.class); as.addInterface(Comparable.class);
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as); Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(3, completedInterfaces.length); assertEquals(3, completedInterfaces.length);
// Can't assume ordering for others, so use a list // Can't assume ordering for others, so use a list
List l = Arrays.asList(completedInterfaces); List<?> l = Arrays.asList(completedInterfaces);
assertFalse(l.contains(Advised.class)); assertFalse(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class)); assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class)); assertTrue(l.contains(Comparable.class));
} }
@Test
public void testProxiedUserInterfacesWithSingleInterface() { public void testProxiedUserInterfacesWithSingleInterface() {
ProxyFactory pf = new ProxyFactory(); ProxyFactory pf = new ProxyFactory();
pf.setTarget(new TestBean()); pf.setTarget(new TestBean());
pf.addInterface(ITestBean.class); pf.addInterface(ITestBean.class);
Object proxy = pf.getProxy(); Object proxy = pf.getProxy();
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy); Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
assertEquals(1, userInterfaces.length); assertEquals(1, userInterfaces.length);
assertEquals(ITestBean.class, userInterfaces[0]); assertEquals(ITestBean.class, userInterfaces[0]);
} }
@Test
public void testProxiedUserInterfacesWithMultipleInterfaces() { public void testProxiedUserInterfacesWithMultipleInterfaces() {
ProxyFactory pf = new ProxyFactory(); ProxyFactory pf = new ProxyFactory();
pf.setTarget(new TestBean()); pf.setTarget(new TestBean());
pf.addInterface(ITestBean.class); pf.addInterface(ITestBean.class);
pf.addInterface(Comparable.class); pf.addInterface(Comparable.class);
Object proxy = pf.getProxy(); Object proxy = pf.getProxy();
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy); Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
assertEquals(2, userInterfaces.length); assertEquals(2, userInterfaces.length);
assertEquals(ITestBean.class, userInterfaces[0]); assertEquals(ITestBean.class, userInterfaces[0]);
assertEquals(Comparable.class, userInterfaces[1]); assertEquals(Comparable.class, userInterfaces[1]);
} }
@Test
public void testProxiedUserInterfacesWithNoInterface() { public void testProxiedUserInterfacesWithNoInterface() {
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0], Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0],
new InvocationHandler() { new InvocationHandler() {
@ -123,7 +133,7 @@ public class AopProxyUtilsTests extends TestCase {
} }
}); });
try { try {
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy); AopProxyUtils.proxiedUserInterfaces(proxy);
fail("Should have thrown IllegalArgumentException"); fail("Should have thrown IllegalArgumentException");
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {

View File

@ -16,8 +16,7 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import junit.framework.TestCase; import org.junit.Test;
import org.springframework.aop.support.DelegatingIntroductionInterceptor; import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
@ -26,10 +25,13 @@ import org.springframework.util.StopWatch;
/** /**
* Benchmarks for introductions. * Benchmarks for introductions.
* *
* NOTE: No assertions!
*
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
* @since 2.0 * @since 2.0
*/ */
public class IntroductionBenchmarkTests extends TestCase { public class IntroductionBenchmarkTests {
private static final int EXPECTED_COMPARE = 13; private static final int EXPECTED_COMPARE = 13;
@ -37,12 +39,8 @@ public class IntroductionBenchmarkTests extends TestCase {
private static final int INVOCATIONS = 100000; private static final int INVOCATIONS = 100000;
public void testBenchmarks() { @SuppressWarnings("serial")
timeManyInvocations();
}
public static class SimpleCounterIntroduction extends DelegatingIntroductionInterceptor implements Counter { public static class SimpleCounterIntroduction extends DelegatingIntroductionInterceptor implements Counter {
public int getCount() { public int getCount() {
return EXPECTED_COMPARE; return EXPECTED_COMPARE;
} }
@ -52,7 +50,8 @@ public class IntroductionBenchmarkTests extends TestCase {
int getCount(); int getCount();
} }
protected long timeManyInvocations() { @Test
public void timeManyInvocations() {
StopWatch sw = new StopWatch(); StopWatch sw = new StopWatch();
TestBean target = new TestBean(); TestBean target = new TestBean();
@ -82,6 +81,5 @@ public class IntroductionBenchmarkTests extends TestCase {
sw.stop(); sw.stop();
System.out.println(sw.prettyPrint()); System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
} }
} }

View File

@ -1,4 +1,4 @@
#Wed Oct 29 09:29:43 EDT 2008 #Fri Dec 12 10:33:53 PST 2008
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
@ -10,3 +10,259 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=true
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.lineSplit=80
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true

View File

@ -0,0 +1,4 @@
#Fri Dec 12 10:33:53 PST 2008
eclipse.preferences.version=1
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
formatter_settings_version=11

View File

@ -16,12 +16,15 @@
package org.springframework.aop.framework.autoproxy; package org.springframework.aop.framework.autoproxy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import junit.framework.TestCase; import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.CountingBeforeAdvice; import org.springframework.aop.framework.CountingBeforeAdvice;
import org.springframework.aop.framework.Lockable; import org.springframework.aop.framework.Lockable;
@ -41,8 +44,9 @@ import org.springframework.transaction.CallCountingTransactionManager;
* Tests for auto proxy creation by advisor recognition. * Tests for auto proxy creation by advisor recognition.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams
*/ */
public class AdvisorAutoProxyCreatorTests extends TestCase { public class AdvisorAutoProxyCreatorTests {
private static final String ADVISOR_APC_BEAN_NAME = "aapc"; private static final String ADVISOR_APC_BEAN_NAME = "aapc";
@ -55,6 +59,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
return new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml"); return new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml");
} }
@Test
public void testDefaultExclusionPrefix() throws Exception { public void testDefaultExclusionPrefix() throws Exception {
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME); DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME);
assertEquals(ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR, aapc.getAdvisorBeanNamePrefix()); assertEquals(ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR, aapc.getAdvisorBeanNamePrefix());
@ -64,18 +69,21 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
/** /**
* If no pointcuts match (no attrs) there should be proxying. * If no pointcuts match (no attrs) there should be proxying.
*/ */
@Test
public void testNoProxy() throws Exception { public void testNoProxy() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Object o = bf.getBean("noSetters"); Object o = bf.getBean("noSetters");
assertFalse(AopUtils.isAopProxy(o)); assertFalse(AopUtils.isAopProxy(o));
} }
@Test
public void testTxIsProxied() throws Exception { public void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
assertTrue(AopUtils.isAopProxy(test)); assertTrue(AopUtils.isAopProxy(test));
} }
@Test
public void testRegexpApplied() throws Exception { public void testRegexpApplied() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
@ -90,6 +98,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* appear in the chain before "specific" interceptors, * appear in the chain before "specific" interceptors,
* which are sourced from matching advisors * which are sourced from matching advisors
*/ */
@Test
public void testCommonInterceptorAndAdvisor() throws Exception { public void testCommonInterceptorAndAdvisor() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml"); BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml");
ITestBean test1 = (ITestBean) bf.getBean("test1"); ITestBean test1 = (ITestBean) bf.getBean("test1");
@ -119,6 +128,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* We have custom TargetSourceCreators but there's no match, and * We have custom TargetSourceCreators but there's no match, and
* hence no proxying, for this bean * hence no proxying, for this bean
*/ */
@Test
public void testCustomTargetSourceNoMatch() throws Exception { public void testCustomTargetSourceNoMatch() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml"); BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
@ -127,6 +137,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals("Kerry", test.getSpouse().getName()); assertEquals("Kerry", test.getSpouse().getName());
} }
@Test
public void testCustomPrototypeTargetSource() throws Exception { public void testCustomPrototypeTargetSource() throws Exception {
CountingTestBean.count = 0; CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml"); BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
@ -141,6 +152,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
CountingTestBean.count = 0; CountingTestBean.count = 0;
} }
@Test
public void testLazyInitTargetSource() throws Exception { public void testLazyInitTargetSource() throws Exception {
CountingTestBean.count = 0; CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml"); BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
@ -155,6 +167,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
CountingTestBean.count = 0; CountingTestBean.count = 0;
} }
@Test
public void testQuickTargetSourceCreator() throws Exception { public void testQuickTargetSourceCreator() throws Exception {
ClassPathXmlApplicationContext bf = ClassPathXmlApplicationContext bf =
new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/quickTargetSource.xml"); new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/quickTargetSource.xml");
@ -200,6 +213,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
} }
/* /*
@Test
public void testIntroductionIsProxied() throws Exception { public void testIntroductionIsProxied() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Object modifiable = bf.getBean("modifiable1"); Object modifiable = bf.getBean("modifiable1");
@ -209,6 +223,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
} }
*/ */
@Test
public void testTransactionAttributeOnMethod() throws Exception { public void testTransactionAttributeOnMethod() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
@ -230,6 +245,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
/** /**
* Should not roll back on servlet exception. * Should not roll back on servlet exception.
*/ */
@Test
public void testRollbackRulesOnMethodCauseRollback() throws Exception { public void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback"); Rollback rb = (Rollback) bf.getBean("rollback");
@ -255,6 +271,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals("Transaction counts match", 1, txMan.rollbacks); assertEquals("Transaction counts match", 1, txMan.rollbacks);
} }
@Test
public void testRollbackRulesOnMethodPreventRollback() throws Exception { public void testRollbackRulesOnMethodPreventRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback"); Rollback rb = (Rollback) bf.getBean("rollback");
@ -272,6 +289,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals("Transaction counts match", 1, txMan.commits); assertEquals("Transaction counts match", 1, txMan.commits);
} }
@Test
public void testProgrammaticRollback() throws Exception { public void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
@ -289,6 +307,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals(1, txMan.rollbacks); assertEquals(1, txMan.rollbacks);
} }
@Test
public void testWithOptimizedProxy() throws Exception { public void testWithOptimizedProxy() throws Exception {
BeanFactory beanFactory = new ClassPathXmlApplicationContext("org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml"); BeanFactory beanFactory = new ClassPathXmlApplicationContext("org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml");
@ -311,6 +330,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* The Modifiable behaviour of each instance of TestBean should be distinct. * The Modifiable behaviour of each instance of TestBean should be distinct.
*/ */
/* /*
@Test
public void testIntroductionViaPrototype() throws Exception { public void testIntroductionViaPrototype() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();

View File

@ -16,11 +16,13 @@
package org.springframework.aop.framework.autoproxy; package org.springframework.aop.framework.autoproxy;
import static org.junit.Assert.*;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import junit.framework.TestCase;
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.springframework.aop.TargetSource; import org.springframework.aop.TargetSource;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
@ -38,10 +40,12 @@ import org.springframework.context.support.StaticMessageSource;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
* @since 09.12.2003 * @since 09.12.2003
*/ */
public class AutoProxyCreatorTests extends TestCase { public class AutoProxyCreatorTests {
@Test
public void testBeanNameAutoProxyCreator() { public void testBeanNameAutoProxyCreator() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testInterceptor", TestInterceptor.class); sac.registerSingleton("testInterceptor", TestInterceptor.class);
@ -90,6 +94,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(7, ti.nrOfInvocations); assertEquals(7, ti.nrOfInvocations);
} }
@Test
public void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() { public void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testInterceptor", TestInterceptor.class); sac.registerSingleton("testInterceptor", TestInterceptor.class);
@ -114,7 +119,7 @@ public class AutoProxyCreatorTests extends TestCase {
singletonToBeProxied.getName(); singletonToBeProxied.getName();
assertEquals(1, ti.nrOfInvocations); assertEquals(1, ti.nrOfInvocations);
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied"); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(Proxy.isProxyClass(factory.getClass())); assertTrue(Proxy.isProxyClass(factory.getClass()));
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(tb)); assertFalse(AopUtils.isAopProxy(tb));
@ -123,6 +128,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(3, ti.nrOfInvocations); assertEquals(3, ti.nrOfInvocations);
} }
@Test
public void testCustomAutoProxyCreator() { public void testCustomAutoProxyCreator() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
@ -150,6 +156,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(2, tapc.testInterceptor.nrOfInvocations); assertEquals(2, tapc.testInterceptor.nrOfInvocations);
} }
@Test
public void testAutoProxyCreatorWithFactoryBean() { public void testAutoProxyCreatorWithFactoryBean() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
@ -159,7 +166,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
tapc.testInterceptor.nrOfInvocations = 0; tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied"); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(factory)); assertTrue(AopUtils.isCglibProxy(factory));
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
@ -169,6 +176,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(3, tapc.testInterceptor.nrOfInvocations); assertEquals(3, tapc.testInterceptor.nrOfInvocations);
} }
@Test
public void testAutoProxyCreatorWithFactoryBeanAndPrototype() { public void testAutoProxyCreatorWithFactoryBeanAndPrototype() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
@ -182,7 +190,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
tapc.testInterceptor.nrOfInvocations = 0; tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean prototypeFactory = (FactoryBean) sac.getBean("&prototypeFactoryToBeProxied"); FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(prototypeFactory)); assertTrue(AopUtils.isCglibProxy(prototypeFactory));
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(tb)); assertTrue(AopUtils.isCglibProxy(tb));
@ -192,6 +200,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(3, tapc.testInterceptor.nrOfInvocations); assertEquals(3, tapc.testInterceptor.nrOfInvocations);
} }
@Test
public void testAutoProxyCreatorWithFactoryBeanAndProxyObjectOnly() { public void testAutoProxyCreatorWithFactoryBeanAndProxyObjectOnly() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
@ -206,7 +215,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
tapc.testInterceptor.nrOfInvocations = 0; tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied"); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(factory)); assertFalse(AopUtils.isAopProxy(factory));
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
@ -222,6 +231,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals(2, tapc.testInterceptor.nrOfInvocations); assertEquals(2, tapc.testInterceptor.nrOfInvocations);
} }
@Test
public void testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() { public void testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() {
StaticApplicationContext sac = new StaticApplicationContext(); StaticApplicationContext sac = new StaticApplicationContext();
@ -238,7 +248,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
tapc.testInterceptor.nrOfInvocations = 0; tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean prototypeFactory = (FactoryBean) sac.getBean("&prototypeFactoryToBeProxied"); FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(prototypeFactory)); assertTrue(AopUtils.isCglibProxy(prototypeFactory));
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
assertFalse(AopUtils.isCglibProxy(tb)); assertFalse(AopUtils.isCglibProxy(tb));
@ -249,6 +259,7 @@ public class AutoProxyCreatorTests extends TestCase {
} }
@SuppressWarnings("serial")
public static class TestAutoProxyCreator extends AbstractAutoProxyCreator { public static class TestAutoProxyCreator extends AbstractAutoProxyCreator {
private boolean proxyFactoryBean = true; private boolean proxyFactoryBean = true;
@ -270,7 +281,7 @@ public class AutoProxyCreatorTests extends TestCase {
this.proxyObject = proxyObject; this.proxyObject = proxyObject;
} }
protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String name, TargetSource customTargetSource) { protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, TargetSource customTargetSource) {
if (StaticMessageSource.class.equals(beanClass)) { if (StaticMessageSource.class.equals(beanClass)) {
return DO_NOT_PROXY; return DO_NOT_PROXY;
} }

View File

@ -16,30 +16,27 @@
package org.springframework.aop.framework.autoproxy; package org.springframework.aop.framework.autoproxy;
import junit.framework.TestCase; import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Dave Syer * @author Dave Syer
* @author Chris Beams
*/ */
public class BeanNameAutoProxyCreatorInitTests extends TestCase { public class BeanNameAutoProxyCreatorInitTests {
@Test(expected=IllegalArgumentException.class)
public void testIgnoreAdvisorThatIsCurrentlyCreation() { public void testIgnoreAdvisorThatIsCurrentlyCreation() {
ClassPathXmlApplicationContext ctx = ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorInitTests.xml", getClass()); new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorInitTests.xml", getClass());
TestBean bean = (TestBean) ctx.getBean("bean"); TestBean bean = (TestBean) ctx.getBean("bean");
bean.setName("foo"); bean.setName("foo");
assertEquals("foo", bean.getName()); assertEquals("foo", bean.getName());
try { bean.setName(null); // should throw
bean.setName(null);
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
// expected
}
} }
} }

View File

@ -16,10 +16,12 @@
package org.springframework.aop.framework.autoproxy; package org.springframework.aop.framework.autoproxy;
import static org.junit.Assert.*;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase; import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.CountingBeforeAdvice; import org.springframework.aop.framework.CountingBeforeAdvice;
import org.springframework.aop.framework.Lockable; import org.springframework.aop.framework.Lockable;
@ -35,35 +37,41 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Rob Harrop * @author Rob Harrop
* @author Chris Beams
*/ */
public class BeanNameAutoProxyCreatorTests extends TestCase { public class BeanNameAutoProxyCreatorTests {
private BeanFactory beanFactory; private BeanFactory beanFactory;
protected void setUp() throws IOException { @Before
public void setUp() throws IOException {
// Note that we need an ApplicationContext, not just a BeanFactory, // Note that we need an ApplicationContext, not just a BeanFactory,
// for post-processing and hence auto-proxying to work. // for post-processing and hence auto-proxying to work.
this.beanFactory = new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorTests.xml", getClass()); this.beanFactory = new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorTests.xml", getClass());
} }
@Test
public void testNoProxy() { public void testNoProxy() {
TestBean tb = (TestBean) beanFactory.getBean("noproxy"); TestBean tb = (TestBean) beanFactory.getBean("noproxy");
assertFalse(AopUtils.isAopProxy(tb)); assertFalse(AopUtils.isAopProxy(tb));
assertEquals("noproxy", tb.getName()); assertEquals("noproxy", tb.getName());
} }
@Test
public void testJdkProxyWithExactNameMatch() { public void testJdkProxyWithExactNameMatch() {
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk"); ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
jdkAssertions(tb, 1); jdkAssertions(tb, 1);
assertEquals("onlyJdk", tb.getName()); assertEquals("onlyJdk", tb.getName());
} }
@Test
public void testJdkProxyWithDoubleProxying() { public void testJdkProxyWithDoubleProxying() {
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk"); ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
jdkAssertions(tb, 2); jdkAssertions(tb, 2);
assertEquals("doubleJdk", tb.getName()); assertEquals("doubleJdk", tb.getName());
} }
@Test
public void testJdkIntroduction() { public void testJdkIntroduction() {
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk"); ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
@ -102,6 +110,7 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
} }
} }
@Test
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() { public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk"); ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor"); NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
@ -139,18 +148,21 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
} }
} }
@Test
public void testJdkProxyWithWildcardMatch() { public void testJdkProxyWithWildcardMatch() {
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1"); ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
jdkAssertions(tb, 1); jdkAssertions(tb, 1);
assertEquals("jdk1", tb.getName()); assertEquals("jdk1", tb.getName());
} }
@Test
public void testCglibProxyWithWildcardMatch() { public void testCglibProxyWithWildcardMatch() {
TestBean tb = (TestBean) beanFactory.getBean("cglib1"); TestBean tb = (TestBean) beanFactory.getBean("cglib1");
cglibAssertions(tb); cglibAssertions(tb);
assertEquals("cglib1", tb.getName()); assertEquals("cglib1", tb.getName());
} }
@Test
public void testWithFrozenProxy() { public void testWithFrozenProxy() {
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean"); ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
assertTrue(((Advised)testBean).isFrozen()); assertTrue(((Advised)testBean).isFrozen());