use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class DesignerDataModel method loadImportedPackage.
public void loadImportedPackage(PackageVO pkg, List<ImportItem> importItems) {
ImportItem item;
// PackageListTreeModel pkgTree = getPackageListTree();
// GroupingNode pkgGrpNode;
// PackageNode pkgNode;
boolean loadPackageItself;
// load package
item = findImportItem(importItems, ImportItem.TYPE_PACKAGE, pkg.getPackageName());
loadPackageItself = item.isSelected();
if (item.isSelected()) {
// pkg.setPackageId(model.getNewId());
// pkgGrpNode = pkgTree.findPackageGroupNode(pkg.getPackageName());
// if (pkgGrpNode==null) pkgGrpNode = pkgTree.addPackageGroup(pkg.getPackageName());
// pkgNode = pkgTree.addPackage(pkgGrpNode, pkg);
addPackage(pkg);
// pkgNode.setObject(pkg);
// pkgNode.setStatus(BaseTreeNode.STATUS_NEW);
// pkgNode.clean();
} else {
pkg.setVersion(0);
// pkgNode = pkgTree.getDefaultPackageNode();
}
// add implementors
List<ActivityImplementorVO> pkgImplementors = new ArrayList<ActivityImplementorVO>();
for (ActivityImplementorVO a : pkg.getImplementors()) {
item = findImportItem(importItems, ImportItem.TYPE_IMPLEMENTOR, a.getImplementorClassName());
if (!item.isSelected()) {
if (loadPackageItself) {
if (item.getStatus() == ImportItem.STATUS_SAME || item.getStatus() == ImportItem.STATUS_DIFFERENT) {
pkgImplementors.add(findActivityImplementorVO(a.getImplementorClassName()));
// pkgNode.addImplementor(a, BaseTreeNode.STATUS_CLEAN);
}
}
} else if (item.getStatus() == ImportItem.STATUS_DIFFERENT) {
ActivityImplementorVO impl = findActivityImplementorVO(a.getImplementorClassName());
impl.setIconName(a.getIconName());
impl.setBaseClassName(a.getBaseClassName());
impl.setAttributeDescription(a.getAttributeDescription());
impl.setLabel(a.getLabel());
impl.setShowInToolbox(!StringHelper.isEmpty(a.getAttributeDescription()) && !StringHelper.isEmpty(impl.getBaseClassName()) && !StringHelper.isEmpty(impl.getIconName()));
pkgImplementors.add(impl);
// if (loadPackageItself) {
// pkgNode.addImplementor(a, BaseTreeNode.STATUS_CHANGED);
// }
} else {
// staus==STATUS_NEW
a.setImplementorId(getNewId());
addImplementor(a);
a.setShowInToolbox(!StringHelper.isEmpty(a.getAttributeDescription()) && !StringHelper.isEmpty(a.getBaseClassName()) && !StringHelper.isEmpty(a.getIconName()));
pkgImplementors.add(a);
// if (loadPackageItself) {
// pkgNode.addImplementor(a, BaseTreeNode.STATUS_NEW);
// }
}
}
nodeMetaInfo.init(activityImplementors, databaseSchemaVersion);
pkg.setImplementors(pkgImplementors);
// add event handlers
List<ExternalEventVO> pkgHandlers = new ArrayList<ExternalEventVO>();
for (ExternalEventVO e : pkg.getExternalEvents()) {
item = findImportItem(importItems, ImportItem.TYPE_HANDLER, e.getEventName());
if (!item.isSelected()) {
if (loadPackageItself) {
if (item.getStatus() == ImportItem.STATUS_SAME || item.getStatus() == ImportItem.STATUS_DIFFERENT) {
pkgHandlers.add(findExternalEvent(e.getEventName()));
// pkgNode.addHandler(e, BaseTreeNode.STATUS_CLEAN);
}
}
} else if (item.getStatus() == ImportItem.STATUS_DIFFERENT) {
ExternalEventVO vo = findExternalEvent(e.getEventName());
vo.setEventHandler(e.getEventHandler());
pkgHandlers.add(vo);
// if (loadPackageItself) {
// pkgNode.addHandler(e, BaseTreeNode.STATUS_CHANGED);
// }
} else {
// staus==STATUS_NEW
e.setId(getNewId());
addExternalEvent(e);
pkgHandlers.add(e);
// if (loadPackageItself) {
// pkgNode.addHandler(e, BaseTreeNode.STATUS_NEW);
// }
}
}
pkg.setExternalEvents(pkgHandlers);
// add ruleset
List<RuleSetVO> pkgRuleSets = new ArrayList<RuleSetVO>();
for (RuleSetVO e : pkg.getRuleSets()) {
item = findImportItem(importItems, ImportItem.TYPE_RULESET, e.getName());
if (!item.isSelected()) {
if (loadPackageItself) {
if (item.getStatus() == ImportItem.STATUS_SAME_VERSION) {
pkgRuleSets.add(findRuleSet(e.getName(), e.getLanguage()));
}
}
} else {
e.setId(getNewId());
addRuleSet(e);
pkgRuleSets.add(e);
}
}
pkg.setRuleSets(pkgRuleSets);
// TODO import participants
// load processes
List<ProcessVO> pkgProcesses = new ArrayList<ProcessVO>();
for (ProcessVO p : pkg.getProcesses()) {
item = findImportItem(importItems, ImportItem.TYPE_PROCESS, p.getProcessName());
if (item.isSelected()) {
// p.setProcessId(model.getNewId()); // set IDs for all???
if (p.getVersion() == 0) {
ProcessVO p1 = findProcessDefinition(p.getProcessName(), 0);
if (p1 != null)
p.setVersion(p1.getVersion() + 1);
else
p.setVersion(1);
}
pkgProcesses.add(p);
addProcess(p);
// pkgNode.addProcess(p, BaseTreeNode.STATUS_NEW); done by above
} else if (item.getStatus() == ImportItem.STATUS_SAME_VERSION || item.getStatus() == ImportItem.STATUS_OLD_VERSION) {
ProcessVO p1 = findProcessDefinition(p.getProcessName(), p.getVersion());
if (p1 != null) {
// indicating to include in package but do not import
p.setActivities(null);
p.setProcessId(p1.getProcessId());
pkgProcesses.add(p);
}
// else new process but not import - excluded entirely
}
}
pkg.setProcesses(pkgProcesses);
// return pkgNode;
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class DesignerDataModel method getRuleSet.
public RuleSetVO getRuleSet(DesignerDataAccess dao, Long id) throws DataAccessException, RemoteException {
RuleSetVO found = findRuleSet(id);
if (found != null) {
if (!found.isLoaded()) {
RuleSetVO loaded = dao.getRuleSet(id);
found.setLanguage(loaded.getLanguage());
found.setRuleSet(loaded.getRuleSet());
found.setVersion(loaded.getVersion());
found.setModifyingUser(loaded.getModifyingUser());
found.setModifyDate(loaded.getModifyDate());
}
return found;
}
throw new DataAccessException("Rule Set with ID " + id + " does not exist");
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO 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);
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class GroovyTestCaseScript method request.
public ApiRequest request(String target, Map<String, String> options, Closure<?> cl) throws TestException {
int dotPostmanSlash = target.lastIndexOf(".postman/");
if (dotPostmanSlash == -1)
throw new TestException("Bad API test path: " + target);
String assetName = target.substring(0, dotPostmanSlash + 8);
try {
DesignerDataAccess dao = getTestCaseRun().dao;
RuleSetVO ruleSetVO = dao.getRuleSet(assetName, null, 0);
if (ruleSetVO == null)
throw new TestException("API test case asset not found: " + assetName);
TestCase apiTestCase = new TestCase(ruleSetVO.getPackageName(), ruleSetVO.getRawFile());
String itemDetails = target.substring(dotPostmanSlash + 9);
int colon = itemDetails.indexOf(":");
String method = itemDetails.substring(0, colon);
if (method.equals("DEL"))
method = "DELETE";
TestCaseItem item = apiTestCase.getTestCaseItem(ruleSetVO, method, itemDetails.substring(colon + 1));
if (item == null)
throw new TestException("Test case item not found: " + itemDetails);
apiTestCase.addItem(item);
String resultsPath = ruleSetVO.getRawFile().getAbsolutePath();
apiTestCase.setResultDirectory(new File(resultsPath.substring(0, resultsPath.indexOf("\\assets\\")) + "\\testResults\\" + ruleSetVO.getPackageName()));
apiRequest = new ApiRequest(apiTestCase, options);
if (cl != null) {
cl.setResolveStrategy(Closure.DELEGATE_FIRST);
cl.setDelegate(apiRequest);
cl.call();
}
return apiRequest;
} catch (TestException ex) {
throw ex;
} catch (Exception ex) {
throw new TestException(ex.getMessage(), ex);
}
}
use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.
the class PluginDataAccess method organizeRuleSets.
public void organizeRuleSets() {
// designerDataModel rule_sets will have been previously loaded
// use these since they've already been retrieved, even though we
// maintain a separate cache
allRuleSets = getDesignerDataModel().getAllRuleSets();
userRuleSets = new ArrayList<>();
rulesetCustomAttributes = new HashMap<>();
for (RuleSetVO rs : allRuleSets) {
userRuleSets.add(rs);
if (rs.getLanguage() != null && !rulesetCustomAttributes.containsKey(rs.getLanguage()))
rulesetCustomAttributes.put(rs.getLanguage(), getDesignerDataModel().getRuleSetCustomAttribute(rs.getLanguage()));
}
}
Aggregations