Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.TextPage


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


    @Test
    @SpecAssertions({ @SpecAssertion(section = "6.7.1", id = "ja") })
    public void test() throws Exception {
        WebClient client = new WebClient();

        TextPage page1 = client.getPage(contextPath + "?foo=bar");
        assertTrue(page1.getContent().contains("Initialized requests:1")); // the current request
        assertTrue(page1.getContent().contains("Destroyed requests:0")); // not destroyed yet

        TextPage page2 = client.getPage(contextPath + "?foo=bar");
        assertTrue(page2.getContent().contains("Initialized requests:2"));
        assertTrue(page2.getContent().contains("Destroyed requests:1"));
    }
View Full Code Here

    public void testRequestContextActiveOnComplete() throws Exception {

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

        TextPage page01 = webClient.getPage(getPage(AsyncServlet.TEST_COMPLETE));
        assertTrue(page01.getContent().contains("onTimeout: null"));
        assertTrue(page01.getContent().contains("onError: null"));
        assertFalse(page01.getContent().contains("onComplete: null"));

        // Indirectly test request context is destroyed after onComplete()
        TextPage page02 = webClient.getPage(getPage(AsyncServlet.TEST_COMPLETE));
        assertNotEquals(extractSimpleRequestBeanIdString(page01.getContent()),
                extractSimpleRequestBeanIdString(page02.getContent()));
    }
View Full Code Here

    @Test
    @SpecAssertion(section = "6.7.1", id = "ad")
    public void testRequestContextActiveOnTimeout() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage page = webClient.getPage(getPage(AsyncServlet.TEST_TIMEOUT));
        assertFalse(page.getContent().contains("onTimeout: null"));
    }
View Full Code Here

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

    @SpecAssertions({ @SpecAssertion(section = "6.7.2", id = "da"), @SpecAssertion(section = "6.7.2", id = "db"),
            @SpecAssertion(section = "6.7.2", id = "cd") })
    public void test() throws Exception {
        WebClient client = new WebClient();

        TextPage page = client.getPage(contextPath);
        assertTrue(page.getContent().contains("Initialized sessions:1")); // the current session
        assertTrue(page.getContent().contains("Destroyed sessions:0")); // not destroyed yet

        // nothing should change
        page = client.getPage(contextPath);
        assertTrue(page.getContent().contains("Initialized sessions:1"));
        assertTrue(page.getContent().contains("Destroyed sessions:0"));

        // invalidate the session
        page = client.getPage(contextPath + "/invalidate");
        assertTrue(page.getContent().contains("Initialized sessions:1"));
        // the context is destroyed after the response is sent
        // verify in the next request
        assertTrue(page.getContent().contains("Destroyed sessions:0"));

        page = client.getPage(contextPath);
        // new session context was initialized
        assertTrue(page.getContent().contains("Initialized sessions:2"));
        // the previous one was destroyed
        assertTrue(page.getContent().contains("Destroyed sessions:1"));
    }
View Full Code Here

    @Test
    @SpecAssertions({ @SpecAssertion(section = "6.7.4", id = "aa") })
    public void testTransientConversation() throws Exception {
        WebClient client = new WebClient();
        TextPage page = client.getPage(getPath("/display", null));
        assertTrue(page.getContent().contains("message: Hello"));
        assertTrue(page.getContent().contains("cid: [null]"));
        assertTrue(page.getContent().contains("transient: true"));
    }
View Full Code Here

    @SpecAssertions({ @SpecAssertion(section = "6.7.4", id = "aa") })
    public void testLongRunningConversation() throws Exception {
        WebClient client = new WebClient();

        // begin conversation
        TextPage initialPage = client.getPage(getPath("/begin", null));
        String content = initialPage.getContent();
        assertTrue(content.contains("message: Hello"));
        assertTrue(content.contains("transient: false"));

        String cid = getCid(content);

        // verify conversation is not transient
        {
            TextPage page = client.getPage(getPath("/display", cid));
            assertTrue(page.getContent().contains("message: Hello"));
            assertTrue(page.getContent().contains("cid: [" + cid + "]"));
            assertTrue(page.getContent().contains("transient: false"));
        }

        // modify conversation state
        {
            TextPage page = client.getPage(getPath("/set", cid) + "&message=Hi");
            assertTrue(page.getContent().contains("message: Hi"));
            assertTrue(page.getContent().contains("cid: [" + cid + "]"));
            assertTrue(page.getContent().contains("transient: false"));
        }

        // verify conversation state
        {
            TextPage page = client.getPage(getPath("/display", cid));
            assertTrue(page.getContent().contains("message: Hi"));
            assertTrue(page.getContent().contains("cid: [" + cid + "]"));
            assertTrue(page.getContent().contains("transient: false"));
        }

        // end conversation
        {
            TextPage page = client.getPage(getPath("/end", cid));
            assertTrue(page.getContent().contains("message: Hi"));
            assertTrue(page.getContent().contains("transient: true"));
        }

        // verify that the conversation can no longer be restored
        {
            client.setThrowExceptionOnFailingStatusCode(false);
            Page page = client.getPage(getPath("/display", cid));
            assertEquals(page.getWebResponse().getStatusCode(), 500);
        }
    }
View Full Code Here

    @SpecAssertions({ @SpecAssertion(section = "6.7.4", id = "aa") })
    public void testPost() throws Exception {
        WebClient client = new WebClient();

        // begin conversation
        TextPage initialPage = client.getPage(getPath("/begin", null));
        String content = initialPage.getContent();
        assertTrue(content.contains("message: Hello"));
        assertTrue(content.contains("transient: false"));

        String cid = getCid(content);

        // submit a form
        {
            HtmlPage form = client.getPage(url.toString() + "/message.html");
            getFirstMatchingElement(form, HtmlTextInput.class, "message").setValueAttribute("Hola!");
            getFirstMatchingElement(form, HtmlTextInput.class, "cid").setValueAttribute(cid);
            TextPage page = getFirstMatchingElement(form, HtmlSubmitInput.class, "submit").click();

            assertTrue(page.getContent().contains("message: Hola!"));
            assertTrue(page.getContent().contains("cid: [" + cid + "]"));
            assertTrue(page.getContent().contains("transient: false"));
        }

        // verify conversation state
        {
            TextPage page = client.getPage(getPath("/display", cid));
            assertTrue(page.getContent().contains("message: Hola!"));
            assertTrue(page.getContent().contains("cid: [" + cid + "]"));
            assertTrue(page.getContent().contains("transient: false"));
        }
    }
View Full Code Here

    // TODO this test doesn't verify that the long-running conversation is destroyed but that it cannot be associated
    public void testInvalidatingSessionDestroysConversation() throws Exception {
        WebClient client = new WebClient();

        // begin conversation
        TextPage initialPage = client.getPage(getPath("/begin", null));
        String content = initialPage.getContent();
        assertTrue(content.contains("message: Hello"));
        assertTrue(content.contains("transient: false"));

        String cid = getCid(content);
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.TextPage

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.