use of com.centurylink.mdw.plugin.project.model.WorkflowProject in project mdw-designer by CenturyLinkCloud.
the class AutoTestPropertyTester method test.
// TODO: support multiple selections
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
ResourceWrapper resourceWrapper = new ResourceWrapper((IAdaptable) receiver);
try {
WorkflowProject workflowProject = resourceWrapper.getOwningWorkflowProject();
if ("canLaunchAutoTest".equals(property)) {
// currently only for
// debug
IFile file = resourceWrapper.getFile();
if (file != null && ("test".equals(file.getFileExtension()) || "postman".equals(file.getFileExtension())) && file.exists() && !file.isDerived() && workflowProject != null) {
WorkflowPackage pkg = workflowProject.getPackage((IFolder) file.getParent());
if (pkg != null)
return pkg.getAsset(file) != null;
}
} else if ("canLaunchAutomatedTests".equals(property)) {
IFolder folder = resourceWrapper.getFolder();
if (folder != null) {
workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(folder.getProject());
if (workflowProject != null && workflowProject.isInitialized()) {
WorkflowPackage pkg = workflowProject.getPackage(folder);
if (pkg != null)
return !pkg.getTestCases().isEmpty();
}
} else {
IProject project = resourceWrapper.getProject();
if (project != null) {
WorkflowProject proj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
if (proj != null && proj.isInitialized()) {
return !proj.getTestCases().isEmpty();
}
}
}
} else if ("canLaunchCucumberTest".equals(property)) {
if (resourceWrapper.getOwningJavaProject() != null) {
IFile file = resourceWrapper.getFile();
if (file != null && "feature".equals(file.getFileExtension()) && file.exists() && !file.isDerived()) {
// exclude mdw automated gherkin tests
if (workflowProject != null && workflowProject.isInitialized()) {
ResourceWrapper parentWrapper = new ResourceWrapper((IAdaptable) file.getParent());
IFolder folder = parentWrapper.getFolder();
if (folder != null && workflowProject.getPackage(folder) != null)
return false;
}
return true;
}
}
} else if ("canLaunchCucumberTests".equals(property) && resourceWrapper.getOwningJavaProject() != null) {
IFolder folder = resourceWrapper.getFolder();
if (folder != null) {
if (workflowProject != null && workflowProject.isInitialized() && workflowProject.getPackage(folder) != null)
return false;
List<CucumberTest> tests = new ArrayList<>();
CucumberTest.findTests(folder, tests);
return !tests.isEmpty();
} else {
return false;
}
}
} catch (CoreException ex) {
PluginMessages.log(ex);
}
return false;
}
use of com.centurylink.mdw.plugin.project.model.WorkflowProject in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestLaunchConfiguration method launch.
public void launch(ILaunchConfiguration launchConfig, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(launchConfig.getAttribute(WORKFLOW_PROJECT, ""));
boolean isLoadTest = launchConfig.getAttribute(IS_LOAD_TEST, false);
String attrPrefix = isLoadTest ? AutomatedTestCase.LOAD_TEST : AutomatedTestCase.FUNCTION_TEST;
String resultsPath = launchConfig.getAttribute(attrPrefix + "_" + RESULTS_PATH, "");
if (resultsPath.isEmpty())
resultsPath = WorkflowProject.DEFAULT_TEST_RESULTS_PATH;
workflowProject.setTestResultsPath(attrPrefix, resultsPath);
int threadCount = launchConfig.getAttribute(attrPrefix + "_" + THREAD_COUNT, 5);
int runCount = launchConfig.getAttribute(attrPrefix + "_" + RUN_COUNT, 100);
int threadInterval = launchConfig.getAttribute(attrPrefix + "_" + THREAD_INTERVAL, 2);
int runInterval = launchConfig.getAttribute(attrPrefix + "_" + RUN_INTERVAL, 2);
boolean verbose = launchConfig.getAttribute(attrPrefix + "_" + VERBOSE, true);
boolean stubbing = launchConfig.getAttribute(attrPrefix + "_" + STUBBING, false);
boolean singleServer = launchConfig.getAttribute(attrPrefix + "_" + SINGLE_SERVER, true);
boolean createReplace = launchConfig.getAttribute(attrPrefix + "_" + CREATE_REPLACE_RESULTS, false);
boolean postmanTestsExists = false;
HashMap<String, Boolean> testCaseOrder = null;
testSuite = new AutomatedTestSuite(workflowProject);
testSuite.setLoadTest(isLoadTest);
testSuite.setThreadCount(threadCount);
testSuite.setRunCount(runCount);
if (isLoadTest)
testSuite.setThreadInterval(runInterval);
else
testSuite.setThreadInterval(threadInterval);
testSuite.setVerbose(verbose);
testSuite.setStubbing(stubbing);
testSuite.setSingleServer(singleServer);
testSuite.setCreateReplaceResults(createReplace);
List<AutomatedTestCase> testCases = new ArrayList<>();
List<String> testCasesStr = launchConfig.getAttribute(attrPrefix + "_" + TEST_CASES, new ArrayList<String>());
for (String testCaseStr : testCasesStr) {
AutomatedTestCase autoTestCase;
if (testCaseStr.startsWith("Legacy/"))
autoTestCase = workflowProject.getLegacyTestSuite().getTestCase(testCaseStr);
else if (testCaseStr.indexOf("postman") > -1) {
String[] pathArray = testCaseStr.split("/");
String method = pathArray[2];
AutomatedTestCase cloneTestCase = (AutomatedTestCase) workflowProject.getAsset(pathArray[0] + "/" + pathArray[1]);
autoTestCase = new AutomatedTestCase(cloneTestCase);
autoTestCase.setId(cloneTestCase.getId());
try {
StringBuilder itemName = new StringBuilder(pathArray[3]);
for (int i = 4; i < pathArray.length; i++) itemName = itemName.append("/" + pathArray[i]);
autoTestCase.setItemName(itemName.toString());
autoTestCase.setMethod(method);
autoTestCase.getTestCase().resetItems();
autoTestCase.getTestCase().addItem(cloneTestCase.getItem(itemName.toString(), method));
postmanTestsExists = true;
} catch (Exception e) {
PluginMessages.log(e);
}
} else
autoTestCase = (AutomatedTestCase) workflowProject.getAsset(testCaseStr);
autoTestCase.setTestSuite(testSuite);
if (!autoTestCase.getResultsDir().exists())
autoTestCase.getResultsDir().mkdirs();
testCases.add(autoTestCase);
}
testSuite.setTestCases(testCases);
if (postmanTestsExists) {
testCaseOrder = new HashMap<>();
List<AutomatedTestCase> cases = new ArrayList<>();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
if (!testCase.isPostman())
cases.add(testCase);
else {
if (testCaseOrder.get(testCase.getName()) == null) {
List<AutomatedTestCase> postmanCases = testSuite.getPostmanTestCasesByName(testCase.getName());
testCaseOrder.put(testCase.getName(), true);
AutomatedTestCase postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "GET");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "DELETE");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "POST");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "PUT");
if (postmanCase != null)
cases.add(postmanCase);
}
}
}
testSuite.setTestCases(cases);
}
if (isLoadTest) {
Map<String, String> testCaseCounts = launchConfig.getAttribute(attrPrefix + "_" + TESTCASE_COUNTS_MAP, new HashMap<String, String>());
for (Map.Entry<String, String> entry : testCaseCounts.entrySet()) {
int count = Integer.parseInt(entry.getValue());
testSuite.getTestCase(entry.getKey()).setRunCount(count);
}
}
if (!testSuite.getResultsDir().exists())
testSuite.getResultsDir().mkdirs();
testSuite.setDebug(ILaunchManager.DEBUG_MODE.equals(mode));
showResultsView();
}
use of com.centurylink.mdw.plugin.project.model.WorkflowProject in project mdw-designer by CenturyLinkCloud.
the class TomcatServerOptionsSection method getDescription.
protected String getDescription() {
if (server != null && server.getRuntime() != null) {
String tomcatLoc = String.valueOf(server.getRuntime().getLocation());
WorkflowProject workflowProject = getProject();
String desc = "Tomcat Location: " + new File(tomcatLoc) + "\nMDW War: ";
if (workflowProject != null)
desc += new File(workflowProject.getDeployFolder().getLocation().toPortableString() + "/webapps/mdw.war");
return desc;
} else {
return "MDW Tomcat Launch Settings";
}
}
use of com.centurylink.mdw.plugin.project.model.WorkflowProject in project mdw-designer by CenturyLinkCloud.
the class TomcatServerOptionsSection method getDefaultJavaOptions.
protected String getDefaultJavaOptions() {
WorkflowProject project = getProject();
String runtimeEnv = project != null && project.checkRequiredVersion(6, 0) ? "-Dmdw.runtime.env=dev" : "-DruntimeEnv=dev";
return runtimeEnv + "\n" + "-Dmdw.config.location=" + (project == null ? "null" : project.getProjectDir()) + System.getProperty("file.separator") + "config\n" + "-Xms512m -Xmx1024m -XX:MaxPermSize=256m";
}
use of com.centurylink.mdw.plugin.project.model.WorkflowProject in project mdw-designer by CenturyLinkCloud.
the class TomcatServerBehavior method publishModule.
/**
* For client apps with no workflow webapp, we take care of publishing in
* ProjectUpdater.deployCloudWar().
*/
@Override
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
IProject webProject = getWebProject();
boolean isClientWf = false;
if (// not
webProject == null && moduleTree[0].getProject() != null)
// framework
isClientWf = WorkflowProjectManager.getInstance().getWorkflowProject(moduleTree[0].getProject()) != null;
if (// nothing to publish -- just refresh
isClientWf) {
// refresh the project's deploy folder after full publish
WorkflowProject project = getProject();
if (project != null)
project.getDeployFolder().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
} else {
IPath publishPath = getModuleDeployDirectory(moduleTree[0]);
if (moduleTree.length > 1 && !"jst.web".equals(moduleTree[1].getModuleType().getId()))
// non-web
publishPath = publishPath.append("WEB-INF/classes");
// child
// module
File publishDir = publishPath.toFile();
// passes
if (moduleTree.length == 1 && kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
if (publishPath != null && publishDir.exists())
showError(PublishHelper.deleteDirectory(publishDir, monitor));
if (deltaKind == ServerBehaviourDelegate.REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
return;
}
} else if (!publishDir.exists() && !publishDir.mkdirs()) {
PluginMessages.log("Error creating directory: " + publishDir);
showError("Error creating directory: " + publishDir, "Server Deploy", getProject());
return;
}
PublishHelper publishHelper = new PublishHelper(null);
if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) {
if (// publish everything in top level
moduleTree.length == 1) // module to prevent overwriting by submodules
{
// referenced projects first so that main module overrides any conflicts
IModule[] submods = getTomcatServer().getChildModules(moduleTree);
for (IModule submod : submods) {
if ("mdw-web".equals(submod.getName()) || "mdw-taskmgr".equals(submod.getName()))
continue;
IModuleResource[] mrs = getResources(new IModule[] { submod });
IPath submodPath = publishPath;
if (!"jst.web".equals(submod.getModuleType().getId()))
submodPath = submodPath.append("WEB-INF/classes");
// deployment assembly designates
IStatus[] statuses = publishHelper.publishFull(mrs, submodPath, monitor);
if (showError(statuses))
return;
monitor.worked(2000 / submods.length);
}
// main module publish
IModuleResource[] mrs = getResources(moduleTree);
IStatus[] statuses = publishHelper.publishFull(mrs, publishPath, monitor);
if (showError(statuses))
return;
monitor.worked(1000);
// wtp components cover deps)
try {
OsgiBuildFile buildFile = new GradleBuildFile(moduleTree[0].getProject());
if (!buildFile.exists())
// fall
buildFile = new MavenBuildFile(moduleTree[0].getProject());
// back
// to
// pom.xml
buildFile.parse();
if (!buildFile.exists()) {
PluginMessages.log("neither build.gradle nor pom.xml was found");
// can happen when project deleted from
return;
// workspace
}
String archiveName = buildFile.getArtifactName();
if (archiveName.startsWith("mdw-hub-") || archiveName.startsWith("mdwhub-")) {
// first delete conflicting jsf dependencies
File toDelete = publishPath.append("WEB-INF/lib/mdwweb-" + buildFile.getVersion() + ".jar").toFile();
if (toDelete.exists() && !toDelete.delete())
throw new IOException("Unable to delete file: " + toDelete);
archiveName = "mdw-" + buildFile.getVersion() + ".war";
}
if (!archiveName.endsWith(".war"))
archiveName += ".war";
File archive;
if (// relative
buildFile.getArtifactGenDir().startsWith(".."))
// path
// one
// level
// too
// high
archive = new File(moduleTree[0].getProject().getLocation().toFile().toString() + buildFile.getArtifactGenDir().substring(2) + "/" + archiveName);
else
archive = new File(moduleTree[0].getProject().getLocation().toFile().toString() + "/" + buildFile.getArtifactGenDir() + "/" + archiveName);
if (!archive.exists()) {
PluginMessages.log("Unable to locate web archive: " + archive);
showError("Unable to locate web archive: " + archive, "Server Deploy", getProject());
return;
}
copyWebInfLibArchiveEntriesToDir(archive, publishDir);
// refresh the project's deploy folder after full publish
WorkflowProject project = getProject();
if (project != null)
project.getDeployFolder().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
} catch (OperationCanceledException ex) {
// do nothing
} catch (Exception ex) {
PluginMessages.log(ex);
showError(ex.toString(), "Server Publish", getProject());
}
}
} else {
IModuleResourceDelta[] deltas = getPublishedResourceDelta(moduleTree);
IStatus[] statuses = publishHelper.publishDelta(deltas, publishPath, monitor);
if (showError(statuses))
return;
}
}
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
}
Aggregations