From d39fc5bb9298b8e7c4ef03fd5f60997abe3bd1fb Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 28 Nov 2013 17:35:48 +0000 Subject: [PATCH] Tidy up some tests --- .../boot/SpringApplicationTests.java | 2 -- ...tEmbeddedServletContainerFactoryTests.java | 29 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 99a0fd91f2..e2d8f57f8a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -412,8 +412,6 @@ public class SpringApplicationTests { return false; } - // FIXME test initializers - public static class SpyApplicationContext extends AnnotationConfigApplicationContext { ConfigurableApplicationContext applicationContext = spy(new AnnotationConfigApplicationContext()); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index 5e3c245a0d..871259b4a9 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -27,6 +27,8 @@ import java.util.Date; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; @@ -39,6 +41,7 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.InOrder; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; @@ -263,7 +266,19 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { response.close(); } - // FIXME test error page + @Test + @Ignore + // FIXME: how to test an error response (maybe java.net.HttpUrlConnection isn't going + // to cut it) + public void errorPage() throws Exception { + ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); + this.container = factory.getEmbeddedServletContainer( + exampleServletRegistration(), errorServletRegistration()); + this.container.start(); + assertThat(getResponse("http://localhost:8080/hello"), equalTo("Hello World")); + assertThat(getResponse("http://localhost:8080/bang"), equalTo("Hello World")); + } protected String getResponse(String url) throws IOException, URISyntaxException { ClientHttpResponse response = getClientResponse(url); @@ -289,4 +304,16 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { private ServletContextInitializer exampleServletRegistration() { return new ServletRegistrationBean(new ExampleServlet(), "/hello"); } + + private ServletContextInitializer errorServletRegistration() { + ServletRegistrationBean bean = new ServletRegistrationBean(new ExampleServlet() { + @Override + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + throw new RuntimeException("Planned"); + } + }, "/bang"); + bean.setName("error"); + return bean; + } }