Skip to content

Add integration test with OpenDJ Docker container #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions openam-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2011-2016 ForgeRock AS.
* Portions copyright 2017-2025 3A Systems LLC.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand All @@ -23,6 +24,9 @@
<artifactId>openam</artifactId>
<version>15.1.6-SNAPSHOT</version>
</parent>
<properties>
<test.config.path>${basedir}/target/config</test.config.path>
</properties>

<!-- Component Definition -->
<name>OpenAM Server</name>
Expand Down Expand Up @@ -95,8 +99,8 @@
<systemProperties>
<file.encoding>UTF-8</file.encoding>
<com.sun.xml.ws.transport.http.HttpAdapter.dump>true</com.sun.xml.ws.transport.http.HttpAdapter.dump>
<com.iplanet.services.configpath>${basedir}/target/config</com.iplanet.services.configpath>
<com.sun.identity.configuration.directory>${basedir}/target/config</com.sun.identity.configuration.directory>
<com.iplanet.services.configpath>${test.config.path}</com.iplanet.services.configpath>
<com.sun.identity.configuration.directory>${test.config.path}</com.sun.identity.configuration.directory>
<logback.configurationFile>${basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
<ssoadm.disabled>false</ssoadm.disabled>
<com.iplanet.services.debug.level>message</com.iplanet.services.debug.level>
Expand All @@ -114,6 +118,13 @@
</properties>
<pingURL>http://localhost:8207/openam</pingURL>
</deployable>
<deployable>
<type>war</type>
<properties>
<context>am</context>
</properties>
<pingURL>http://localhost:8207/am</pingURL>
</deployable>
</deployables>
<configuration>
<properties>
Expand Down Expand Up @@ -157,6 +168,12 @@
<version>4.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.20.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand All @@ -179,6 +196,9 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
<systemProperties>
<test.config.path>${test.config.path}</test.config.path>
</systemProperties>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2025 3A Systems LLC.
*/

package org.openidentityplatform.openam.test.integration;

import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;

public abstract class BaseTest {
WebDriver driver;
WebDriverWait wait;

final static String AM_PASSWORD = "AMp@ssw0rd";
final static String PA_PASSWORD = "PAp@ssw0rd";

@BeforeClass
public void webdriverSetup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*","--headless", "--disable-dev-shm-usage", "--no-sandbox", "--verbose");
//options.addArguments("--remote-allow-origins=*", "--verbose");
driver = new ChromeDriver(options);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

@AfterClass
public void webDriverTearDown() {
if(driver != null) {
driver.quit();
}
}

@BeforeMethod
public void cleanup() throws IOException {
String testConfigPath = System.getProperty("test.config.path");
Path testConfig = Paths.get(testConfigPath);
if(testConfig.toFile().exists()) {
System.out.println("delete existing config directory");
FileUtils.deleteDirectory(testConfig.toFile());
}
}

protected void printInstallLogFile() {
String testConfigPath = System.getProperty("test.config.path");
Path installLog = Paths.get(testConfigPath, "install.log");
if(installLog.toFile().exists()) {
System.err.println("install.log file:");
try (BufferedReader reader = new BufferedReader(new FileReader(installLog.toFile()))) {
String line;
while ((line = reader.readLine()) != null) {
System.err.println(line);
}
} catch (IOException e) {
System.err.println("Error reading file: " + e.getMessage());
}
}

}

WebElement waitForElement(By by) {
return wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

WebElement waitForElementVisible(By by) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}

public static ExpectedCondition<WebElement> visibilityOfAnyElement(final By locator) {
return new ExpectedCondition<WebElement>() {

@Override
public WebElement apply(WebDriver webDriver) {
List<WebElement> elements = webDriver.findElements(locator);
return elements.stream().filter(WebElement::isDisplayed).findFirst().orElse(null);
}

@Override
public String toString() {
return "visibility of any element " + locator;
}
};
}

public boolean isTextPresent(String str) {
Exception lastException = new Exception();
for(int i = 0; i < 3; i++) {
try {
WebElement bodyElement = new WebDriverWait(driver,Duration.ofSeconds(20)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")));
return bodyElement.getText().toLowerCase().contains(str.toLowerCase());
} catch (StaleElementReferenceException e) {
lastException = e;
}
}
throw new RuntimeException(lastException);
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2022-2025 3A Systems LLC.
*/

package org.openidentityplatform.openam.test.integration;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.time.Duration;
import java.util.List;

import static org.testng.Assert.assertTrue;

public class IT_Setup {
public class IT_Setup extends BaseTest {

WebDriver driver;
WebDriverWait wait;
@Test
public void testSetup() {

final static String OPENAM_URL = "http://openam.local:8207/openam";
final static String AM_PASSWORD = "AMp@ssw0rd";
final static String PA_PASSWORD = "PAp@ssw0rd";

@BeforeTest
public void webdriverSetup() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*","--headless", "--disable-dev-shm-usage", "--no-sandbox", "--verbose");
driver = new ChromeDriver(options);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

@Test
public void testSetup() {
driver.get(OPENAM_URL);
final String openamUrl = "http://openam.local:8207/openam";

driver.get(openamUrl);

//wait for setup page is loaded
waitForElement(By.id("pushConfigDialog_c"));
Expand All @@ -65,8 +64,19 @@ public void testSetup() {

//wait for setup complete
WebDriverWait waitComplete = new WebDriverWait(driver, Duration.ofSeconds(300));
WebElement proceedToConsole = waitComplete.until(visibilityOfAnyElement(By.cssSelector("#confComplete a")));
proceedToConsole.click();
try {
WebElement proceedToConsole = waitComplete.until(visibilityOfAnyElement(By.cssSelector("#confComplete a")));
proceedToConsole.click();
} catch (TimeoutException e) {
System.err.println("error occurred during install: " + e);
WebElement progressIframe = waitForElement(By.id("progressIframe"));
driver.switchTo().frame(progressIframe);
System.err.println("output messages: " + waitForElement(By.id("progressP")).getText());
printInstallLogFile();
throw e;
} finally {
driver.switchTo().defaultContent();
}

waitForElement(By.id("IDToken1")).sendKeys("amadmin");
waitForElement(By.id("IDToken2")).sendKeys(AM_PASSWORD);
Expand All @@ -79,7 +89,7 @@ public void testSetup() {
assertTrue(isTextPresent("You are logged out."));

//check XUI
driver.get(OPENAM_URL.concat("/XUI"));
driver.get(openamUrl.concat("/XUI"));
waitForElement(By.id("idToken1")).sendKeys("amadmin");
waitForElement(By.id("idToken2")).sendKeys(AM_PASSWORD);
waitForElement(By.id("loginButton_0")).click();
Expand All @@ -88,47 +98,5 @@ public void testSetup() {
waitForElementVisible(By.id("mainNavBar"));
}

@AfterTest
public void webDriverTearDown() {
if(driver != null) {
driver.quit();
}
}

WebElement waitForElement(By by) {
return wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

WebElement waitForElementVisible(By by) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}

public static ExpectedCondition<WebElement> visibilityOfAnyElement(final By locator) {
return new ExpectedCondition<WebElement>() {

@Override
public WebElement apply(WebDriver webDriver) {
List<WebElement> elements = webDriver.findElements(locator);
return elements.stream().filter(WebElement::isDisplayed).findFirst().orElse(null);
}

@Override
public String toString() {
return "visibility of any element " + locator;
}
};
}

public boolean isTextPresent(String str) {
Exception lastException = new Exception();
for(int i = 0; i < 3; i++) {
try {
WebElement bodyElement = new WebDriverWait(driver,Duration.ofSeconds(20)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")));
return bodyElement.getText().toLowerCase().contains(str.toLowerCase());
} catch (StaleElementReferenceException e) {
lastException = e;
}
}
throw new RuntimeException(lastException);
}
}
Loading