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);
}
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();
}
}
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");
}
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"));
}
}
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);
}
}
Aggregations