Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.TextPage


    @Test
    public void testSeamSecurityWithCorrectUser() throws Exception {

        WebClient client = new WebClient();

        TextPage beforeLogin = client.getPage(url + "features");
        assertTrue(beforeLogin.getContent().contains("DISABLED = false"));
        assertTrue(beforeLogin.getContent().contains("ENABLED_FOR_ALL = true"));
        assertTrue(beforeLogin.getContent().contains("ENABLED_FOR_CK = false"));

        TextPage loginPage = client.getPage(url + "login?user=ck");
        assertTrue(loginPage.getContent().contains("SUCCESS"));

        TextPage afterLogin = client.getPage(url + "features");
        assertTrue(afterLogin.getContent().contains("DISABLED = false"));
        assertTrue(afterLogin.getContent().contains("ENABLED_FOR_ALL = true"));
        assertTrue(afterLogin.getContent().contains("ENABLED_FOR_CK = true"));

        TextPage logoutPage = client.getPage(url + "logout");
        assertTrue(logoutPage.getContent().contains("SUCCESS"));

        TextPage afterLogout = client.getPage(url + "features");
        assertTrue(afterLogout.getContent().contains("DISABLED = false"));
        assertTrue(afterLogout.getContent().contains("ENABLED_FOR_ALL = true"));
        assertTrue(afterLogout.getContent().contains("ENABLED_FOR_CK = false"));

    }
View Full Code Here


        assertElementPresent(page, CONTAINER_BACKGROUND_THREAD);
    }

    @Test
    public void checkDetail() throws IOException {
        final TextPage page = page("threads/" + CONTAINER_BACKGROUND_THREAD);
        assertThat(page.getWebResponse().getContentAsString(), containsString("org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run"));
    }
View Full Code Here

        assertThat(page.getWebResponse().getContentAsString(), containsString("id=\"" + CPU_GAUGE_ENCODED + "-graph\""));
    }

    @Test
    public void checkJsonDetail() throws IOException {
        final TextPage page = page("gauges/" + CPU_GAUGE_ENCODED + "/0/" + (System.currentTimeMillis() + 1000));
        final String json = page.getWebResponse().getContentAsString();
        assertThat(json, containsString("[{\"label\":\"CPU\",\"color\":"));
        assertThat(json, containsString("\"data\":"));
    }
View Full Code Here

        final HtmlPage page = page("jmx");
        assertElementPresent(page, classLoadingMBeanId);

        // we could click on the link but it would mandates to activate js in the WebClient (see parent)
        // this is not as easy as setting the boolean because of dev environment (proxy, etc...)
        final TextPage detail = page("jmx/" + classLoadingMBeanId);
        final String detailAsStr = detail.getWebResponse().getContentAsString();
        assertThat(detailAsStr, containsString("LoadedClassCount"));
        assertThat(detailAsStr, containsString("sun.management.ClassLoadingImpl"));
    }
View Full Code Here

        Repository.INSTANCE.clearCounters();
    }

    @Test
    public void monitorRequest() throws IOException {
        final TextPage page = newClient().getPage(base.toExternalForm() + "hit");
        assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());

        final Counter hitCounter = Repository.INSTANCE.getCounter(new Counter.Key(Role.WEB, "/sirona-test/hit"));
        assertEquals(1, hitCounter.getHits());
    }
View Full Code Here

    @Test
    public void knownStatusIsMonitored() throws IOException, InterruptedException {
        final Role role = new Role("/sirona-test-HTTP-200", Unit.UNARY);
        final int before = statusGaugeSum(role);
        final TextPage page = newClient().getPage(base.toExternalForm() + "hit");
        assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
        Thread.sleep(1000);
        assertEquals("" + Repository.INSTANCE.getGaugeValues(0, System.currentTimeMillis() + 1000, role), 1, statusGaugeSum(role) - before);
    }
