Search in sources :

Example 16 with WebResponse

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

the class MockWebResponseBuilderTests method buildContent.

// --- build
@Test
public void buildContent() throws Exception {
    this.response.getWriter().write("expected content");
    WebResponse webResponse = this.responseBuilder.build();
    assertThat(webResponse.getContentAsString(), equalTo("expected content"));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) Test(org.junit.Test)

Example 17 with WebResponse

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

the class MockWebResponseBuilderTests method buildContentCharset.

@Test
public void buildContentCharset() throws Exception {
    this.response.addHeader("Content-Type", "text/html; charset=UTF-8");
    WebResponse webResponse = this.responseBuilder.build();
    assertThat(webResponse.getContentCharset(), equalTo(StandardCharsets.UTF_8));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) Test(org.junit.Test)

Example 18 with WebResponse

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

the class DelegatingWebConnectionTests method getResponseDefault.

@Test
public void getResponseDefault() throws Exception {
    when(defaultConnection.getResponse(request)).thenReturn(expectedResponse);
    WebResponse response = webConnection.getResponse(request);
    assertThat(response, sameInstance(expectedResponse));
    verify(matcher1).matches(request);
    verify(matcher2).matches(request);
    verifyNoMoreInteractions(connection1, connection2);
    verify(defaultConnection).getResponse(request);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) Test(org.junit.Test)

Example 19 with WebResponse

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

the class DelegatingWebConnectionTests method getResponseAllMatches.

@Test
public void getResponseAllMatches() throws Exception {
    when(matcher1.matches(request)).thenReturn(true);
    when(connection1.getResponse(request)).thenReturn(expectedResponse);
    WebResponse response = webConnection.getResponse(request);
    assertThat(response, sameInstance(expectedResponse));
    verify(matcher1).matches(request);
    verifyNoMoreInteractions(matcher2, connection2, defaultConnection);
    verify(connection1).getResponse(request);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) Test(org.junit.Test)

Example 20 with WebResponse

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

the class DelegatingWebConnectionTests method setup.

@Before
public void setup() throws Exception {
    request = new WebRequest(new URL("http://localhost/"));
    WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.<NameValuePair>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) Before(org.junit.Before)

Aggregations

WebResponse (com.gargoylesoftware.htmlunit.WebResponse)22 Test (org.junit.Test)14 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)5 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)4 URL (java.net.URL)4 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 WebResponseData (com.gargoylesoftware.htmlunit.WebResponseData)3 StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)2 Cookie (javax.servlet.http.Cookie)2 JvmAttributeGaugeSet (com.codahale.metrics.JvmAttributeGaugeSet)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpWebConnection (com.gargoylesoftware.htmlunit.HttpWebConnection)1 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)1 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1