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"));
}
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/");
}
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;
}
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"));
}
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);
}
Aggregations