use of com.centurylink.mdw.test.PackageTests in project mdw-designer by CenturyLinkCloud.
the class TestResultsParser method parseJson.
public void parseJson(File assetRoot) throws JSONException, IOException {
String json = new String(FileHelper.read(suiteResults));
TestCaseList testCaseList = new TestCaseList(assetRoot, new JSONObject(json));
for (PackageTests pkgTests : testCaseList.getPackageTests()) {
for (com.centurylink.mdw.test.TestCase pkgTest : pkgTests.getTestCases()) {
for (TestCase testCase : testCases) {
if (testCase.getPath().equals(pkgTest.getPackage() + "/" + pkgTest.getName())) {
testCase.setStatus(pkgTest.getStatus());
testCase.setStartDate(pkgTest.getStart());
testCase.setEndDate(pkgTest.getEnd());
testCase.setMessage(pkgTest.getMessage());
}
}
}
testCaseList.setCount(testCaseList.getTestCases().size());
}
}
use of com.centurylink.mdw.test.PackageTests in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestSuite method writeTestResults.
public void writeTestResults(AutomatedTestCase exeTestCase) throws JSONException, IOException {
String jsonString = null;
File resultsFile = getProject().getFunctionTestResultsFile();
TestCaseList testCaseList = null;
if (resultsFile.exists())
jsonString = new String(Files.readAllBytes(resultsFile.toPath()));
if (jsonString != null && !jsonString.isEmpty())
testCaseList = new TestCaseList(getProject().getAssetDir(), new JSONObject(jsonString));
if (testCaseList == null) {
testCaseList = new TestCaseList(getProject().getAssetDir());
testCaseList.setPackageTests(new ArrayList<PackageTests>());
}
for (WorkflowPackage pkg : getProject().getTopLevelUserVisiblePackages()) {
if (pkg.getTestCases() != null && !pkg.getTestCases().isEmpty()) {
PackageTests pkgTests = testCaseList.getPackageTests(pkg.getName());
for (AutomatedTestCase autoTestCase : pkg.getTestCases()) {
com.centurylink.mdw.test.TestCase testCase = null;
List<com.centurylink.mdw.test.TestCase> cases = new ArrayList<>();
boolean caseMatched = true;
if (autoTestCase.isPostman() && exeTestCase.isPostman())
testCase = testCaseList.getTestCaseByItemName(autoTestCase.getPath(), exeTestCase.getMethod() + "/" + exeTestCase.getItemName());
else
testCase = testCaseList.getTestCase(autoTestCase.getPath());
if (testCase == null) {
if (autoTestCase.getItems() != null) {
for (TestCaseItem item : autoTestCase.getItems()) {
com.centurylink.mdw.test.TestCase itemTestCase = new com.centurylink.mdw.test.TestCase(pkg.getName(), new AssetInfo(autoTestCase.getRawFile()));
String method = "";
if (item.getObject().has("request")) {
JSONObject request = item.getObject().getJSONObject("request");
if (request.has("method"))
method = request.getString("method");
}
itemTestCase.setItemName(method + "/" + item.getName());
if (exeTestCase.getMethod() != null && exeTestCase.getMethod().equals(method) && exeTestCase.getItemName() != null && exeTestCase.getItemName().equals(item.getName()))
testCase = itemTestCase;
else
cases.add(itemTestCase);
}
} else
testCase = new com.centurylink.mdw.test.TestCase(pkg.getName(), new AssetInfo(autoTestCase.getRawFile()));
}
if (pkgTests == null) {
PackageDir pkgDir = new PackageDir(getProject().getAssetDir(), pkg.getPackageVO(), null);
pkgTests = new PackageTests(pkgDir);
pkgTests.setTestCases(new ArrayList<com.centurylink.mdw.test.TestCase>());
}
if (testCase != null) {
if (testCase.getPackage().equals(pkg.getName()) && !pkgTests.getTestCases().contains(testCase)) {
pkgTests.getTestCases().add(testCase);
if (!cases.isEmpty())
pkgTests.getTestCases().addAll(cases);
}
if (autoTestCase.getItems() != null && exeTestCase.getItemName() != null && !(exeTestCase.getMethod() + "/" + exeTestCase.getItemName()).equals(testCase.getItemName()))
caseMatched = false;
if (exeTestCase.getPath().equals(autoTestCase.getPath()) && caseMatched) {
getProject().fireTestCaseStatusChange(exeTestCase, autoTestCase.getStatus());
testCase.setStatus(exeTestCase.getCaseStatus());
testCase.setStart(exeTestCase.getStartTime());
testCase.setEnd(exeTestCase.getEndTime());
testCase.setMessage(exeTestCase.getMessage());
}
}
}
if (!testCaseList.getPackageTests().contains(pkgTests))
testCaseList.getPackageTests().add(pkgTests);
}
}
testCaseList.setCount(testCaseList.getTestCases().size());
PluginUtil.writeFile(resultsFile, testCaseList.getJson().toString(2).getBytes());
}
use of com.centurylink.mdw.test.PackageTests in project mdw-designer by CenturyLinkCloud.
the class AutoTestAntTask method runTests.
public void runTests() throws Exception {
if (!baseDir.exists() || !baseDir.isDirectory())
throw new IOException("Directory does not exist: " + baseDir);
ThreadPool threadPool = new ThreadPool(threadCount);
HashMap<String, ProcessVO> processCache = new HashMap<>();
boolean hasGherkin = false;
boolean hasNonGherkin = false;
if (workflowDir != null) {
DirectoryScanner scanner = getDirectoryScanner(workflowDir);
scanner.scan();
String jsonString;
if (testResultsSummaryFile.exists() && testResultsSummaryFile.getName().endsWith(".json")) {
jsonString = new String(Files.readAllBytes(testResultsSummaryFile.toPath()));
if (jsonString != null && !jsonString.isEmpty())
testCaseList = new TestCaseList(workflowDir, new JSONObject(jsonString));
}
if (testCaseList == null) {
testCaseList = new TestCaseList(workflowDir);
testCaseList.setPackageTests(new ArrayList<PackageTests>());
}
String workflowPath = workflowDir.toString().replace('\\', '/');
String[] caseFilePaths = scanner.getIncludedFiles();
for (String caseFilePath : caseFilePaths) {
String casePath = caseFilePath.replace('\\', '/');
int lastSlash = casePath.lastIndexOf('/');
String pkgName = casePath.substring(0, lastSlash).replace('/', '.');
File caseFile = new File(workflowPath + "/" + casePath);
PackageTests pkgTests = testCaseList.getPackageTests(pkgName);
if (pkgTests == null) {
PackageDir pkgDir = new PackageDir(workflowDir, caseFile.getParentFile(), null);
pkgDir.parse();
pkgTests = new PackageTests(pkgDir);
pkgTests.setTestCases(new ArrayList<com.centurylink.mdw.test.TestCase>());
testCaseList.getPackageTests().add(pkgTests);
}
pkgTests.getTestCases().add(new com.centurylink.mdw.test.TestCase(pkgName, new AssetInfo(caseFile)));
TestCase tc = new TestCase(pkgName, caseFile);
if (tc.isGherkin())
hasGherkin = true;
else
hasNonGherkin = true;
testCases.add(tc);
}
} else if (jdbcUrl != null) {
// db asset tests
if (dbAssetTests == null)
throw new BuildException("Attribute dbAssetTests required for non-VCS asset tests");
String[] assets = dbAssetTests.split("\\s?,\\s?");
for (String asset : assets) {
int lastSlash = asset.lastIndexOf('/');
String pkg = asset.substring(0, lastSlash);
String assetName = asset.substring(lastSlash + 1);
String language = RuleSetVO.getLanguage(assetName.substring(assetName.lastIndexOf('.')));
RuleSetVO ruleSet = designerDataAccess.getRuleSet(assetName, language, 0);
ruleSet.setPackageName(pkg);
TestCase tc = new TestCase(pkg, ruleSet);
testCases.add(tc);
}
} else {
throw new BuildException("Missing attribute: workflowDir");
}
if (hasGherkin && hasNonGherkin)
throw new BuildException("Gherkin/non-Gherkin tests require separate task/target executions.");
// gradle
boolean useStdErr = System.getProperty("org.gradle.appname") != null;
// does
// not
// show
// output
// otherwise
LogMessageMonitor monitor = hasGherkin ? null : new LogMessageMonitor(designerDataAccess, oldNamespaces);
if (monitor != null)
monitor.start(true);
for (TestCase testCase : testCases) {
String masterRequestId = user + "-" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
File resultDir = new File(testResultsDir + "/" + testCase.getPrefix());
testCase.prepare();
TestCaseRun run;
if (testCase.isGherkin()) {
// User defined masterRequestId
if (testCase.getMasterRequestId() != null) {
if (testCase.getMasterRequestId().indexOf("${masterRequestId}") != -1) {
masterRequestId = testCase.getMasterRequestId().replace("${masterRequestId}", masterRequestId);
} else
masterRequestId = testCase.getMasterRequestId();
}
testCase.setMasterRequestId(masterRequestId);
run = new GherkinTestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, oldNamespaces, resultDir, stubbing, stubPort);
} else if (testCase.isGroovy())
run = new GroovyTestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, loadTests, true, oldNamespaces, null);
else
run = new TestCaseRun(testCase, 0, masterRequestId, new DesignerDataAccess(designerDataAccess), monitor, processCache, loadTests, true, oldNamespaces);
File executeLog = new File(resultDir.getPath() + "/" + testCase.getCaseName() + ".log");
if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
PrintStream log = verbose ? new TeePrintStream(useStdErr ? System.err : System.out, executeLog) : new PrintStream(executeLog);
run.prepareTest(false, resultDir, true, singleServer, stubbing, log);
if (verbose)
log("Test case prepared: " + testCase.getCaseName(), useStdErr ? Project.MSG_ERR : Project.MSG_INFO);
masterRequestRunMap.put(run.getMasterRequestId(), run);
threadPool.execute(run);
updateResults(false);
try {
Thread.sleep(intervalSecs * 1000);
} catch (InterruptedException e) {
}
}
log("All cases prepared. Waiting for completion ...", Project.MSG_INFO);
threadPool.shutdown();
while (!threadPool.isTerminated()) {
updateResults(false);
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
}
}
if (monitor != null)
monitor.shutdown();
updateResults(true);
log("All cases completed.", Project.MSG_ERR);
}
Aggregations