Renamed tests for AnnotationConfig[Web]ApplicationContext; added tests for scan() and register() methods.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2604 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
1c5590cbab
commit
5900cd6daa
|
|
@ -22,23 +22,39 @@ import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.matchers.JUnitMatchers.*;
|
import static org.junit.matchers.JUnitMatchers.*;
|
||||||
|
import static org.springframework.util.StringUtils.uncapitalize;
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation6.ComponentForScanning;
|
||||||
|
import org.springframework.context.annotation6.ConfigForScanning;
|
||||||
|
import org.springframework.context.annotation6.Jsr330NamedForScanning;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ConfigurationClassApplicationContextTests {
|
public class AnnotationConfigApplicationContextTests {
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void nullGetBeanParameterIsDisallowed() {
|
public void nullGetBeanParameterIsDisallowed() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||||
context.getBean((Class<?>)null);
|
context.getBean((Class<?>)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanAndRefresh() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
context.scan("org.springframework.context.annotation6");
|
||||||
|
context.refresh();
|
||||||
|
context.getBean(uncapitalize(ConfigForScanning.class.getSimpleName()));
|
||||||
|
context.getBean("testBean"); // contributed by ConfigForScanning
|
||||||
|
context.getBean(uncapitalize(ComponentForScanning.class.getSimpleName()));
|
||||||
|
context.getBean(uncapitalize(Jsr330NamedForScanning.class.getSimpleName()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addConfigurationClass() {
|
public void registerAndRefresh() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.register(Config.class, NameConfig.class);
|
context.register(Config.class, NameConfig.class);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
@ -63,7 +79,7 @@ public class ConfigurationClassApplicationContextTests {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||||
|
|
||||||
// attempt to retrieve the instance by its generated bean name
|
// attempt to retrieve the instance by its generated bean name
|
||||||
Config configObject = (Config) context.getBean("configurationClassApplicationContextTests.Config");
|
Config configObject = (Config) context.getBean("annotationConfigApplicationContextTests.Config");
|
||||||
assertNotNull(configObject);
|
assertNotNull(configObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.springframework.context.annotation6;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ComponentForScanning {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.springframework.context.annotation6;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import test.beans.TestBean;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ConfigForScanning {
|
||||||
|
@Bean
|
||||||
|
public TestBean testBean() {
|
||||||
|
return new TestBean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.springframework.context.annotation6;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
@Named
|
||||||
|
public class Jsr330NamedForScanning {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
/**
|
/**
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ConfigurationClassWebApplicationContextTests {
|
public class AnnotationConfigWebApplicationContextTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleWellFormedConfigLocation() {
|
public void testSingleWellFormedConfigLocation() {
|
||||||
Loading…
Reference in New Issue