Search in sources :

Example 21 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse 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 22 with WebResponse

use of com.gargoylesoftware.htmlunit.WebResponse in project sling by apache.

the class MetricWebConsolePluginTest method webConsolePlugin.

@Test
public void webConsolePlugin() throws Exception {
    MetricRegistry reg1 = new MetricRegistry();
    reg1.meter("test1").mark(5);
    reg1.timer("test2").time().close();
    reg1.histogram("test3").update(743);
    reg1.counter("test4").inc(9);
    reg1.registerAll(new JvmAttributeGaugeSet());
    context.registerService(MetricRegistry.class, reg1, regProps("foo"));
    activatePlugin();
    StringWriter sw = new StringWriter();
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(response.getWriter()).thenReturn(new PrintWriter(sw));
    plugin.doGet(mock(HttpServletRequest.class), response);
    WebClient client = new WebClient();
    WebResponse resp = new StringWebResponse(sw.toString(), WebClient.URL_ABOUT_BLANK);
    HtmlPage page = HTMLParser.parseHtml(resp, client.getCurrentWindow());
    assertTable("data-meters", page);
    assertTable("data-counters", page);
    assertTable("data-timers", page);
    assertTable("data-histograms", page);
    assertTable("data-gauges", page);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JvmAttributeGaugeSet(com.codahale.metrics.JvmAttributeGaugeSet) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) StringWriter(java.io.StringWriter) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebClient(com.gargoylesoftware.htmlunit.WebClient) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

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