Skip to content

Commit

Permalink
add script and improve integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thumimku committed Jul 1, 2022
1 parent 56c3097 commit fa16866
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 102 deletions.
Expand Up @@ -52,13 +52,11 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader;
import org.wso2.carbon.identity.application.common.model.xsd.Claim;
import org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig;
import org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping;
import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider;
import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient;
import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient;
import org.wso2.identity.integration.common.clients.oauth.OauthAdminClient;
Expand Down Expand Up @@ -133,59 +131,6 @@ public void testInit() throws Exception {
setClaimConfigsToServiceProvider(serviceProvider);
}

private void runAdaptiveAuthenticationDependencyScript() {

ServerLogReader inputStreamHandler;
ServerLogReader errorStreamHandler;
String scriptFolder = (System.getProperty("carbon.home"))
+ File.separator + "bin" + File.separator;
Process tempProcess = null;
File shFile = new File(scriptFolder);
java.lang.Runtime rt = java.lang.Runtime.getRuntime();

try {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
log.warn("Operating System is Windows, skipping execution");
} else {
log.info("Operating system is not windows. Executing shell script");
tempProcess = rt.getRuntime().exec(
new String[] { "/bin/bash", "dwNashorn.sh" }, null, shFile);
errorStreamHandler = new ServerLogReader("errorStream",
tempProcess.getErrorStream());
inputStreamHandler = new ServerLogReader("inputStream",
tempProcess.getInputStream());
inputStreamHandler.start();
errorStreamHandler.start();
boolean runStatus = waitForMessage(inputStreamHandler, "Updating Adaptive Authentication finished.");
log.info("Status Message : " + runStatus);
restartServer();
}
} catch (Exception e) {
log.error("Failed to execute adaptive authentication dependency script", e);
} finally {
if (tempProcess != null) {
tempProcess.destroy();
}
}
}

private void restartServer() throws AutomationUtilException, IOException, XPathExpressionException {

serverConfigurationManager = new ServerConfigurationManager(isServer);
serverConfigurationManager.restartGracefully();
}

private boolean waitForMessage(ServerLogReader inputStreamHandler,
String message) {
long time = System.currentTimeMillis() + 60 * 1000;
while (System.currentTimeMillis() < time) {
if (inputStreamHandler.getOutput().contains(message)) {
return true;
}
}
return false;
}

@AfterClass(alwaysRun = true)
public void atEnd() throws Exception {

Expand Down
Expand Up @@ -34,7 +34,6 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader;
import org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider;
import org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep;
import org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig;
Expand Down Expand Up @@ -173,7 +172,6 @@ public void testInit() throws Exception {

private void changeISConfiguration() throws Exception {

// runAdaptiveAuthenticationDependencyScript();
String carbonHome = Utils.getResidentCarbonHome();
File defaultTomlFile = getDeploymentTomlFile(carbonHome);
File configuredTomlFile = new File(getISResourceLocation() + File.separator
Expand All @@ -183,51 +181,6 @@ private void changeISConfiguration() throws Exception {
serverConfigurationManager.restartGracefully();
}

private void runAdaptiveAuthenticationDependencyScript() {

ServerLogReader inputStreamHandler;
ServerLogReader errorStreamHandler;
String scriptFolder = (System.getProperty("carbon.home"))
+ File.separator + "bin" + File.separator;
Process tempProcess = null;
File shFile = new File(scriptFolder);
java.lang.Runtime rt = java.lang.Runtime.getRuntime();

try {
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
log.warn("Operating System is Windows, skipping execution");
} else {
log.info("Operating system is not windows. Executing shell script");
tempProcess = rt.getRuntime().exec(
new String[] { "/bin/bash", "dwNashorn.sh" }, null, shFile);
errorStreamHandler = new ServerLogReader("errorStream",
tempProcess.getErrorStream());
inputStreamHandler = new ServerLogReader("inputStream",
tempProcess.getInputStream());
inputStreamHandler.start();
errorStreamHandler.start();
boolean runStatus = waitForMessage(inputStreamHandler, "Updating Adaptive Authentication finished.");
log.info("Status Message : " + runStatus);
}
} catch (Exception e) {
log.error("Failed to execute adaptive authentication dependency script", e);
} finally {
if (tempProcess != null) {
tempProcess.destroy();
}
}
}
private boolean waitForMessage(ServerLogReader inputStreamHandler,
String message) {
long time = System.currentTimeMillis() + 60 * 1000;
while (System.currentTimeMillis() < time) {
if (inputStreamHandler.getOutput().contains(message)) {
return true;
}
}
return false;
}

private void resetISConfiguration() throws Exception {

serverConfigurationManager.restoreToLastConfiguration(false);
Expand Down

0 comments on commit fa16866

Please sign in to comment.