Search in sources :

Example 1 with StringWebResponse

use of com.gargoylesoftware.htmlunit.StringWebResponse 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 2 with StringWebResponse

use of com.gargoylesoftware.htmlunit.StringWebResponse 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

StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)2 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)2 JvmAttributeGaugeSet (com.codahale.metrics.JvmAttributeGaugeSet)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.Test)1