use of cn.taketoday.test.web.servlet.ExampleServlet in project today-infrastructure by TAKETODAY.
the class UndertowServletWebServerFactoryTests method testAccessLog.
private void testAccessLog(String prefix, String suffix, String expectedFile) throws IOException, URISyntaxException {
UndertowServletWebServerFactory factory = getFactory();
factory.setAccessLogEnabled(true);
factory.setAccessLogPrefix(prefix);
factory.setAccessLogSuffix(suffix);
File accessLogDirectory = this.tempDir;
factory.setAccessLogDirectory(accessLogDirectory);
assertThat(accessLogDirectory.listFiles()).isEmpty();
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
this.webServer.start();
Assertions.assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
File accessLog = new File(accessLogDirectory, expectedFile);
awaitFile(accessLog);
assertThat(accessLogDirectory.listFiles()).contains(accessLog);
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class UndertowServletWebServerFactoryTests method errorPage404.
@Test
void errorPage404() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/hello"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
this.webServer.start();
Assertions.assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
Assertions.assertThat(getResponse(getLocalUrl("/not-found"))).isEqualTo("Hello World");
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class UndertowServletWebServerFactoryTests method testAccessLog.
private void testAccessLog(String prefix, String suffix, String expectedFile) throws IOException, URISyntaxException {
UndertowServletWebServerFactory factory = getFactory();
factory.setAccessLogEnabled(true);
factory.setAccessLogPrefix(prefix);
factory.setAccessLogSuffix(suffix);
File accessLogDirectory = this.tempDir;
factory.setAccessLogDirectory(accessLogDirectory);
assertThat(accessLogDirectory.listFiles()).isEmpty();
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(), "/hello"));
this.webServer.start();
Assertions.assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
File accessLog = new File(accessLogDirectory, expectedFile);
awaitFile(accessLog);
assertThat(accessLogDirectory.listFiles()).contains(accessLog);
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.
@Test
void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sslWithInvalidAliasFailsDuringStartup.
@Test
void sslWithInvalidAliasFailsDuringStartup() {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = getSsl(null, "password", "test-alias-404", "src/test/resources/test.jks");
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello");
ThrowingCallable call = () -> factory.getWebServer(registration).start();
assertThatSslWithInvalidAliasCallFails(call);
}
Aggregations