Skip to content

Commit

Permalink
Move server restart tests to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachini-Dissanayaka committed Nov 18, 2022
1 parent b65c7c3 commit 28b9989
Show file tree
Hide file tree
Showing 218 changed files with 38,407 additions and 20 deletions.
1 change: 1 addition & 0 deletions modules/integration/tests-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ under the License.
<modules>
<module>tests-benchmark</module>
<module>tests-backend</module>
<module>tests-restart</module>
<!--module>tests-config</module-->
</modules>
</project>
3 changes: 0 additions & 3 deletions modules/integration/tests-integration/tests-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ under the License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng-server-mgt.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-server-restart.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
Expand Down Expand Up @@ -217,7 +216,6 @@ under the License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng-server-mgt.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-server-restart.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
Expand Down Expand Up @@ -323,7 +321,6 @@ under the License.
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng-server-mgt.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-server-restart.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
Expand Down
862 changes: 862 additions & 0 deletions modules/integration/tests-integration/tests-restart/pom.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.am.integration.tests.api.lifecycle;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;

import java.io.File;

/**
* Deploy jaxrs_basic webApp and monitoring webApp required to run tests
* jaxrs_basic - Provides rest backend to run tests
* <p/>
* APIStatusMonitor - Can be used to retrieve API deployment status in worker and manager nodes
*/
public class APIManagerConfigurationChangeTestSuite extends APIManagerLifecycleBaseTest {

private AutomationContext superTenantKeyManagerContext;
private ServerConfigurationManager serverConfigurationManager;

@BeforeTest(alwaysRun = true)
public void configureEnvironment() throws Exception {

superTenantKeyManagerContext = new AutomationContext(APIMIntegrationConstants.AM_PRODUCT_GROUP_NAME,
APIMIntegrationConstants.AM_KEY_MANAGER_INSTANCE,
TestUserMode.SUPER_TENANT_ADMIN);
serverConfigurationManager = new ServerConfigurationManager(superTenantKeyManagerContext);
serverConfigurationManager.applyConfigurationWithoutRestart(new File(getAMResourceLocation()
+ File.separator + "configFiles" + File.separator + "fileBaseAPIS" + File.separator +
"deployment.toml"));
serverConfigurationManager.restartGracefully();
}


@AfterTest(alwaysRun = true)
public void restoreConfiguration() throws Exception {

serverConfigurationManager = new ServerConfigurationManager(superTenantKeyManagerContext);
serverConfigurationManager.restoreToLastConfiguration();
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.am.integration.tests.listener;

import org.apache.commons.lang.StringUtils;
import org.testng.IAlterSuiteListener;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

import java.util.ArrayList;
import java.util.List;

public class APIMAlterSuiteListener implements IAlterSuiteListener {
@Override
public void alter(List<XmlSuite> list) {
String testsToRunCommaSeparated = System.getenv("PRODUCT_APIM_TESTS");
String testClassesToRunCommaSeparated = System.getenv("PRODUCT_APIM_TEST_CLASSES");
String testGroupsToRunCommaSeparated = System.getenv("PRODUCT_APIM_TEST_GROUPS");
if (StringUtils.isBlank(testsToRunCommaSeparated) && StringUtils.isBlank(testClassesToRunCommaSeparated)
&& StringUtils.isBlank(testGroupsToRunCommaSeparated)) {
return;
}
String[] enabledTests = new String[]{};
String[] enabledTestClasses = new String[]{};
String[] enableTestGroups = new String[]{};
if (!StringUtils.isBlank(testsToRunCommaSeparated)) {
enabledTests = testsToRunCommaSeparated.split(",");
}
if (!StringUtils.isBlank(testClassesToRunCommaSeparated)) {
enabledTestClasses = testClassesToRunCommaSeparated.split(",");
}
if (!StringUtils.isBlank(testGroupsToRunCommaSeparated)) {
enableTestGroups = testGroupsToRunCommaSeparated.split(",");
}
for (XmlSuite suite: list) {
if ("ApiManager-features-test-suite".equals(suite.getName())) {
List<XmlTest> newXMLTests = new ArrayList<>();
for (XmlTest xmlTest: suite.getTests()) {
// process PRODUCT_APIM_TESTS to select xml tests to run
boolean xmlTestAdded = false;
for (String enabledTest: enabledTests) {
if (enabledTest.trim().equals(xmlTest.getName().trim())) {
xmlTestAdded = true;
newXMLTests.add(xmlTest);
}
}
// Process PRODUCT_APIM_TEST_GROUPS to select xml tests to run.
for (String enabledTestGroup: enableTestGroups) {
if (enabledTestGroup.trim().equals(getTestGroup(xmlTest))) {
xmlTestAdded = true;
newXMLTests.add(xmlTest);
}
}

List<XmlClass> selectedXmlClassList = new ArrayList<>();
// process PRODUCT_APIM_TEST_CLASSES to select xml test classes to run
for (String enabledTestClass : enabledTestClasses) {
List<XmlClass> xmlClassList = xmlTest.getClasses();
for (int i = 0; i < xmlClassList.size(); i++) {
if (enabledTestClass.trim().equals(xmlClassList.get(i).getName().trim())) {
// add first XML test class of the XML test always if any of the test xml class is
// selected.
if (i != 0) {
selectedXmlClassList.add(xmlClassList.get(0));
}
selectedXmlClassList.add(xmlClassList.get(i));
}
}
}
// if any xml class is selected in the particular xml test, we need to run the xml test if it is
// not added to the suite to run
if (selectedXmlClassList.size() > 0) {
xmlTest.setClasses(selectedXmlClassList);
// when the xml is not added already from the PRODUCT_APIM_TESTS list, need to add them.
if (!xmlTestAdded) {
newXMLTests.add(xmlTest);
}
}
}
suite.setTests(newXMLTests);
}
}
}

private String getTestGroup(XmlTest xmlTest) {

return xmlTest.getParameter("group");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.am.integration.tests.listener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.wso2.am.integration.tests.workflow.WorkflowApprovalExecutorTest;

public class APIMTestExecutionListener implements ITestListener {
private static final Log log = LogFactory.getLog(WorkflowApprovalExecutorTest.class);

private long startTime;

@Override
public void onStart(ITestContext iTestContext) {
log.info("Starting test group - " + iTestContext.getCurrentXmlTest().getName());
startTime = System.currentTimeMillis() / 1000;
}

@Override
public void onFinish(ITestContext iTestContext) {
long endTime = System.currentTimeMillis() / 1000;
log.info("Finished test group - " + iTestContext.getCurrentXmlTest().getName()
+ " (Completed in " + (endTime - startTime) + "s)");
}

@Override
public void onTestStart(ITestResult iTestResult) {

}

@Override
public void onTestSuccess(ITestResult iTestResult) {

}

@Override
public void onTestFailure(ITestResult iTestResult) {

}

@Override
public void onTestSkipped(ITestResult iTestResult) {

}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {

}

}
Loading

0 comments on commit 28b9989

Please sign in to comment.