use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.
the class FreeMarkerAutoConfigurationTests method customTemplateLoaderPath.
@Test
public void customTemplateLoaderPath() throws Exception {
registerAndRefreshContext("spring.freemarker.templateLoaderPath:classpath:/custom-templates/");
MockHttpServletResponse response = render("custom");
String result = response.getContentAsString();
assertThat(result).contains("custom");
}
use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.
the class ThymeleafAutoConfigurationTests method createLayoutFromConfigClass.
@Test
public void createLayoutFromConfigClass() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
MockServletContext servletContext = new MockServletContext();
context.setServletContext(servletContext);
context.refresh();
ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class).resolveViewName("view", Locale.UK);
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
view.render(Collections.singletonMap("foo", "bar"), request, response);
String result = response.getContentAsString();
assertThat(result).contains("<title>Content</title>");
assertThat(result).contains("<span>bar</span>");
context.close();
}
use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.
the class LogFileMvcEndpointTests method notAvailableIfDisabled.
@Test
public void notAvailableIfDisabled() throws Exception {
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
this.mvc.setEnabled(false);
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
}
use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.
the class LogFileMvcEndpointTests method availableWithLogFile.
@Test
public void availableWithLogFile() throws Exception {
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.HEAD.name(), "/logfile");
this.mvc.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
}
use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.
the class LogFileMvcEndpointTests method invokeGetsContentExternalFile.
@Test
public void invokeGetsContentExternalFile() throws Exception {
this.mvc.setExternalFile(this.logFile);
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/logfile");
this.mvc.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat("--TEST--").isEqualTo(response.getContentAsString());
}
Aggregations