Skip to content

Commit 0b45daf

Browse files
committed
Assess claims made in SPR-9799
This commit validates the claims made in SPR-9799. - Spr9799XmlConfigTests demonstrates that a WAC is not always necessary when integration testing with XML configuration that uses <mvc:annotation-driven />. - Spr9799AnnotationConfigTests demonstrates that a WAC is in fact necessary when integration testing with a configuration class that uses @EnableWebMvc. Issue: SPR-9799
1 parent 4cdf46f commit 0b45daf

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2002-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test.context.junit4.spr9799;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.test.context.ContextConfiguration;
24+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25+
import org.springframework.test.context.web.WebAppConfiguration;
26+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
27+
28+
/**
29+
* Integration tests used to assess claims raised in
30+
* <a href="https://jira.springsource.org/browse/SPR-9799" target="_blank">SPR-9799</a>.
31+
*
32+
* <p>Note: this test class would normally reside in the {@code spring-test} source
33+
* tree; however, due to classpath issues with slf4j, this class must reside in
34+
* the {@code spring-test-mvc} source tree.
35+
*
36+
* @author Sam Brannen
37+
* @since 3.2
38+
* @see Spr9799XmlConfigTests
39+
*/
40+
@RunWith(SpringJUnit4ClassRunner.class)
41+
@ContextConfiguration
42+
// NOTE: if we omit the @WebAppConfiguration declaration, the ApplicationContext will fail
43+
// to load since @EnableWebMvc requires that the context be a WebApplicationContext.
44+
@WebAppConfiguration
45+
public class Spr9799AnnotationConfigTests {
46+
47+
@Configuration
48+
@EnableWebMvc
49+
static class Config {
50+
/* intentionally no beans defined */
51+
}
52+
53+
54+
@Test
55+
public void applicationContextLoads() {
56+
// no-op
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2002-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test.context.junit4.spr9799;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.springframework.test.context.ContextConfiguration;
22+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
23+
24+
/**
25+
* Integration tests used to assess claims raised in
26+
* <a href="https://jira.springsource.org/browse/SPR-9799" target="_blank">SPR-9799</a>.
27+
*
28+
* <p>Note: this test class would normally reside in the {@code spring-test} source
29+
* tree; however, due to classpath issues with slf4j, this class must reside in
30+
* the {@code spring-test-mvc} source tree.
31+
*
32+
* @author Sam Brannen
33+
* @since 3.2
34+
* @see Spr9799AnnotationConfigTests
35+
*/
36+
@RunWith(SpringJUnit4ClassRunner.class)
37+
@ContextConfiguration
38+
public class Spr9799XmlConfigTests {
39+
40+
@Test
41+
public void applicationContextLoads() {
42+
// nothing to assert: we just want to make sure that the context loads without
43+
// errors.
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:mvc="http://www.springframework.org/schema/mvc"
4+
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
5+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
6+
7+
<mvc:annotation-driven />
8+
<mvc:default-servlet-handler />
9+
10+
</beans>

0 commit comments

Comments
 (0)