reworked ConfigurationClass(Web)ApplicationContext into AnnotationConfig(Web)ApplicationContext; revised BeansException signatures

This commit is contained in:
Juergen Hoeller
2009-10-23 17:46:16 +00:00
parent 87b2f23692
commit 8a09c8e7da
16 changed files with 344 additions and 512 deletions

View File

@@ -16,25 +16,20 @@
package org.springframework.web.context.support;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Chris Beams
*/
public class ConfigurationClassWebApplicationContextTests {
@Test
public void testSingleWellFormedConfigLocation() {
ConfigurationClassWebApplicationContext ctx = new ConfigurationClassWebApplicationContext();
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setConfigLocation(Config.class.getName());
ctx.refresh();
@@ -42,45 +37,6 @@ public class ConfigurationClassWebApplicationContextTests {
assertNotNull(bean);
}
@Test
public void testWithoutExplicitlySettingConfigLocations() {
ConfigurationClassWebApplicationContext ctx = new ConfigurationClassWebApplicationContext();
try {
ctx.refresh();
fail("expected exception");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), containsString(
"Is the 'contextConfigLocations' context-param " +
"and/or init-param set properly in web.xml?"));
}
}
@Test
public void testMalformedConfigLocation() {
ConfigurationClassWebApplicationContext ctx = new ConfigurationClassWebApplicationContext();
ctx.setConfigLocation("garbage");
try {
ctx.refresh();
fail("expected exception");
} catch (ApplicationContextException ex) {
assertThat(ex.getCause(), is(IOException.class));
assertThat(ex.getCause().getMessage(),
containsString("Could not load @Configuration class"));
}
}
@Test
public void testNonConfigurationClass() {
ConfigurationClassWebApplicationContext ctx = new ConfigurationClassWebApplicationContext();
ctx.setConfigLocation(NotConfigurationAnnotated.class.getName());
try {
ctx.refresh();
fail("expected exception");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(),
containsString("is not annotated with @Configuration"));
}
}
@Configuration
static class Config {
@@ -92,7 +48,6 @@ public class ConfigurationClassWebApplicationContextTests {
static class NotConfigurationAnnotated { }
static class TestBean {
static class TestBean { }
}
}