Search in sources :

Example 96 with WebClient

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

the class SimpleAsyncListenerTest method testOnErrorCalledSuccesfully.

@Test
// enable when WELD-1774 is fixed
@Ignore
public void testOnErrorCalledSuccesfully() throws Exception {
    WebClient webClient = new WebClient();
    webClient.setThrowExceptionOnFailingStatusCode(false);
    webClient.getPage(getPath(AsyncServlet.TEST_ERROR));
    Page results = webClient.getPage(contextPath + "Status");
    assertTrue(results.getWebResponse().getContentAsString(), results.getWebResponse().getContentAsString().contains("onError: true"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 97 with WebClient

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

the class SimpleAsyncListenerTest method testOnStartAsyncCalledSuccesfully.

@Test
public void testOnStartAsyncCalledSuccesfully() throws Exception {
    WebClient webClient = new WebClient();
    webClient.getPage(getPath(AsyncServlet.TEST_LOOP));
    Page results = webClient.getPage(contextPath + "Status");
    assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true"));
    assertTrue(results.getWebResponse().getContentAsString().contains("onStartAsync: true"));
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 98 with WebClient

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

the class ListenerSymmetryTest method testListenerCalledSymmetrically.

@Test
public void testListenerCalledSymmetrically() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
    WebClient webClient = new WebClient();
    assertEquals("Async OK", webClient.getPage(contextPath + "async").getWebResponse().getContentAsString().trim());
    assertEquals("OK", webClient.getPage(contextPath + "result").getWebResponse().getContentAsString().trim());
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 99 with WebClient

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

the class BootstrapNotNeededTest method testBootstrapNotNeeded.

@Test
public void testBootstrapNotNeeded() throws Exception {
    String id = UUID.randomUUID().toString();
    // First boostrap Weld SE
    try (WeldContainer container = new Weld(id).initialize()) {
        TestBean testBean = container.instance().select(TestBean.class).get();
        assertNotNull(testBean);
        // @Initialized(ApplicationScoped.class) ContainerInitialized
        List<Object> initEvents = testBean.getInitEvents();
        assertEquals(1, initEvents.size());
        Object event = initEvents.get(0);
        assertTrue(event instanceof ContainerInitialized);
        assertEquals(id, ((ContainerInitialized) event).getContainerId());
        // Test CDIProvider
        CDI<Object> cdi = CDI.current();
        assertTrue(cdi instanceof WeldContainer);
        // Then start Jetty
        Server server = new Server(InetSocketAddress.createUnresolved("localhost", 8080));
        try {
            ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
            context.setContextPath("/");
            server.setHandler(context);
            context.addServlet(TestServlet.class, "/test");
            context.setAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME, container.getBeanManager());
            context.addEventListener(new Listener());
            server.start();
            // @Initialized(ApplicationScoped.class) ServletContext not fired
            assertEquals(1, initEvents.size());
            WebClient webClient = new WebClient();
            webClient.setThrowExceptionOnFailingStatusCode(true);
            Page page = webClient.getPage("http://localhost:8080/test");
            assertEquals(testBean.getId(), page.getWebResponse().getContentAsString().trim());
        } finally {
            server.stop();
        }
    }
}
Also used : Listener(org.jboss.weld.environment.servlet.Listener) Server(org.eclipse.jetty.server.Server) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Page(com.gargoylesoftware.htmlunit.Page) ContainerInitialized(org.jboss.weld.environment.se.events.ContainerInitialized) WebClient(com.gargoylesoftware.htmlunit.WebClient) Weld(org.jboss.weld.environment.se.Weld) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Example 100 with WebClient

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

the class CrossContextForwardTest method testCrossContextForward.

@Test
public void testCrossContextForward(@ArquillianResource @OperateOnDeployment(FIRST) URL firstContext) throws IOException {
    Page page = new WebClient().getPage(firstContext + "forwarding");
    assertEquals(200, page.getWebResponse().getStatusCode());
    assertEquals("<h1>Hello World</h1>", page.getWebResponse().getContentAsString());
}
Also used : Page(com.gargoylesoftware.htmlunit.Page) 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