Search in sources :

Example 36 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class InvalidateConversationTest method testConversationDestroyedAfterRequestEnds.

@Test
public void testConversationDestroyedAfterRequestEnds() throws IOException {
    WebClient client = new WebClient();
    // reset ActionSequence on server
    client.getPage(url + "resetSequence");
    // trigger conversation
    TextPage page = client.getPage(url + "begin");
    String cid = page.getContent().trim();
    // trigger session invalidation
    page = client.getPage(url + "invalidate?cid=" + cid);
    // invoke third request to get complete result of ActionSequence from server
    page = client.getPage(url + "result");
    String result = page.getContent();
    // prepare expected result
    ActionSequence.reset();
    ActionSequence.addAction("conversationCreated");
    ActionSequence.addAction("beforeInvalidate");
    ActionSequence.addAction("afterInvalidate");
    ActionSequence.addAction("conversationDestroyed");
    assertEquals(ActionSequence.getSequence().dataToCsv(), result);
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 37 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class InvalidateConversationTest method testAllLongRunningConversationsGetDestroyedAfterRequest.

@Test
public void testAllLongRunningConversationsGetDestroyedAfterRequest() throws IOException {
    String firstCid;
    String secondCid;
    WebClient client = new WebClient();
    // reset ActionSequence on server
    client.getPage(url + "resetSequence");
    // initiate conversations
    TextPage page = client.getPage(url + "begin");
    firstCid = page.getContent().trim();
    page = client.getPage(url + "begin");
    secondCid = page.getContent().trim();
    assertFalse(firstCid.equals(secondCid));
    // trigger session invalidation with one cid
    page = client.getPage(url + "invalidate?cid=" + secondCid);
    // invoke third request to get complete result of ActionSequence from server
    page = client.getPage(url + "result");
    String result = page.getContent();
    // prepare expected result
    ActionSequence.reset();
    ActionSequence.addAction("conversationCreated");
    ActionSequence.addAction("conversationCreated");
    ActionSequence.addAction("beforeInvalidate");
    ActionSequence.addAction("afterInvalidate");
    ActionSequence.addAction("conversationDestroyed");
    ActionSequence.addAction("conversationDestroyed");
    assertEquals(ActionSequence.getSequence().dataToCsv(), result);
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 38 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class ServletConversationTest method testPost.

@Test
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"));
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 39 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class Weld1262Test method startConversation.

public HtmlPage startConversation() throws Exception {
    WebClient client = new WebClient();
    HtmlPage main = client.getPage(url.toString().concat("crossroad.jsf"));
    main = getFirstMatchingElement(main, HtmlSubmitInput.class, "begin").click();
    String cid = getFirstMatchingElement(main, HtmlSpan.class, "cid").getTextContent();
    assertTrue(Integer.valueOf(cid) > 0);
    return main;
}
Also used : HtmlSpan(com.gargoylesoftware.htmlunit.html.HtmlSpan) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Example 40 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project core by weld.

the class RequestScopeEventTest method test.

@Test
public void test() throws Exception {
    WebClient client = new WebClient();
    TextPage page1 = client.getPage(url + "?foo=bar");
    // the current request
    assertTrue(page1.getContent().contains("Initialized requests:1"));
    // not destroyed yet
    assertTrue(page1.getContent().contains("Destroyed requests:0"));
    TextPage page2 = client.getPage(url + "?foo=bar");
    assertTrue(page2.getContent().contains("Initialized requests:2"));
    assertTrue(page2.getContent().contains("Destroyed requests:1"));
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)182 Test (org.junit.Test)110 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)55 Page (com.gargoylesoftware.htmlunit.Page)33 TextPage (com.gargoylesoftware.htmlunit.TextPage)21 Before (org.junit.Before)20 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)17 URL (java.net.URL)14 JsonObject (javax.json.JsonObject)13 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)13 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)12 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)11 HtmlSpan (com.gargoylesoftware.htmlunit.html.HtmlSpan)10 ReadContext (com.jayway.jsonpath.ReadContext)10 File (java.io.File)9 IOException (java.io.IOException)8 NicelyResynchronizingAjaxController (com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController)7 Test (org.junit.jupiter.api.Test)7 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)6 DefaultCredentialsProvider (com.gargoylesoftware.htmlunit.DefaultCredentialsProvider)5