moving unit tests from .testsuite -> .context
+ created example.scannable package to house scannable components away from .context.annotation package + example.scannable will also lend itself to sharing via externals
This commit is contained in:
parent
57eaf42424
commit
e944e2fcc5
|
@ -12,6 +12,8 @@
|
|||
<classpathentry kind="var" path="IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-1.1.0.jar" sourcepath="/IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-sources-1.1.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-1.5.1.jar" sourcepath="/IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-sources-1.5.1.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.beanshell/com.springsource.bsh/2.0.0.b4/com.springsource.bsh-2.0.0.b4.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm/2.2.3/com.springsource.org.objectweb.asm-2.2.3.jar" sourcepath="/IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm/2.2.3/com.springsource.org.objectweb.asm-sources-2.2.3.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-2.2.3.jar" sourcepath="/IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-sources-2.2.3.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/com.sun.enterprise/com.springsource.com.sun.enterprise.loader/1.0.0/com.springsource.com.sun.enterprise.loader-1.0.0.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/com.oracle.oc4j/com.springsource.oracle.classloader/10.1.3.1/com.springsource.oracle.classloader-10.1.3.1.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-3.0.0.jar" sourcepath="/IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-sources-3.0.0.jar"/>
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/>
|
||||
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="test->runtime"/>
|
||||
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="test->runtime"/>
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="test->runtime"/>
|
||||
</dependencies>
|
||||
|
||||
</ivy-module>
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
package org.springframework.context.annotation;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.test.AssertThrows;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link AnnotationScopeMetadataResolver} class.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
||||
public final class AnnotationScopeMetadataResolverTests {
|
||||
|
||||
private AnnotationScopeMetadataResolver scopeMetadataResolver;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
|
||||
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
|
||||
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
|
||||
|
@ -31,6 +35,7 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
|
||||
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
|
||||
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
|
||||
|
@ -40,20 +45,14 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
|||
assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCtorWithNullScopedProxyMode() {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new AnnotationScopeMetadataResolver(null);
|
||||
}
|
||||
}.runTest();
|
||||
new AnnotationScopeMetadataResolver(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSetScopeAnnotationTypeWithNullType() {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
scopeMetadataResolver.setScopeAnnotationType(null);
|
||||
}
|
||||
}.runTest();
|
||||
scopeMetadataResolver.setScopeAnnotationType(null);
|
||||
}
|
||||
|
||||
|
|
@ -16,12 +16,13 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
|
@ -35,13 +36,15 @@ import org.springframework.util.ClassUtils;
|
|||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||
public class ClassPathScanningCandidateComponentProviderTests {
|
||||
|
||||
private static final String TEST_BASE_PACKAGE =
|
||||
ClassPathScanningCandidateComponentProviderTests.class.getPackage().getName();
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithDefaults() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
|
@ -53,12 +56,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithBogusBasePackage() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
|
||||
assertEquals(0, candidates.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPackageExcludeFilter() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*")));
|
||||
|
@ -66,12 +71,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertEquals(0, candidates.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNoFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||
assertEquals(0, candidates.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithComponentAnnotationOnly() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
|
@ -88,6 +95,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testWithAspectAnnotationOnly() throws Exception {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(
|
||||
|
@ -97,6 +105,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterfaceType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||
|
@ -105,6 +114,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertTrue(containsBeanClass(candidates, StubFooDao.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithClassType() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
|
||||
|
@ -113,6 +123,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertTrue(containsBeanClass(candidates, MessageBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMultipleMatchingFilters() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||
|
@ -124,6 +135,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
|||
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExcludeTakesPrecedence() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -23,10 +25,9 @@ import java.util.List;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
|
@ -54,7 +55,7 @@ import org.springframework.util.ObjectUtils;
|
|||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
*/
|
||||
public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||
public class Spr3775InitDestroyLifecycleTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(Spr3775InitDestroyLifecycleTests.class);
|
||||
|
||||
|
@ -86,6 +87,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
return beanFactory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitDestroyMethods() {
|
||||
final Class<?> beanClass = InitDestroyBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
||||
|
@ -96,6 +98,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializingDisposableInterfaces() {
|
||||
final Class<?> beanClass = CustomInitializingDisposableBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||
|
@ -108,6 +111,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
bean.destroyMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializingDisposableInterfacesWithShadowedMethods() {
|
||||
final Class<?> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
||||
|
@ -119,6 +123,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsr250Annotations() {
|
||||
final Class<?> beanClass = CustomAnnotatedInitDestroyBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||
|
@ -131,6 +136,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
bean.destroyMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsr250AnnotationsWithShadowedMethods() {
|
||||
final Class<?> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||
|
@ -143,6 +149,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
|||
bean.destroyMethods);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllLifecycleMechanismsAtOnce() {
|
||||
final Class<?> beanClass = AllInOneBean.class;
|
||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
package example.scannable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
public @interface CustomComponent {
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.scannable;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Component
|
||||
public @interface CustomStereotype {
|
||||
|
||||
String value() default "thoreau";
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.scannable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@CustomStereotype
|
||||
public class DefaultNamedComponent {
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface FooDao {
|
||||
|
||||
String findFoo(int id);
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public interface FooService {
|
||||
|
||||
String foo(int id);
|
||||
|
||||
boolean isInitCalled();
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Service
|
||||
public class FooServiceImpl implements FooService {
|
||||
|
||||
@Autowired private FooDao fooDao;
|
||||
|
||||
@Autowired public BeanFactory beanFactory;
|
||||
|
||||
@Autowired public List<ListableBeanFactory> listableBeanFactory;
|
||||
|
||||
@Autowired public ResourceLoader resourceLoader;
|
||||
|
||||
@Autowired public ResourcePatternResolver resourcePatternResolver;
|
||||
|
||||
@Autowired public ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Autowired public MessageSource messageSource;
|
||||
|
||||
@Autowired public ApplicationContext context;
|
||||
|
||||
@Autowired public ConfigurableApplicationContext[] configurableContext;
|
||||
|
||||
@Autowired public AbstractApplicationContext genericContext;
|
||||
|
||||
private boolean initCalled = false;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
if (this.initCalled) {
|
||||
throw new IllegalStateException("Init already called");
|
||||
}
|
||||
this.initCalled = true;
|
||||
}
|
||||
|
||||
public String foo(int id) {
|
||||
return this.fooDao.findFoo(id);
|
||||
}
|
||||
|
||||
public boolean isInitCalled() {
|
||||
return this.initCalled;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@CustomComponent
|
||||
public class MessageBean {
|
||||
|
||||
private String message;
|
||||
|
||||
public MessageBean() {
|
||||
this.message = "DEFAULT MESSAGE";
|
||||
}
|
||||
|
||||
public MessageBean(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Component("myNamedComponent")
|
||||
public class NamedComponent {
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Repository("myNamedDao")
|
||||
public class NamedStubDao {
|
||||
|
||||
public String find(int id) {
|
||||
return "bar";
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
package example.scannable;
|
||||
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Component
|
||||
@Aspect
|
||||
public class ServiceInvocationCounter {
|
||||
|
||||
private int useCount;
|
||||
|
||||
@Pointcut("execution(* example.scannable.FooService+.*(..))")
|
||||
public void serviceExecution() {}
|
||||
|
||||
@Before("serviceExecution()")
|
||||
public void countUse() {
|
||||
this.useCount++;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.useCount;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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 example.scannable;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Repository
|
||||
@Qualifier("testing")
|
||||
public class StubFooDao implements FooDao {
|
||||
|
||||
public String findFoo(int id) {
|
||||
return "bar";
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,13 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -34,12 +35,14 @@ import org.springframework.util.StopWatch;
|
|||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 2.5
|
||||
*/
|
||||
public class AnnotationProcessorPerformanceTests extends TestCase {
|
||||
public class AnnotationProcessorPerformanceTests {
|
||||
|
||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
@ -65,6 +68,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
@ -91,6 +95,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
@ -116,6 +121,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
|
|||
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
|
||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||
// Skip this test: Trace logging blows the time limit.
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
|
@ -33,21 +35,28 @@ import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import example.scannable.CustomComponent;
|
||||
import example.scannable.FooService;
|
||||
import example.scannable.FooServiceImpl;
|
||||
import example.scannable.NamedStubDao;
|
||||
import example.scannable.StubFooDao;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||
public class ClassPathBeanDefinitionScannerTests {
|
||||
|
||||
private static final String BASE_PACKAGE =
|
||||
ClassPathBeanDefinitionScannerTests.class.getPackage().getName();
|
||||
private static final String BASE_PACKAGE = "example.scannable";
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, beanCount);
|
||||
assertEquals(10, beanCount);
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -59,11 +68,12 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleScan() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, beanCount);
|
||||
assertEquals(10, beanCount);
|
||||
scanner.scan(BASE_PACKAGE);
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
|
@ -73,12 +83,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean("thoreau"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setIncludeAnnotationConfig(false);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(9, beanCount);
|
||||
assertEquals(6, beanCount);
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -86,6 +97,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean("myNamedDao"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
|
||||
|
@ -95,6 +107,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
scanner.scan(BASE_PACKAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
|
@ -111,14 +124,15 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setIncludeAnnotationConfig(false);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(8, beanCount);
|
||||
assertEquals(9, context.getBeanDefinitionCount());
|
||||
assertEquals(5, beanCount);
|
||||
assertEquals(6, context.getBeanDefinitionCount());
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -126,6 +140,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean("myNamedDao"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
|
||||
|
@ -134,8 +149,8 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setIncludeAnnotationConfig(false);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(8, beanCount);
|
||||
assertEquals(9, context.getBeanDefinitionCount());
|
||||
assertEquals(5, beanCount);
|
||||
assertEquals(6, context.getBeanDefinitionCount());
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -143,6 +158,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean("myNamedDao"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
|
@ -152,6 +168,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
scanner.scan(BASE_PACKAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
|
@ -168,6 +185,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||
|
@ -180,6 +198,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||
|
@ -197,12 +216,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomIncludeFilterAndDefaults() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(14, beanCount);
|
||||
assertEquals(11, beanCount);
|
||||
assertTrue(context.containsBean("messageBean"));
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
|
@ -214,12 +234,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAnnotationExcludeFilterAndDefaults() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(12, beanCount);
|
||||
assertEquals(9, beanCount);
|
||||
assertFalse(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -230,12 +251,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAssignableTypeExcludeFilterAndDefaults() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(12, beanCount);
|
||||
assertEquals(9, beanCount);
|
||||
assertFalse(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -246,13 +268,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||
scanner.setIncludeAnnotationConfig(false);
|
||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(8, beanCount);
|
||||
assertEquals(5, beanCount);
|
||||
assertFalse(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -263,13 +286,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertFalse(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleCustomExcludeFiltersAndDefaults() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(11, beanCount);
|
||||
assertEquals(8, beanCount);
|
||||
assertFalse(context.containsBean("fooServiceImpl"));
|
||||
assertFalse(context.containsBean("serviceInvocationCounter"));
|
||||
assertTrue(context.containsBean("stubFooDao"));
|
||||
|
@ -280,12 +304,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomBeanNameGenerator() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, beanCount);
|
||||
assertEquals(10, beanCount);
|
||||
assertFalse(context.containsBean("fooServiceImpl"));
|
||||
assertTrue(context.containsBean("fooService"));
|
||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||
|
@ -297,35 +322,37 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleBasePackagesWithDefaultsOnly() {
|
||||
GenericApplicationContext singlePackageContext = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
|
||||
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
|
||||
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, singlePackageBeanCount);
|
||||
int multiPackageBeanCount = multiPackageScanner.scan(
|
||||
BASE_PACKAGE, "org.springframework.dao.annotation");
|
||||
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
||||
assertEquals(10, singlePackageBeanCount);
|
||||
multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
|
||||
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleScanCalls() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, beanCount);
|
||||
assertEquals(10, beanCount);
|
||||
assertEquals(beanCount, context.getBeanDefinitionCount());
|
||||
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
|
||||
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanAutowiredWithAnnotationConfigEnabled() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(13, beanCount);
|
||||
assertEquals(10, beanCount);
|
||||
context.refresh();
|
||||
|
||||
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
|
||||
|
@ -347,13 +374,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertSame(context, fooService.genericContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
scanner.setIncludeAnnotationConfig(false);
|
||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||
assertEquals(9, beanCount);
|
||||
assertEquals(6, beanCount);
|
||||
context.refresh();
|
||||
FooService fooService = (FooService) context.getBean("fooService");
|
||||
assertFalse(fooService.isInitCalled());
|
||||
|
@ -365,6 +393,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireCandidatePatternMatches() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
|
@ -377,6 +406,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
|||
assertEquals("bar", fooService.foo(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowireCandidatePatternDoesNotMatch() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||
|
|
|
@ -23,6 +23,9 @@ import org.springframework.beans.FatalBeanException;
|
|||
import org.springframework.beans.factory.config.SimpleMapScope;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import example.scannable.FooService;
|
||||
import example.scannable.ScopedProxyTestBean;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.springframework.core.type.classreading.MetadataReader;
|
|||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
|
||||
import example.scannable.AutowiredQualifierFooService;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.context.annotation;
|
|||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
import example.scannable.FooService;
|
||||
import example.scannable.ServiceInvocationCounter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.context.annotation;
|
|||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
import example.scannable.FooService;
|
||||
import example.scannable.ServiceInvocationCounter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation" use-default-filters="false" annotation-config="false">
|
||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.Stub*"/>
|
||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
|
||||
<context:exclude-filter type="aspectj" expression="org.springframework..Scoped*Test*" />
|
||||
<context:component-scan base-package="example.scannable" use-default-filters="false" annotation-config="false">
|
||||
<context:include-filter type="aspectj" expression="example.scannable.Stub*"/>
|
||||
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
|
||||
<context:exclude-filter type="aspectj" expression="example..Scoped*Test*" />
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<bean id="fooService" class="org.springframework.context.annotation.AutowiredQualifierFooService"/>
|
||||
<bean id="fooService" class="example.scannable.AutowiredQualifierFooService"/>
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"/>
|
||||
<context:component-scan base-package="example.scannable"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
<context:component-scan base-package="example.scannable"
|
||||
name-generator="org.springframework.context.annotation.TestBeanNameGenerator"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
<context:component-scan base-package="example.scannable"
|
||||
scope-resolver="org.springframework.context.annotation.TestScopeMetadataResolver"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"/>
|
||||
<context:component-scan base-package="example.scannable"/>
|
||||
|
||||
<!-- shouldn't cause a conflict -->
|
||||
<context:component-scan base-package="org.springframework.context.annotation"/>
|
||||
<context:component-scan base-package="example.scannable"/>
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework."
|
||||
resource-pattern="**/annotation/*.class"
|
||||
<context:component-scan base-package="example."
|
||||
resource-pattern="**/scannable/*.class"
|
||||
use-default-filters="false"
|
||||
annotation-config="false">
|
||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
|
||||
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
resource-pattern="**/thispackagedoesnotexist/*.class"
|
||||
use-default-filters="false"
|
||||
annotation-config="false">
|
||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
|
||||
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
use-default-filters="false">
|
||||
<context:include-filter type="assignable"
|
||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
||||
<context:component-scan base-package="example.scannable" use-default-filters="false">
|
||||
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
use-default-filters="false" scoped-proxy="interfaces">
|
||||
<context:include-filter type="assignable"
|
||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
||||
<context:component-scan base-package="example.scannable" use-default-filters="false" scoped-proxy="interfaces">
|
||||
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
<context:component-scan base-package="example.scannable"
|
||||
use-default-filters="false" scoped-proxy="no">
|
||||
<context:include-filter type="assignable"
|
||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
||||
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"
|
||||
use-default-filters="false" scoped-proxy="targetClass">
|
||||
<context:include-filter type="assignable"
|
||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
||||
<context:component-scan base-package="example.scannable" use-default-filters="false" scoped-proxy="targetClass">
|
||||
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean class="org.springframework.context.annotation.FooServiceImpl"/>
|
||||
<bean class="example.scannable.FooServiceImpl"/>
|
||||
|
||||
<bean class="org.springframework.context.annotation.ServiceInvocationCounter"/>
|
||||
<bean class="example.scannable.ServiceInvocationCounter"/>
|
||||
|
||||
<bean class="org.springframework.context.annotation.StubFooDao"/>
|
||||
<bean class="example.scannable.StubFooDao"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.context.annotation"/>
|
||||
<context:component-scan base-package="example.scannable"/>
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ package org.springframework.context.annotation3;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.context.annotation.FooDao;
|
||||
|
||||
import example.scannable.FooDao;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
|
Loading…
Reference in New Issue