Search in sources :

Example 1 with DelegateWebConnection

use of org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection in project spring-security by spring-projects.

the class WebTestClientHtmlUnitDriverBuilder method build.

public WebDriver build() {
    WebConnectionHtmlUnitDriver driver = new WebConnectionHtmlUnitDriver();
    WebClient webClient = driver.getWebClient();
    WebTestClientWebConnection webClientConnection = new WebTestClientWebConnection(this.webTestClient, webClient);
    WebConnection connection = new DelegatingWebConnection(driver.getWebConnection(), new DelegateWebConnection(new HostRequestMatcher("localhost"), webClientConnection));
    driver.setWebConnection(connection);
    return driver;
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) DelegatingWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) DelegatingWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) WebConnectionHtmlUnitDriver(org.springframework.test.web.servlet.htmlunit.webdriver.WebConnectionHtmlUnitDriver) WebClient(com.gargoylesoftware.htmlunit.WebClient) HostRequestMatcher(org.springframework.test.web.servlet.htmlunit.HostRequestMatcher)

Example 2 with DelegateWebConnection

use of org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection in project spring-framework by spring-projects.

the class MockMvcWebConnectionBuilderSupport method createConnection.

private WebConnection createConnection(WebClient webClient, WebConnection defaultConnection) {
    WebConnection connection = new MockMvcWebConnection(this.mockMvc, webClient, this.contextPath);
    if (this.alwaysUseMockMvc) {
        return connection;
    }
    List<DelegateWebConnection> delegates = new ArrayList<>(this.requestMatchers.size());
    for (WebRequestMatcher matcher : this.requestMatchers) {
        delegates.add(new DelegateWebConnection(matcher, connection));
    }
    return new DelegatingWebConnection(defaultConnection, delegates);
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) ArrayList(java.util.ArrayList) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection)

Example 3 with DelegateWebConnection

use of org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method verifyExampleInClassLevelJavadoc.

@Test
@EnabledForTestGroups(LONG_RUNNING)
public void verifyExampleInClassLevelJavadoc() throws Exception {
    WebClient webClient = new WebClient();
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build();
    MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient);
    WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
    WebConnection httpConnection = new HttpWebConnection(webClient);
    webClient.setWebConnection(new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection)));
    Page page = webClient.getPage("https://code.jquery.com/jquery-1.11.0.min.js");
    assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
    assertThat(page.getWebResponse().getContentAsString()).isNotEmpty();
}
Also used : HttpWebConnection(com.gargoylesoftware.htmlunit.HttpWebConnection) WebConnection(com.gargoylesoftware.htmlunit.WebConnection) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) 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.jupiter.api.Test) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 4 with DelegateWebConnection

use of org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method setup.

@BeforeEach
public void setup() throws Exception {
    request = new WebRequest(new URL("http://localhost/"));
    WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.emptyList());
    expectedResponse = new WebResponse(data, request, 100L);
    webConnection = new DelegatingWebConnection(defaultConnection, new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) WebResponseData(com.gargoylesoftware.htmlunit.WebResponseData) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) URL(java.net.URL) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DelegateWebConnection (org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection)4 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)1 Page (com.gargoylesoftware.htmlunit.Page)1 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 WebResponseData (com.gargoylesoftware.htmlunit.WebResponseData)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 EnabledForTestGroups (org.springframework.core.testfixture.EnabledForTestGroups)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 DelegatingWebConnection (org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection)1 HostRequestMatcher (org.springframework.test.web.servlet.htmlunit.HostRequestMatcher)1 WebConnectionHtmlUnitDriver (org.springframework.test.web.servlet.htmlunit.webdriver.WebConnectionHtmlUnitDriver)1