Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebClient$BinaryWebResponse


    }

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertion(section = REQUEST_CONTEXT, id = "ad")
    public void testRequestContextActiveOnStartAsync() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage page = webClient.getPage(getPath(AsyncServlet.TEST_LOOP));
        assertFalse(page.getContent().contains("onStartAsync: null"));
        assertFalse(page.getContent().contains("onComplete: null"));
    }
View Full Code Here


    }

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertion(section = APPLICATION_CONTEXT, id = "ae")
    public void testApplicationContextActiveOnComplete() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage page = webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE));
        assertTrue(page.getContent().contains("onTimeout: null"));
        assertTrue(page.getContent().contains("onError: null"));
        assertFalse(page.getContent().contains("onComplete: null"));
    }
View Full Code Here

    }

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertion(section = APPLICATION_CONTEXT, id = "ae")
    public void testApplicationContextActiveOnTimeout() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(false);
        TextPage page = webClient.getPage(getPath(AsyncServlet.TEST_TIMEOUT));
        assertTrue(page.getContent().contains("onTimeout:"));
        assertFalse(page.getContent().contains("onTimeout: null"));
    }
View Full Code Here

    }

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertion(section = APPLICATION_CONTEXT, id = "ae")
    public void testApplicationContextActiveOnError() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(false);
        TextPage page = webClient.getPage(getPath(AsyncServlet.TEST_ERROR));
        assertTrue(page.getContent().contains("onError:"));
        assertFalse(page.getContent().contains("onError: null"));
    }
View Full Code Here

    }

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertion(section = APPLICATION_CONTEXT, id = "ae")
    public void testApplicationContextActiveOnStartAsync() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage page = webClient.getPage(getPath(AsyncServlet.TEST_LOOP));
        assertFalse(page.getContent().contains("onStartAsync: null"));
        assertFalse(page.getContent().contains("onComplete: null"));
    }
View Full Code Here

    @Test(groups = {INTEGRATION, ASYNC_SERVLET})
    @SpecAssertions({ @SpecAssertion(section = CONVERSATION_CONTEXT, id = "da"), @SpecAssertion(section = CONVERSATION_CONTEXT, id = "db"),
            @SpecAssertion(section = CONVERSATION_CONTEXT, id = "dc"), @SpecAssertion(section = CONVERSATION_CONTEXT, id = "dd") })
    public void testConversationDetermination() throws Exception {

        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);

        // Begin long-running conversation
        TextPage cidPage = webClient.getPage(contextPath + "foo?action=begin");
        String cid = cidPage.getContent().substring(cidPage.getContent().indexOf("cid: [") + 6,
                cidPage.getContent().indexOf("]"));
        assertTrue(cidPage.getContent().contains("transient: false"));

        // Test built-in conversation bean is available
        TextPage resultPage = webClient.getPage(contextPath + "foo?action=test&cid=" + cid.trim());
        assertTrue(resultPage.getContent().contains("testServlet=true"));
        assertTrue(resultPage.getContent().contains("testFilter=true"));
        assertTrue(resultPage.getContent().contains("testListener=true"));

        // Async listener
        resultPage = webClient.getPage(contextPath + "foo-async?action=test&cid=" + cid.trim());
        assertTrue(resultPage.getContent().contains("testAsyncListener=true"));
    }
View Full Code Here

    @Test(groups = { INTEGRATION })
    @SpecAssertions({ @SpecAssertion(section = REQUEST_CONTEXT, id = "jd") })
    public void testEventsFired() throws Exception {

        WebClient client = new WebClient();

        TextPage page = client.getPage(contextPath + "info");
        String content = page.getContent();

        checkContent(content, "(Initialized:)(\\w+)", "true");
        // Timeout request only
        checkContent(content, "(Destroyed:)(\\w+)", "true");
View Full Code Here

  }

  @SecondsLong(43)
  @TestType(Type.INTEGRATION)
  public void testKeepalive() throws Exception {
    WebClient c = new WebClient();
    String requestId = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    c.closeAllWindows();
    if (c.getPage(TEST_URL_PREFIX + "/keepalive/?requestId=" + requestId).getWebResponse().getContentAsString().startsWith("SUCCESS") == false) {
      throw new Exception("Initial keepalive should be successfull");
    }
    Thread.sleep(43000);
    if (c.getPage(TEST_URL_PREFIX + "/keepalive/?requestId=" + requestId).getWebResponse().getContentAsString().startsWith("FAILURE") == false) {
      throw new Exception("Timeouted keepalive should have failed");
    }
    c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId);
  }
View Full Code Here

  }

  @SecondsLong(4)
  @TestType(Type.ACCEPTANCE)
  public void testPushing() throws Exception {
    WebClient c = new WebClient();
    WebWindow w = new TopLevelWindow("1", c);
    c.setCurrentWindow(w);
    HtmlPage p = c.getPage(TEST_URL);
    Thread.sleep(4000);
    int current = Integer.parseInt(p.getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 3 || current > 5) {
      throw new Exception("The value is not in the expected interval:[3,5]. The current value:" + current);
    }
    c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + p.getElementById("requestId").getAttribute("value"));
  }
View Full Code Here

  }

  @SecondsLong(12)
  @TestType(Type.ACCEPTANCE)
  public void testConnectionSharing() throws Exception {
    WebClient c = new WebClient();
    WebWindow w1 = new TopLevelWindow("1", c);
    WebWindow w2 = new TopLevelWindow("2", c);
    c.setCurrentWindow(w1);
    String requestId1 = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    Thread.sleep(1000);
    c.setCurrentWindow(w2);
    String requestId2 = ((HtmlPage) c.getPage(TEST_URL)).getElementById("requestId").getAttribute("value");
    Thread.sleep(500);
    enableDebug(w1);
    enableDebug(w2);
    Thread.sleep(10000);
    System.out.println(getLogForWindows(w1,w2));
    int current = Integer.parseInt(((HtmlPage) w1.getEnclosedPage()).getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 9 || current > 12) {
      throw new Exception("The value is not in the expected interval:[9,12] for Window 1. The current value:" + current);
    }
    current = Integer.parseInt(((HtmlPage) w2.getEnclosedPage()).getElementById("content").getFirstChild().getFirstChild().getTextContent().trim());
    if (current < 9 || current > 12) {
      throw new Exception("The value is not in the expected interval:[9,12] for Window 2. The current value:" + current);
    }
    if (getLogForWindows(w2).contains("pushnotifications") || getLogForWindows(w1).contains("pushnotifications") == false) {
      throw new Exception("Window 2 is making permanent requests or Window 1 don't");
    }
    c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId1);
    c.getPage(TEST_URL_PREFIX + "/leaving/?requestId=" + requestId2);
  }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebClient$BinaryWebResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.