use of com.gargoylesoftware.htmlunit.WebClient in project spring-boot by spring-projects.
the class LocalHostWebClientTests method getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080.
@Test
void getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080() throws Exception {
MockEnvironment environment = new MockEnvironment();
WebClient client = new LocalHostWebClient(environment);
WebConnection connection = mockConnection();
client.setWebConnection(connection);
client.getPage("/test");
then(connection).should().getResponse(this.requestCaptor.capture());
assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8080/test"));
}
use of com.gargoylesoftware.htmlunit.WebClient in project spring-framework by spring-projects.
the class MockMvcWebClientBuilderTests method mockMvcSetupWithDefaultWebClientDelegate.
@Test
void mockMvcSetupWithDefaultWebClientDelegate() throws Exception {
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
assertMockMvcUsed(client, "http://localhost/test");
}
use of com.gargoylesoftware.htmlunit.WebClient in project spring-framework by spring-projects.
the class MockMvcWebClientBuilderTests method cookieManagerShared.
// SPR-14066
@Test
void cookieManagerShared() throws Exception {
this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build();
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
client.getCookieManager().addCookie(new Cookie("localhost", "cookie", "cookieManagerShared"));
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("cookieManagerShared");
}
use of com.gargoylesoftware.htmlunit.WebClient in project spring-framework by spring-projects.
the class MockMvcWebClientBuilderTests method cookiesAreManaged.
// SPR-14265
@Test
void cookiesAreManaged() throws Exception {
this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build();
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
assertThat(postResponse(client, "http://localhost/?cookie=foo").getContentAsString()).isEqualTo("Set");
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("foo");
assertThat(deleteResponse(client, "http://localhost/").getContentAsString()).isEqualTo("Delete");
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
}
use of com.gargoylesoftware.htmlunit.WebClient in project tomee by apache.
the class MovieTest method getWrongPermission.
@Test
public void getWrongPermission() throws Exception {
System.out.println("\n\nCalling MovieServlet with a valid user but without required permissions.");
try (final WebClient webClient = new WebClient()) {
// set proxy username and password
final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
credentialsProvider.addCredentials("iron", "man");
webClient.getPage(serverURI.toString() + "/movies");
} catch (final FailingHttpStatusCodeException e) {
Assert.assertEquals(403, e.getStatusCode());
}
}
Aggregations