Search in sources :

Example 11 with WebConnection

use of com.gargoylesoftware.htmlunit.WebConnection 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)

Aggregations

WebConnection (com.gargoylesoftware.htmlunit.WebConnection)11 Test (org.junit.Test)9 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 URL (java.net.URL)3 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 DelegateWebConnection (org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection)2 HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)1 Page (com.gargoylesoftware.htmlunit.Page)1 StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 ArrayList (java.util.ArrayList)1