Search in sources :

Example 61 with WebClient

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"));
}
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.jupiter.api.Test)

Example 62 with WebClient

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");
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.jupiter.api.Test)

Example 63 with WebClient

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");
}
Also used : Cookie(com.gargoylesoftware.htmlunit.util.Cookie) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.jupiter.api.Test)

Example 64 with WebClient

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");
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.jupiter.api.Test)

Example 65 with WebClient

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());
    }
}
Also used : FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) DefaultCredentialsProvider(com.gargoylesoftware.htmlunit.DefaultCredentialsProvider) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)182 Test (org.junit.Test)110 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)55 Page (com.gargoylesoftware.htmlunit.Page)33 TextPage (com.gargoylesoftware.htmlunit.TextPage)21 Before (org.junit.Before)20 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)17 URL (java.net.URL)14 JsonObject (javax.json.JsonObject)13 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)13 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)12 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)11 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)10 ReadContext (com.jayway.jsonpath.ReadContext)10 File (java.io.File)9 IOException (java.io.IOException)8 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)7 Test (org.junit.jupiter.api.Test)7 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)6 DefaultCredentialsProvider (com.gargoylesoftware.htmlunit.DefaultCredentialsProvider)5