use of org.springframework.mock.web.MockServletContext in project spring-framework by spring-projects.
the class MockMultipartHttpServletRequestBuilderTests method test.
@Test
public void test() {
MockHttpServletRequestBuilder parent = new MockHttpServletRequestBuilder(HttpMethod.GET, "/");
parent.characterEncoding("UTF-8");
Object result = new MockMultipartHttpServletRequestBuilder("/fileUpload").merge(parent);
assertNotNull(result);
assertEquals(MockMultipartHttpServletRequestBuilder.class, result.getClass());
MockMultipartHttpServletRequestBuilder builder = (MockMultipartHttpServletRequestBuilder) result;
MockHttpServletRequest request = builder.buildRequest(new MockServletContext());
assertEquals("UTF-8", request.getCharacterEncoding());
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class ConditionalOnNotWebApplicationTests method testNotWebApplicationWithServletContext.
@Test
public void testNotWebApplicationWithServletContext() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(NotWebApplicationConfiguration.class);
ctx.setServletContext(new MockServletContext());
ctx.refresh();
this.context = ctx;
assertThat(this.context.getBeansOfType(String.class)).isEmpty();
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class SpringDataWebAutoConfigurationTests method webSupportIsAutoConfiguredInWebApplicationContexts.
@Test
public void webSupportIsAutoConfiguredInWebApplicationContexts() {
this.context = new AnnotationConfigWebApplicationContext();
((AnnotationConfigWebApplicationContext) this.context).register(SpringDataWebAutoConfiguration.class);
this.context.refresh();
((AnnotationConfigWebApplicationContext) this.context).setServletContext(new MockServletContext());
Map<String, PageableHandlerMethodArgumentResolver> beans = this.context.getBeansOfType(PageableHandlerMethodArgumentResolver.class);
assertThat(beans).hasSize(1);
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class HypermediaAutoConfigurationTests method linkDiscoverersCreated.
@Test
public void linkDiscoverersCreated() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
this.context.refresh();
LinkDiscoverers discoverers = this.context.getBean(LinkDiscoverers.class);
assertThat(discoverers).isNotNull();
LinkDiscoverer discoverer = discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON);
assertThat(HalLinkDiscoverer.class.isInstance(discoverer)).isTrue();
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class HypermediaAutoConfigurationTests method customizationOfSupportedMediaTypesCanBeDisabled.
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes()).containsExactly(MediaTypes.HAL_JSON);
}
}
}
Aggregations