Search in sources :

Example 26 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.

the class ManagementWebSecurityAutoConfigurationTests method testSecurityPropertiesNotAvailable.

@Test
public void testSecurityPropertiesNotAvailable() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(TestConfiguration.class, SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, EndpointAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo(this.context.getBean(TestConfiguration.class).authenticationManager);
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 27 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.

the class CloudFoundryActuatorAutoConfigurationTests method setup.

@Before
public void setup() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class, WebMvcAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, RestTemplateAutoConfiguration.class, EndpointWebMvcManagementContextConfiguration.class, CloudFoundryActuatorAutoConfiguration.class);
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 28 with MockServletContext

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();
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 29 with MockServletContext

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);
}
Also used : PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 30 with MockServletContext

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();
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) LinkDiscoverer(org.springframework.hateoas.LinkDiscoverer) HalLinkDiscoverer(org.springframework.hateoas.hal.HalLinkDiscoverer) MockServletContext(org.springframework.mock.web.MockServletContext) LinkDiscoverers(org.springframework.hateoas.LinkDiscoverers) Test(org.junit.Test)

Aggregations

MockServletContext (org.springframework.mock.web.MockServletContext)173 Test (org.junit.Test)126 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)79 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)71 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)63 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)43 MockRequestContext (org.springframework.webflow.test.MockRequestContext)38 Before (org.junit.Before)14 MockMvc (org.springframework.test.web.servlet.MockMvc)13 Event (org.springframework.webflow.execution.Event)11 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)10 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)9 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)8 MockFilterChain (org.springframework.mock.web.MockFilterChain)8 MockHttpSession (org.springframework.mock.web.MockHttpSession)8 Map (java.util.Map)7 Credential (org.apereo.cas.authentication.Credential)7 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)7 FilterChainProxy (org.springframework.security.web.FilterChainProxy)6 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)6