Search in sources :

Example 61 with MockServletContext

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

the class DispatcherServletAutoConfigurationTests method registrationNonServletBean.

@Test
public void registrationNonServletBean() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.register(NonServletConfiguration.class, DispatcherServletAutoConfiguration.class);
    this.context.setServletContext(new MockServletContext());
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(ServletRegistrationBean.class).length).isEqualTo(0);
    assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length).isEqualTo(0);
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 62 with MockServletContext

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

the class MvcEndpointCorsIntegrationTests method createContext.

@Before
public void createContext() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, AuditAutoConfiguration.class, JolokiaAutoConfiguration.class, WebMvcAutoConfiguration.class);
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 63 with MockServletContext

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

the class MvcEndpointSecurityInterceptorTests method setup.

@Before
public void setup() throws Exception {
    this.roles = Arrays.asList("SUPER_HERO");
    this.securityInterceptor = new MvcEndpointSecurityInterceptor(true, this.roles);
    this.endpoint = new TestEndpoint("a");
    this.mvcEndpoint = new TestMvcEndpoint(this.endpoint);
    this.handlerMethod = new HandlerMethod(this.mvcEndpoint, "invoke");
    this.servletContext = new MockServletContext();
    this.request = new MockHttpServletRequest(this.servletContext);
    this.response = mock(HttpServletResponse.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerMethod(org.springframework.web.method.HandlerMethod) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 64 with MockServletContext

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

the class NoSpringSecurityHealthMvcEndpointIntegrationTests method healthWhenRightRoleNotPresentShouldNotExposeHealthDetails.

@Test
public void healthWhenRightRoleNotPresentShouldNotExposeHealthDetails() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(TestConfiguration.class);
    this.context.refresh();
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(get("/health").with(getRequestPostProcessor())).andExpect(status().isOk()).andExpect(content().string("{\"status\":\"UP\"}"));
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 65 with MockServletContext

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

the class NoSpringSecurityMvcEndpointSecurityInterceptorTests method setup.

@Before
public void setup() throws Exception {
    this.roles = Arrays.asList("SUPER_HERO");
    this.securityInterceptor = new MvcEndpointSecurityInterceptor(true, this.roles);
    this.endpoint = new TestEndpoint("a");
    this.mvcEndpoint = new TestMvcEndpoint(this.endpoint);
    this.handlerMethod = new HandlerMethod(this.mvcEndpoint, "invoke");
    this.servletContext = new MockServletContext();
    this.request = new MockHttpServletRequest(this.servletContext);
    this.response = mock(HttpServletResponse.class);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerMethod(org.springframework.web.method.HandlerMethod) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Aggregations

MockServletContext (org.springframework.mock.web.MockServletContext)186 Test (org.junit.Test)135 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)82 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)80 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)74 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)54 MockRequestContext (org.springframework.webflow.test.MockRequestContext)46 Event (org.springframework.webflow.execution.Event)18 Before (org.junit.Before)16 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 MockMvc (org.springframework.test.web.servlet.MockMvc)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 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 Cookie (javax.servlet.http.Cookie)6 FilterChainProxy (org.springframework.security.web.FilterChainProxy)6