Search in sources :

Example 1 with AutomationFrameworkException

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;
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ServerLogReader(org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) File(java.io.File)

Example 2 with AutomationFrameworkException

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");
        }
    }
}
Also used : AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) File(java.io.File)

Example 3 with AutomationFrameworkException

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);
}
Also used : JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) File(java.io.File) URL(java.net.URL) JMeterTestManager(org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) Test(org.testng.annotations.Test)

Example 4 with AutomationFrameworkException

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);
}
Also used : JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) File(java.io.File) URL(java.net.URL) JMeterTestManager(org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) Test(org.testng.annotations.Test)

Example 5 with AutomationFrameworkException

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());
}
Also used : JsonObject(com.google.gson.JsonObject) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)15 File (java.io.File)12 URL (java.net.URL)8 JMeterTest (org.wso2.carbon.automation.extensions.jmeter.JMeterTest)8 JMeterTestManager (org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager)8 XPathExpressionException (javax.xml.xpath.XPathExpressionException)7 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)7 JsonObject (com.google.gson.JsonObject)4 AutomationFrameworkException (org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException)4 AutomationContext (org.wso2.carbon.automation.engine.context.AutomationContext)3 IOException (java.io.IOException)2 User (org.wso2.carbon.automation.engine.context.beans.User)2 BeforeClass (org.testng.annotations.BeforeClass)1 ReportGenerator (org.wso2.carbon.automation.engine.frameworkutils.ReportGenerator)1 ArchiveExtractor (org.wso2.carbon.automation.extensions.servers.utils.ArchiveExtractor)1 ServerLogReader (org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader)1 LogViewerClient (org.wso2.carbon.integration.common.admin.client.LogViewerClient)1