use of org.springframework.test.web.servlet.MockMvc in project cucumber-jvm by cucumber.
the class SpringInjectionStepDefs method I_call_the_url.
@When("^I call the url \"([^\"]*)\"$")
public void I_call_the_url(String url) throws Throwable {
MockMvc mock = MockMvcBuilders.webAppContextSetup(wac).build();
callUrl = mock.perform(get(url));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class SharedHttpSessionTests method noHttpSession.
@Test
public void noHttpSession() throws Exception {
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new TestController()).apply(sharedHttpSession()).build();
String url = "/no-session";
MvcResult result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
HttpSession session = result.getRequest().getSession(false);
assertNull(session);
result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
session = result.getRequest().getSession(false);
assertNull(session);
url = "/session";
result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
session = result.getRequest().getSession(false);
assertNotNull(session);
assertEquals(1, session.getAttribute("counter"));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class SharedHttpSessionTests method httpSession.
@Test
public void httpSession() throws Exception {
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new TestController()).apply(sharedHttpSession()).build();
String url = "/session";
MvcResult result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
HttpSession session = result.getRequest().getSession(false);
assertNotNull(session);
assertEquals(1, session.getAttribute("counter"));
result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
session = result.getRequest().getSession(false);
assertNotNull(session);
assertEquals(2, session.getAttribute("counter"));
result = mockMvc.perform(get(url)).andExpect(status().isOk()).andReturn();
session = result.getRequest().getSession(false);
assertNotNull(session);
assertEquals(3, session.getAttribute("counter"));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class DefaultMockMvcBuilderTests method dispatcherServletCustomizerProcessedInOrder.
@Test
public void dispatcherServletCustomizerProcessedInOrder() {
StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext);
DefaultMockMvcBuilder builder = webAppContextSetup(root);
builder.addDispatcherServletCustomizer(ds -> ds.setContextId("test-id"));
builder.addDispatcherServletCustomizer(ds -> ds.setContextId("override-id"));
builder.dispatchOptions(true);
MockMvc mvc = builder.build();
DispatcherServlet ds = (DispatcherServlet) new DirectFieldAccessor(mvc).getPropertyValue("servlet");
assertEquals("override-id", ds.getContextId());
}
use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.
the class MockMvcConnectionBuilderSupportTests method mockMvc.
@Test
public void mockMvc() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
WebConnection conn = new MockMvcWebConnectionBuilderSupport(mockMvc) {
}.createConnection(this.client);
assertMockMvcUsed(conn, "http://localhost/");
assertMockMvcNotUsed(conn, "http://example.com/");
}
Aggregations