View Full Code Here

        assertEquals("" + Repository.INSTANCE.getGaugeValues(0, System.currentTimeMillis() + 1000, role), 1, statusGaugeSum(role) - before);
    }

    @Test
    public void unknownStatusIsIgnored() throws IOException, InterruptedException {
        final TextPage page = newClient().getPage(base.toExternalForm() + "hit?status=4567");
        assertEquals(4567, page.getWebResponse().getStatusCode());
        Thread.sleep(1000);
        assertEquals(0, statusGaugeSum(new Role("/sirona-test-HTTP-4567", Unit.UNARY)));
    }
View Full Code Here

    public void testDecoratorInstanceIsDependentObject() throws Exception {

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

        TextPage resp01 = webClient.getPage(contextPath + "bank?action=deposit&amount=10");
        assertTrue(resp01.getContent().contains("ShortTermBalance:10"));
        assertTrue(resp01.getContent().contains("DurableBalance:10"));
        assertTrue(resp01.getContent().contains("PostConstructCallers:2"));
        // Note that short-term account is request scoped and thus destroyed after request - however this info is not available
        // during the request - we have to check after the next request
        assertTrue(resp01.getContent().contains("PreDestroyCallers:0"));

        TextPage resp02 = webClient.getPage(contextPath + "bank?action=deposit&amount=10");
        assertTrue(resp02.getContent().contains("ShortTermBalance:10"));
        assertTrue(resp02.getContent().contains("DurableBalance:20"));
        assertTrue(resp02.getContent().contains("PostConstructCallers:3"));
        assertTrue(resp02.getContent().contains("PreDestroyCallers:1"));

        // And finally check decorator is applied
        TextPage resp03 = webClient.getPage(contextPath + "bank?action=withdraw&amount=5");
        assertTrue(resp03.getContent().contains("ShortTermBalance:-10"));
        assertTrue(resp03.getContent().contains("DurableBalance:10"));
        assertTrue(resp03.getContent().contains("PostConstructCallers:4"));
        assertTrue(resp03.getContent().contains("PreDestroyCallers:2"));
    }
View Full Code Here

    @Test(groups = { CONTEXTS, SERVLET })
    @SpecAssertion(section = "6.7.2", id = "b")
    public void testSessionContextSharedBetweenServletRequestsInSameHttpSession() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage firstRequestResult = webClient.getPage(contextPath + "IntrospectSession");
        assert firstRequestResult.getContent() != null;
        assert Long.parseLong(firstRequestResult.getContent()) != 0;
        // Make a second request and make sure the same context is used
        TextPage secondRequestResult = webClient.getPage(contextPath + "IntrospectSession");
        assert secondRequestResult.getContent() != null;
        assert Long.parseLong(secondRequestResult.getContent()) == Long.parseLong(firstRequestResult.getContent());
    }
View Full Code Here

    @Test(groups = { CONTEXTS, SERVLET })
    @SpecAssertion(section = "6.7.2", id = "ca")
    public void testSessionContextDestroyedWhenHttpSessionInvalidated() throws Exception {
        WebClient webClient = new WebClient();
        webClient.setThrowExceptionOnFailingStatusCode(true);
        TextPage firstRequestResult = webClient.getPage(contextPath + "IntrospectSession");
        assert firstRequestResult.getContent() != null;
        assert Long.parseLong(firstRequestResult.getContent()) != 0;
        webClient.getPage(contextPath + "InvalidateSession");
        // Make a second request and make sure the same context is not there
        TextPage secondRequestResult = webClient.getPage(contextPath + "IntrospectSession");
        assert secondRequestResult.getContent() != null;
        assert Long.parseLong(secondRequestResult.getContent()) != Long.parseLong(firstRequestResult.getContent());

        // As final confirmation that the context was destroyed, check that its beans
        // were also destroyed.
        TextPage beanDestructionResult = webClient.getPage(contextPath + "InvalidateSession?isBeanDestroyed");
        assert Boolean.parseBoolean(beanDestructionResult.getContent());
    }
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.