Search in sources :

Example 1 with WebConnection

use of com.gargoylesoftware.htmlunit.WebConnection in project spring-boot by spring-projects.

the class LocalHostWebClientTests method getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080.

@Test
public void getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    WebClient client = new LocalHostWebClient(environment);
    WebConnection connection = mockConnection();
    client.setWebConnection(connection);
    client.getPage("/test");
    verify(connection).getResponse(this.requestCaptor.capture());
    assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8080/test"));
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) MockEnvironment(org.springframework.mock.env.MockEnvironment) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 2 with WebConnection

use of com.gargoylesoftware.htmlunit.WebConnection in project spring-framework by spring-projects.

the class MockMvcConnectionBuilderSupportTests method context.

@Test
public void context() throws Exception {
    WebConnection conn = this.builder.createConnection(this.client);
    assertMockMvcUsed(conn, "http://localhost/");
    assertMockMvcNotUsed(conn, "http://example.com/");
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) Test(org.junit.Test)

Example 3 with WebConnection

use of com.gargoylesoftware.htmlunit.WebConnection in project spring-boot by spring-projects.

the class LocalHostWebClientTests method mockConnection.

private WebConnection mockConnection() throws MalformedURLException, IOException {
    WebConnection connection = mock(WebConnection.class);
    WebResponse response = new StringWebResponse("test", new URL("http://localhost"));
    given(connection.getResponse((WebRequest) any())).willReturn(response);
    return connection;
}
Also used : StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) WebConnection(com.gargoylesoftware.htmlunit.WebConnection) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) URL(java.net.URL)

Example 4 with WebConnection

use of com.gargoylesoftware.htmlunit.WebConnection in project spring-boot by spring-projects.

the class LocalHostWebClientTests method getPageWhenUrlIsRelativeAndHasPortWillUseLocalhostPort.

@Test
public void getPageWhenUrlIsRelativeAndHasPortWillUseLocalhostPort() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("local.server.port", "8181");
    WebClient client = new LocalHostWebClient(environment);
    WebConnection connection = mockConnection();
    client.setWebConnection(connection);
    client.getPage("/test");
    verify(connection).getResponse(this.requestCaptor.capture());
    assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8181/test"));
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) MockEnvironment(org.springframework.mock.env.MockEnvironment) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 5 with WebConnection

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

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