use of org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException in project product-iots by wso2.
the class CarbonServerManagerExtension method startServerUsingCarbonHome.
public synchronized void startServerUsingCarbonHome(String carbonHome, Map<String, String> commandMap) throws AutomationFrameworkException {
if (this.process == null) {
this.portOffset = this.checkPortAvailability(commandMap);
Process tempProcess = null;
try {
if (!commandMap.isEmpty() && this.getPortOffsetFromCommandMap(commandMap) == 0) {
System.setProperty("carbon.home", carbonHome);
}
File commandDir = new File(carbonHome);
log.info("Starting carbon server............. ");
String scriptName = TestFrameworkUtils.getStartupScriptFileName(carbonHome);
String[] parameters = this.expandServerStartupCommandList(commandMap);
String[] cmdArray;
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
commandDir = new File(carbonHome + File.separator + "bin");
cmdArray = new String[] { "cmd.exe", "/c", scriptName + ".bat" };
cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
} else {
cmdArray = new String[] { "sh", "bin/" + scriptName + ".sh" };
cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
}
this.errorStreamHandler = new ServerLogReader("errorStream", tempProcess.getErrorStream());
this.inputStreamHandler = new ServerLogReader("inputStream", tempProcess.getInputStream());
this.inputStreamHandler.start();
this.errorStreamHandler.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
CarbonServerManagerExtension.this.serverShutdown(CarbonServerManagerExtension.this.portOffset);
} catch (Exception var2) {
CarbonServerManagerExtension.log.error("Error while server shutdown ..", var2);
}
}
});
ClientConnectionUtil.waitForPort(defaultHttpPort + this.portOffset, DEFAULT_START_STOP_WAIT_MS, false, (String) this.automationContext.getInstance().getHosts().get("default"));
long time = System.currentTimeMillis() + 60000L;
// while(true) {
// if(this.inputStreamHandler.getOutput().contains("Mgt Console URL") || System.currentTimeMillis() >= time) {
// int httpsPort = defaultHttpsPort + this.portOffset;
// String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
// User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
// ClientConnectionUtil.waitForLogin(backendURL, superUser);
// log.info("Server started successfully.");
// break;
// }
// }
int httpsPort = defaultHttpsPort + this.portOffset;
String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
ClientConnectionUtil.waitForLogin(backendURL, superUser);
} catch (XPathExpressionException | IOException var13) {
throw new IllegalStateException("Unable to start server", var13);
}
this.process = tempProcess;
}
}
use of org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException in project product-iots by wso2.
the class CarbonServerManagerExtension method serverShutdown.
public synchronized void serverShutdown(int portOffset) throws AutomationFrameworkException {
if (this.process != null) {
log.info("Shutting down server..");
if (ClientConnectionUtil.isPortOpen(Integer.parseInt("9443") + portOffset)) {
int httpsPort = defaultHttpsPort + portOffset;
String url = null;
try {
url = this.automationContext.getContextUrls().getBackEndUrl();
} catch (XPathExpressionException var10) {
throw new AutomationFrameworkException("Get context failed", var10);
}
String backendURL = url.replaceAll("(:\\d+)", ":" + httpsPort);
try {
ClientConnectionUtil.sendForcefulShutDownRequest(backendURL, this.automationContext.getSuperTenant().getContextUser().getUserName(), this.automationContext.getSuperTenant().getContextUser().getPassword());
} catch (AutomationFrameworkException var8) {
throw new AutomationFrameworkException("Get context failed", var8);
} catch (XPathExpressionException var9) {
throw new AutomationFrameworkException("Get context failed", var9);
}
long time = System.currentTimeMillis() + 300000L;
// while(!this.inputStreamHandler.getOutput().contains("Halting JVM") && System.currentTimeMillis() < time) {
// ;
// }
log.info("Server stopped successfully...");
}
this.inputStreamHandler.stop();
this.errorStreamHandler.stop();
this.process.destroy();
this.process = null;
if (this.isCoverageEnable) {
try {
log.info("Generating Jacoco code coverage...");
this.generateCoverageReport(new File(this.carbonHome + File.separator + "wso2" + File.separator + "components" + File.separator + "plugins" + File.separator));
} catch (IOException var7) {
log.error("Failed to generate code coverage ", var7);
throw new AutomationFrameworkException("Failed to generate code coverage ", var7);
}
}
if (portOffset == 0) {
System.clearProperty("carbon.home");
}
}
}
use of org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException in project product-iots by wso2.
the class AndroidDeviceManagementAPIJmeterTestCase method permutationTest.
@Test(description = "Testing the response when sending different input parameters with different values")
public void permutationTest() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader().getResource("jmeter-scripts" + File.separator + "AndroidDeviceManagementAPIAdditionalPermutations.jmx");
JMeterTest script = new JMeterTest(new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running permutation test using jmeter scripts");
manager.runTest(script);
}
use of org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException in project product-iots by wso2.
the class PolicyManagementJMeterTestCase method PolicyManagementTest.
@Test(description = "This test case tests the Policy Management APIs")
public void PolicyManagementTest() throws AutomationFrameworkException {
URL url = Thread.currentThread().getContextClassLoader().getResource("jmeter-scripts" + File.separator + "PolicyManagementAPI.jmx");
JMeterTest script = new JMeterTest(new File(url.getPath()));
JMeterTestManager manager = new JMeterTestManager();
log.info("Running policy management api test cases using jmeter scripts");
manager.runTest(script);
}
use of org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException in project product-iots by wso2.
the class AndroidOperation method testUpgradeFirmware.
@Test(groups = { Constants.AndroidOperations.OPERATIONS_GROUP }, description = "Test upgrade firmware operation")
public void testUpgradeFirmware() throws FileNotFoundException, MalformedURLException, AutomationFrameworkException {
JsonObject upgradeFirmWarePayload = PayloadGenerator.getJsonPayload(Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, Constants.AndroidOperations.UPGRADE_FIRMWARE_OPERATION);
HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.AndroidOperations.UPGRADE_FIRMWARE_ENDPOINT, upgradeFirmWarePayload.toString());
Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
}
Aggregations