Browse Source

Test for base package specified as config location

Issue: SPR-11647
pull/528/merge
Juergen Hoeller 12 years ago
parent
commit
8e6e6c22af
  1. 29
      spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java

29
spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.web.context.support; package org.springframework.web.context.support;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AnnotationBeanNameGenerator; import org.springframework.context.annotation.AnnotationBeanNameGenerator;
@ -24,18 +25,17 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller
*/ */
public class AnnotationConfigWebApplicationContextTests { public class AnnotationConfigWebApplicationContextTests {
@Test @Test
public void registerSingleClass() { public void registerSingleClass() {
AnnotationConfigWebApplicationContext ctx = AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
new AnnotationConfigWebApplicationContext();
ctx.register(Config.class); ctx.register(Config.class);
ctx.refresh(); ctx.refresh();
@ -45,8 +45,7 @@ public class AnnotationConfigWebApplicationContextTests {
@Test @Test
public void configLocationWithSingleClass() { public void configLocationWithSingleClass() {
AnnotationConfigWebApplicationContext ctx = AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
new AnnotationConfigWebApplicationContext();
ctx.setConfigLocation(Config.class.getName()); ctx.setConfigLocation(Config.class.getName());
ctx.refresh(); ctx.refresh();
@ -54,10 +53,19 @@ public class AnnotationConfigWebApplicationContextTests {
assertNotNull(bean); assertNotNull(bean);
} }
@Test
public void configLocationWithBasePackage() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setConfigLocation("org.springframework.web.context.support");
ctx.refresh();
TestBean bean = ctx.getBean(TestBean.class);
assertNotNull(bean);
}
@Test @Test
public void withBeanNameGenerator() { public void withBeanNameGenerator() {
AnnotationConfigWebApplicationContext ctx = AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
new AnnotationConfigWebApplicationContext();
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() { ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
@Override @Override
public String generateBeanName(BeanDefinition definition, public String generateBeanName(BeanDefinition definition,
@ -73,14 +81,15 @@ public class AnnotationConfigWebApplicationContextTests {
@Configuration("myConfig") @Configuration("myConfig")
static class Config { static class Config {
@Bean @Bean
public TestBean myTestBean() { public TestBean myTestBean() {
return new TestBean(); return new TestBean();
} }
} }
static class NotConfigurationAnnotated { }
static class TestBean { } static class TestBean {
}
} }

Loading…
Cancel
Save