changes for integration tests - TFLDEV-41
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/f2830962 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/f2830962 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/f2830962 Branch: refs/heads/stratos-4.1.x Commit: f2830962cb6b9277a22941b7faacbe410d9d0cdd Parents: 932ec49 Author: Isuru Haththotuwa <[email protected]> Authored: Sat Nov 21 08:27:32 2015 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Sat Nov 21 10:35:28 2015 +0530 ---------------------------------------------------------------------- .../integration/common/ServerLogClient.java | 96 +++++++++++++------- .../tests/other/IaasProviderAttributeTest.java | 31 +++++-- 2 files changed, 84 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/f2830962/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java index 2ac6ce9..12c40f8 100644 --- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/ServerLogClient.java @@ -22,25 +22,22 @@ package org.apache.stratos.integration.common; import org.apache.axis2.AxisFault; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.automation.engine.context.AutomationContext; import org.wso2.carbon.integration.common.admin.client.LogViewerClient; import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; +import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException; +import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; -import javax.xml.xpath.XPathExpressionException; +import java.rmi.RemoteException; public class ServerLogClient { private static final Log log = LogFactory.getLog(ServerLogClient.class); private LogViewerClient logViewerClient; - private AutomationContext automationContext; - - public ServerLogClient () throws AutomationUtilException { - createAutomationContext(); - createlogViewerClient(getBackEndUrl(), getUsername(), getPassword()); - } + private int logCount; public ServerLogClient (String backEndUrl, String username, String password) throws AutomationUtilException { + logCount = 0; createlogViewerClient(backEndUrl, username, password); } @@ -54,48 +51,81 @@ public class ServerLogClient { } } - private void createAutomationContext() throws AutomationUtilException { + public LogEvent[] getLogLines () throws AutomationUtilException { try { - automationContext = new AutomationContext(); - } catch (XPathExpressionException e) { - String errorMsg = "Error in creating AutomationContext"; + return logViewerClient.getAllRemoteSystemLogs(); + + } catch (RemoteException e) { + String errorMsg = "Error in creating getting remote system logs"; log.error(errorMsg, e); throw new AutomationUtilException(errorMsg, e); - } - } - private String getBackEndUrl () throws AutomationUtilException { - try { - return automationContext.getContextUrls().getBackEndUrl(); - } catch (XPathExpressionException e) { - String errorMsg = "Error in getting beck end URL"; + } catch (LogViewerLogViewerException e) { + String errorMsg = "Error in creating getting remote system logs"; log.error(errorMsg, e); throw new AutomationUtilException(errorMsg, e); } } - private String getUsername () throws AutomationUtilException { + public LogEvent[] getLogLines (String logType, String searchKey, String domain, String serverKey) + throws AutomationUtilException { try { - return automationContext.getSuperTenant().getTenantAdmin().getUserName(); - } catch (XPathExpressionException e) { - String errorMsg = "Error in getting super tenant username"; + return logViewerClient.getRemoteLogs(logType, searchKey, domain, serverKey); + } catch (RemoteException e) { + String errorMsg = "Error in creating getting remote system logs"; log.error(errorMsg, e); throw new AutomationUtilException(errorMsg, e); - } - } - private String getPassword () throws AutomationUtilException { - try { - return automationContext.getSuperTenant().getTenantAdmin().getPassword(); - } catch (XPathExpressionException e) { - String errorMsg = "Error in getting super tenant password"; + } catch (LogViewerLogViewerException e) { + String errorMsg = "Error in creating getting remote system logs"; log.error(errorMsg, e); throw new AutomationUtilException(errorMsg, e); } } +// public String[] getLogLines() throws AutomationUtilException { +// +// LogEvent[] allLogs = null; +// try { +// allLogs = logViewerClient.getAllRemoteSystemLogs(); +// +// } catch (RemoteException e) { +// String errorMsg = "Error in creating getting remote system logs"; +// log.error(errorMsg, e); +// throw new AutomationUtilException(errorMsg, e); +// +// } catch (LogViewerLogViewerException e) { +// String errorMsg = "Error in creating getting remote system logs"; +// log.error(errorMsg, e); +// throw new AutomationUtilException(errorMsg, e); +// } +// +// if (allLogs.length == 0) { +// allLogs = new LogEvent[0]; +// } +// +// if (logCount > allLogs.length) { +// // cannot happen, return +// return getLogsAsStrings(allLogs); +// } +// +// log.info("Total no. of log lines: " + Integer.toString(allLogs.length)); +// log.info("Previously returned count : " + Integer.toString(logCount)); +// log.info("Current count : " + Integer.toString(allLogs.length - logCount)); +// +// LogEvent[] selectedLogs = Arrays.copyOfRange(allLogs, logCount, allLogs.length); +// logCount += (allLogs.length - logCount); +// +// return getLogsAsStrings(selectedLogs); +// } +// +// private String[] getLogsAsStrings(LogEvent[] selectedLogs) { +// +// String [] logs = new String[selectedLogs.length]; +// for (int i = 0 ; i < selectedLogs.length ; i++) { +// logs [i] = selectedLogs [i].getMessage(); +// } +// return logs; +// } - public LogViewerClient getLogViewerClient () { - return logViewerClient; - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/f2830962/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java index 1f7b042..5a44c62 100644 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/other/IaasProviderAttributeTest.java @@ -29,6 +29,8 @@ import org.apache.stratos.integration.common.ServerLogClient; import org.apache.stratos.integration.common.TopologyHandler; import org.apache.stratos.integration.tests.StratosIntegrationTest; import org.apache.stratos.messaging.domain.application.ApplicationStatus; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; @@ -50,6 +52,12 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { private static final String CARTRIDGE = "cartridge-iaasprovider-attribute-test"; private static final String UPDATED_CARTRIDGE = "cartridge-iaasprovider-attribute-test-updated"; private static final String APPLICATION = "app-iaasprovider-attribute-test"; + private ServerLogClient serverLogClient; + + @BeforeClass + public void setup () throws Exception { + serverLogClient = new ServerLogClient(stratosSecuredBackendURL + "/services/", adminUsername, adminPassword); + } @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.iaas.attributes", "all"}) public void testIaasProviderAttributes () throws Exception { @@ -125,14 +133,10 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { // create a ServerLogClientInstance and get logs boolean found = false; - ServerLogClient serverLogClient = new ServerLogClient(stratosSecuredBackendURL + "/services/", - adminUsername, - adminPassword); - LogEvent [] logEvents = serverLogClient.getLogViewerClient().getAllRemoteSystemLogs(); + LogEvent[] logEvents = serverLogClient.getLogLines(); if (logEvents.length > 0) { - for (int i = 0; i < logEvents.length; i++) { - if (!logEvents[i].getMessage().contains("cartridge_property_value_1") && - logEvents[i].getMessage().contains("cc_property_value_1")) { + for (LogEvent log : logEvents) { + if (!log.getMessage().contains("cartridge_property_value_1") && log.getMessage().contains("cc_property_value_1")) { found = true; break; } @@ -173,10 +177,14 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { assertTrue(appDeployed); log.info("Re-deployed application 'app-iaasprovider-attribute-test'"); - logEvents = serverLogClient.getLogViewerClient().getAllRemoteSystemLogs(); + log.info("Waiting for application status to become ACTIVE..."); + topologyHandler.assertApplicationStatus(applicationBean.getApplicationId(), ApplicationStatus.Active); + + logEvents = serverLogClient.getLogLines(); + found = false; if (logEvents.length > 0) { - for (int i = 0; i < logEvents.length; i++) { - if (logEvents[i].getMessage().contains("cartridge_property_value_1")) { + for (LogEvent log : logEvents) { + if (log.getMessage().contains("cartridge_property_value_1")) { found = true; break; } @@ -184,7 +192,10 @@ public class IaasProviderAttributeTest extends StratosIntegrationTest { } assertTrue("Property 'property1' not found | value not equal to 'cartridge_property_value_1'", found); + } + @AfterClass + public void tearDown () throws Exception { terminateAndRemoveAllArtifacts(); }
