Tidy up some tests

pull/138/head
Dave Syer 11 years ago
parent 9db55a3b71
commit d39fc5bb92

@ -412,8 +412,6 @@ public class SpringApplicationTests {
return false; return false;
} }
// FIXME test initializers
public static class SpyApplicationContext extends AnnotationConfigApplicationContext { public static class SpyApplicationContext extends AnnotationConfigApplicationContext {
ConfigurableApplicationContext applicationContext = spy(new AnnotationConfigApplicationContext()); ConfigurableApplicationContext applicationContext = spy(new AnnotationConfigApplicationContext());

@ -27,6 +27,8 @@ import java.util.Date;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
@ -39,6 +41,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
@ -263,7 +266,19 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
response.close(); 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 { protected String getResponse(String url) throws IOException, URISyntaxException {
ClientHttpResponse response = getClientResponse(url); ClientHttpResponse response = getClientResponse(url);
@ -289,4 +304,16 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
private ServletContextInitializer exampleServletRegistration() { private ServletContextInitializer exampleServletRegistration() {
return new ServletRegistrationBean(new ExampleServlet(), "/hello"); 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;
}
} }

Loading…
Cancel
Save