Skip to content

Commit 0950072

Browse files
author
Dave Syer
committed
Fix integration test (shared context by accident)
1 parent 06ffd9d commit 0950072

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTest.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@
1818

1919
import java.util.Map;
2020

21+
import javax.servlet.http.HttpServletRequest;
22+
import javax.servlet.http.HttpServletResponse;
23+
2124
import org.junit.Test;
2225
import org.junit.runner.RunWith;
2326
import org.springframework.beans.factory.annotation.Value;
27+
import org.springframework.boot.SpringApplication;
28+
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.MinimalWebConfiguration;
29+
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.TestConfiguration;
2430
import org.springframework.boot.test.IntegrationTest;
2531
import org.springframework.boot.test.SpringApplicationConfiguration;
2632
import org.springframework.boot.test.TestRestTemplate;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Configuration;
2735
import org.springframework.http.ResponseEntity;
36+
import org.springframework.test.annotation.DirtiesContext;
2837
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2938
import org.springframework.test.context.web.WebAppConfiguration;
39+
import org.springframework.validation.BindException;
40+
import org.springframework.web.bind.annotation.RequestMapping;
41+
import org.springframework.web.bind.annotation.RestController;
42+
import org.springframework.web.servlet.View;
43+
import org.springframework.web.servlet.view.AbstractView;
3044

3145
import static org.hamcrest.Matchers.containsString;
3246
import static org.hamcrest.Matchers.endsWith;
@@ -40,8 +54,9 @@
4054
* @author Dave Syer
4155
*/
4256
@RunWith(SpringJUnit4ClassRunner.class)
43-
@SpringApplicationConfiguration(classes = BasicErrorControllerMockMvcTests.TestConfiguration.class)
57+
@SpringApplicationConfiguration(classes = TestConfiguration.class)
4458
@WebAppConfiguration
59+
@DirtiesContext
4560
@IntegrationTest("server.port=0")
4661
public class BasicErrorControllerIntegrationTest {
4762

@@ -69,4 +84,49 @@ public void testBindingExceptionForMachineClient() throws Exception {
6984
assertThat(resp, containsString("errors=[{codes="));
7085
assertThat(resp, containsString("org.springframework.validation.BindException"));
7186
}
87+
88+
@Configuration
89+
@MinimalWebConfiguration
90+
public static class TestConfiguration {
91+
92+
// For manual testing
93+
public static void main(String[] args) {
94+
SpringApplication.run(TestConfiguration.class, args);
95+
}
96+
97+
@Bean
98+
public View error() {
99+
return new AbstractView() {
100+
@Override
101+
protected void renderMergedOutputModel(Map<String, Object> model,
102+
HttpServletRequest request, HttpServletResponse response)
103+
throws Exception {
104+
response.getWriter().write("ERROR_BEAN");
105+
}
106+
};
107+
}
108+
109+
@RestController
110+
protected static class Errors {
111+
112+
public String getFoo() {
113+
return "foo";
114+
}
115+
116+
@RequestMapping("/")
117+
public String home() {
118+
throw new IllegalStateException("Expected!");
119+
}
120+
121+
@RequestMapping("/bind")
122+
public String bind() throws Exception {
123+
BindException error = new BindException(this, "test");
124+
error.rejectValue("foo", "bar.error");
125+
throw error;
126+
}
127+
128+
}
129+
130+
}
131+
72132
}

0 commit comments

Comments
 (0)