Search in sources :

Example 51 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method mergeHeader.

@Test
public void mergeHeader() throws Exception {
    String headerName = "PARENT";
    String headerValue = "VALUE";
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/").header(headerName, headerValue)).build();
    assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getHeader(headerName), equalTo(headerValue));
}
Also used : MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 52 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method mergeCookie.

@Test
public void mergeCookie() throws Exception {
    String cookieName = "PARENT";
    String cookieValue = "VALUE";
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/").cookie(new Cookie(cookieName, cookieValue))).build();
    Cookie[] cookies = mockMvc.perform(requestBuilder).andReturn().getRequest().getCookies();
    assertThat(cookies, notNullValue());
    assertThat(cookies.length, equalTo(1));
    Cookie cookie = cookies[0];
    assertThat(cookie.getName(), equalTo(cookieName));
    assertThat(cookie.getValue(), equalTo(cookieValue));
}
Also used : Cookie(javax.servlet.http.Cookie) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 53 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method mergeSessionNotInitialized.

@Test
public void mergeSessionNotInitialized() throws Exception {
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/")).build();
    assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession(false), nullValue());
}
Also used : MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 54 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method verifyExampleInClassLevelJavadoc.

@Test
public void verifyExampleInClassLevelJavadoc() throws Exception {
    Assume.group(TestGroup.PERFORMANCE);
    WebClient webClient = new WebClient();
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(TestController.class).build();
    MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient);
    WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
    WebConnection httpConnection = new HttpWebConnection(webClient);
    WebConnection webConnection = new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection));
    webClient.setWebConnection(webConnection);
    Page page = webClient.getPage("http://code.jquery.com/jquery-1.11.0.min.js");
    assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
    assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString()));
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 55 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-framework by spring-projects.

the class HtmlUnitRequestBuilderTests method mergeParameter.

@Test
public void mergeParameter() throws Exception {
    String paramName = "PARENT";
    String paramValue = "VALUE";
    String paramValue2 = "VALUE2";
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).defaultRequest(get("/").param(paramName, paramValue, paramValue2)).build();
    MockHttpServletRequest performedRequest = mockMvc.perform(requestBuilder).andReturn().getRequest();
    assertThat(asList(performedRequest.getParameterValues(paramName)), contains(paramValue, paramValue2));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

MockMvc (org.springframework.test.web.servlet.MockMvc)97 Test (org.junit.Test)91 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)25 Todo (org.springframework.sync.Todo)16 List (java.util.List)15 TodoRepository (org.springframework.sync.TodoRepository)15 Filter (javax.servlet.Filter)13 MockServletContext (org.springframework.mock.web.MockServletContext)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)9 MvcResult (org.springframework.test.web.servlet.MvcResult)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 Ignore (org.junit.Ignore)3 FilterChainProxy (org.springframework.security.web.FilterChainProxy)3 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 HttpSession (javax.servlet.http.HttpSession)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2