Search in sources :

Example 46 with Page

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

the class ServletConversationTest method testLongRunningConversation.

@Test
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(500, page.getWebResponse().getStatusCode());
    }
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 47 with Page

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

the class ServletConversationTest method testInvalidatingSessionDestroysConversation.

@Test
public void testInvalidatingSessionDestroysConversation() throws Exception {
    WebClient client = new WebClient();
    // begin conversation 1
    TextPage initialPage1 = client.getPage(getPath("/begin", null));
    String content = initialPage1.getContent();
    assertTrue(content.contains("message: Hello"));
    assertTrue(content.contains("transient: false"));
    String cid1 = getCid(content);
    // begin conversation 1
    TextPage initialPage2 = client.getPage(getPath("/begin", null));
    String content2 = initialPage2.getContent();
    assertTrue(content2.contains("message: Hello"));
    assertTrue(content2.contains("transient: false"));
    String cid2 = getCid(content2);
    assertFalse(cid1.equals(cid2));
    /*
         * Invalidate the session. This should destroy the currently associated conversation (with cid1) as well as the
         * not-currently-associated conversation (with cid2).
         */
    {
        client.getPage(getPath("/invalidateSession", cid1));
    }
    // verify destroyed conversations
    {
        TextPage page = client.getPage(getPath("/listDestroyedMessages", null));
        assertTrue(page.getContent().contains("DestroyedMessages:"));
        assertTrue(page.getContent().contains("<M:" + cid1 + ">"));
        assertTrue(page.getContent().contains("<M:" + cid2 + ">"));
    }
    {
        TextPage page = client.getPage(getPath("/listConversationsDestroyedWhileBeingAssociated", null));
        assertTrue(page.getContent().contains("ConversationsDestroyedWhileBeingAssociated:"));
        assertTrue(page.getContent().contains("<" + cid1 + ">"));
    }
    {
        TextPage page = client.getPage(getPath("/listConversationsDestroyedWhileBeingDisassociated", null));
        assertTrue(page.getContent().contains("ConversationsDestroyedWhileBeingDisassociated:"));
        assertTrue(page.getContent().contains("<" + cid2 + ">"));
    }
    // Verify that the conversation 1 cannot be associated
    {
        client.setThrowExceptionOnFailingStatusCode(false);
        Page page = client.getPage(getPath("/display", cid1));
        assertEquals(500, page.getWebResponse().getStatusCode());
    }
    // Verify that the conversation 2 cannot be associated
    {
        client.setThrowExceptionOnFailingStatusCode(false);
        Page page = client.getPage(getPath("/display", cid2));
        assertEquals(500, page.getWebResponse().getStatusCode());
    }
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 48 with Page

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

the class EagerHttpSessionTest method testHttpSession.

@Test
public void testHttpSession() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(true);
    Page page = client.getPage(url + "/test");
    String id = page.getWebResponse().getContentAsString();
    assertFalse(id.isEmpty());
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 49 with Page

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

the class EnterpriseBeanLifecycleRemoteTest method testDestroyRemovesSFSB.

@Test
public void testDestroyRemovesSFSB() throws Exception {
    WebClient client = new WebClient();
    Page page = client.getPage(getPath("request1"));
    assertEquals(page.getWebResponse().getStatusCode(), HttpServletResponse.SC_OK);
    page = client.getPage(getPath("request2"));
    assertEquals(page.getWebResponse().getStatusCode(), HttpServletResponse.SC_OK);
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 50 with Page

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

the class JspTest method testConversationPropagationToNonExistentConversationLeadsException.

@Test
public void testConversationPropagationToNonExistentConversationLeadsException() throws Exception {
    WebClient client = new WebClient();
    client.setThrowExceptionOnFailingStatusCode(false);
    Page page = client.getPage(getPath("/index.jsp"));
    Assert.assertEquals(200, page.getWebResponse().getStatusCode());
    Assert.assertTrue(page.getUrl().toString().contains("home.jsf"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Aggregations

Page (com.gargoylesoftware.htmlunit.Page)62 Test (org.junit.Test)39 WebClient (com.gargoylesoftware.htmlunit.WebClient)33 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)15 PublicAtsApi (com.axway.ats.common.PublicAtsApi)9 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)5 File (java.io.File)5 IOException (java.io.IOException)5 URL (java.net.URL)5 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)5 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)4 ConfirmHandler (com.gargoylesoftware.htmlunit.ConfirmHandler)4 Map (java.util.Map)4 JSONObject (net.sf.json.JSONObject)4 RsaJsonWebKey (org.jose4j.jwk.RsaJsonWebKey)4 JsonWebSignature (org.jose4j.jws.JsonWebSignature)4 JwtClaims (org.jose4j.jwt.JwtClaims)4 JwtConsumer (org.jose4j.jwt.consumer.JwtConsumer)4 JwtConsumerBuilder (org.jose4j.jwt.consumer.JwtConsumerBuilder)4 JsonWebStructure (org.jose4j.jwx.JsonWebStructure)4