Search in sources :

Example 76 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.

the class RolesPermittedTest method setUp.

@BeforeClass
public static void setUp() throws InterruptedException {
    WEB_CLIENT = new WebClient();
    // prevent spurious 404 errors
    WEB_CLIENT.getOptions().setThrowExceptionOnFailingStatusCode(false);
    java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) BeforeClass(org.junit.BeforeClass)

Example 77 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.

the class CustomLoginModuleRealmTest method testAuthenticationWithCorrectUser.

@InSequence(2)
@Test
@RunAsClient
public void testAuthenticationWithCorrectUser() throws IOException {
    try (WebClient webClient = new WebClient()) {
        System.out.println("\n\nRequesting: " + base + "testServlet");
        DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
        credentialsProvider.addCredentials("realmUser", "realmPassword");
        webClient.setCredentialsProvider(credentialsProvider);
        TextPage page = webClient.getPage(base + "testServlet");
        System.out.println(page.getContent());
        assertTrue("my GET", page.getContent().contains("This is a test servlet"));
        assertTrue("User doesn't have the corrrect role", page.getContent().contains("web user has role \"realmGroup\": true"));
        webClient.getCookieManager().clearCookies();
    }
}
Also used : DefaultCredentialsProvider(com.gargoylesoftware.htmlunit.DefaultCredentialsProvider) TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) InSequence(org.jboss.arquillian.junit.InSequence) Test(org.junit.Test)

Example 78 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.

the class CompressionTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    WEB_CLIENT = new WebClient();
    WEB_CLIENT.getOptions().setThrowExceptionOnFailingStatusCode(false);
    // disable cache
    WEB_CLIENT.getCache().setMaxSize(0);
    uncompressedSize = WEB_CLIENT.getPage(URL).getWebResponse().getContentLength();
    log.log(Level.FINE, "********* uncompressedSize = {0}", uncompressedSize);
    CliCommands.payaraGlassFish("set", "configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.http2-enabled=false");
    CliCommands.payaraGlassFish("set", "configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.compression=on");
    WEB_CLIENT.addRequestHeader("Accept-Encoding", "gzip,deflate");
}
Also used : WebClient(com.gargoylesoftware.htmlunit.WebClient) BeforeClass(org.junit.BeforeClass)

Example 79 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.

the class HelloWorldControllerTest method testNamespace.

@Test
@RunAsClient
public void testNamespace() throws Exception {
    jakarta.ws.rs.Path jakartaPathAnnotation = HelloWorldController.class.getAnnotation(jakarta.ws.rs.Path.class);
    try (WebClient webClient = new WebClient()) {
        TextPage page = webClient.getPage(base + "/api/hello");
        assertTrue("Status code", page.getWebResponse().getStatusCode() == 200);
        assertNotNull("Existing Annotation", jakartaPathAnnotation);
        assertNotNull("Existing Annotation Value", jakartaPathAnnotation.value().equals("/api/hello"));
        assertTrue("Transformed Annotation", page.getContent().contains("javax.ws.rs.Path"));
    }
}
Also used : TextPage(com.gargoylesoftware.htmlunit.TextPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 80 with WebClient

use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.

the class JsonLogFormatIT method mapParameterLoggedIT.

@Test
public void mapParameterLoggedIT() throws Exception {
    ArrayList<String> command = new ArrayList<>();
    ArrayList<String> output = new ArrayList<>();
    command.add("list-log-attributes");
    CliCommands.payaraGlassFish(command, output);
    boolean foundFile = false;
    boolean foundConsole = false;
    String originalFileHandlerFormatter = "";
    String originalConsoleHandlerFormatter = "";
    for (String keyValue : output) {
        if (keyValue.startsWith("com.sun.enterprise.server.logging.GFFileHandler.formatter")) {
            originalFileHandlerFormatter = keyValue.substring(keyValue.indexOf("\t<") + 2, keyValue.length() - 1);
            foundFile = true;
            continue;
        }
        if (keyValue.startsWith("java.util.logging.ConsoleHandler.formatter")) {
            originalConsoleHandlerFormatter = keyValue.substring(keyValue.indexOf("\t<") + 2, keyValue.length() - 1);
            foundConsole = true;
            continue;
        }
        if (foundFile && foundConsole) {
            break;
        }
    }
    // Will return null if file could not be determined.
    File logFile = getLogFile();
    if (logFile == null) {
        fail("Could not determine or read log file.");
    }
    try {
        // Set log settings to JSON
        command.clear();
        output.clear();
        command.add("set-log-attributes");
        command.add("java.util.logging.ConsoleHandler.formatter='fish.payara.enterprise.server.logging.JSONLogFormatter'" + ":com.sun.enterprise.server.logging.GFFileHandler.formatter=" + "'fish.payara.enterprise.server.logging.JSONLogFormatter'");
        CliCommands.payaraGlassFish(command, output);
        assertEquals("Command set-log-attributes executed successfully.", output.get(output.size() - 1));
        // Invoke page
        try (WebClient client = new WebClient()) {
            TextPage page = client.getPage(baseUrl + "LogRecordMapParameter");
            System.out.println(page.getContent());
        }
        // Check log
        boolean foundMapContents = false;
        try (Scanner scanner = new Scanner(new FileInputStream(logFile))) {
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                if (line.contains("\"" + LogRecordMapParameterServlet.correlationIdKey + "\":\"" + LogRecordMapParameterServlet.correlationIdValue + "\"")) {
                    foundMapContents = true;
                    break;
                }
            }
        }
        Assert.assertTrue(foundMapContents);
    } finally {
        command.clear();
        output.clear();
        command.add("set-log-attributes");
        command.add("java.util.logging.ConsoleHandler.formatter=" + originalConsoleHandlerFormatter + ":com.sun.enterprise.server.logging.GFFileHandler.formatter=" + originalFileHandlerFormatter);
        CliCommands.payaraGlassFish(command, output);
    }
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) TextPage(com.gargoylesoftware.htmlunit.TextPage) File(java.io.File) WebClient(com.gargoylesoftware.htmlunit.WebClient) FileInputStream(java.io.FileInputStream) 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