use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class RunTestXMLAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Project project = appContext.getRootProject();
Map<String, String> parameters = new HashMap<>();
parameters.put("updateClasspath", "true");
parameters.put("testngXML", project.getPath() + "/" + MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml");
Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
presenter.handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class TestNGRunner method execute.
/**
* {@inheritDoc}
*/
@Override
public TestResult execute(Map<String, String> testParameters) throws Exception {
String projectAbsolutePath = testParameters.get("absoluteProjectPath");
String xmlPath = testParameters.get("testngXML");
boolean updateClasspath = Boolean.valueOf(testParameters.get("updateClasspath"));
boolean runClass = Boolean.valueOf(testParameters.get("runClass"));
String projectPath = testParameters.get("projectPath");
String projectType = "";
if (projectManager != null) {
projectType = projectManager.getProject(projectPath).getType();
}
TestClasspathProvider classpathProvider = classpathRegistry.getTestClasspathProvider(projectType);
projectClassLoader = classpathProvider.getClassLoader(projectAbsolutePath, projectPath, updateClasspath);
TestResult testResult;
if (runClass) {
String fqn = testParameters.get("fqn");
testResult = run(projectAbsolutePath, fqn);
} else {
if (xmlPath == null) {
testResult = runAll(projectAbsolutePath);
} else {
testResult = runTestXML(projectAbsolutePath, ResourcesPlugin.getPathToWorkspace() + xmlPath);
}
}
return testResult;
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class RunTestActionDelegate method doRunTests.
public void doRunTests(ActionEvent e, Map<String, String> parameters) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
source.getNotificationManager().notify(notification);
final Project project = source.getAppContext().getRootProject();
parameters.put("updateClasspath", "true");
Promise<TestResult> testResultPromise = source.getService().getTestResult(project.getPath(), "junit", parameters, notification);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
source.getPresenter().handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class JUnitTestRunner method run4xTestClasses.
private TestResult run4xTestClasses(Class<?>... classes) throws Exception {
ClassLoader classLoader = projectClassLoader;
Class<?> clsJUnitCore = Class.forName("org.junit.runner.JUnitCore", true, classLoader);
Class<?> clsResult = Class.forName("org.junit.runner.Result", true, classLoader);
Class<?> clsFailure = Class.forName("org.junit.runner.notification.Failure", true, classLoader);
Class<?> clsDescription = Class.forName("org.junit.runner.Description", true, classLoader);
Class<?> clsThrowable = Class.forName("java.lang.Throwable", true, classLoader);
Class<?> clsStackTraceElement = Class.forName("java.lang.StackTraceElement", true, classLoader);
Class<?> clsTestRunner = Class.forName("org.junit.runner.notification.RunListener", true, classLoader);
Object jUnitCore = clsJUnitCore.getConstructor().newInstance();
Object result;
try (OutputTestListener outputListener = new OutputTestListener(this.getClass().getName() + ".run4xTestClasses")) {
Object testListener = create4xTestListener(classLoader, clsTestRunner, outputListener);
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(projectClassLoader);
clsJUnitCore.getMethod("addListener", clsTestRunner).invoke(jUnitCore, testListener);
result = clsJUnitCore.getMethod("run", Class[].class).invoke(jUnitCore, new Object[] { classes });
} finally {
Thread.currentThread().setContextClassLoader(tccl);
clsJUnitCore.getMethod("removeListener", clsTestRunner).invoke(jUnitCore, testListener);
}
}
TestResult dtoResult = DtoFactory.getInstance().createDto(TestResult.class);
boolean isSuccess = (Boolean) clsResult.getMethod("wasSuccessful").invoke(result);
List<?> failures = (List<?>) clsResult.getMethod("getFailures").invoke(result);
List<Failure> jUnitFailures = new ArrayList<>();
for (Object failure : failures) {
Failure dtoFailure = DtoFactory.getInstance().createDto(Failure.class);
String message = (String) clsFailure.getMethod("getMessage").invoke(failure);
Object description = clsFailure.getMethod("getDescription").invoke(failure);
String failClassName = (String) clsDescription.getMethod("getClassName").invoke(description);
Object exception = clsFailure.getMethod("getException").invoke(failure);
Object stackTrace = clsThrowable.getMethod("getStackTrace").invoke(exception);
String failMethod = "";
Integer failLine = null;
if (stackTrace.getClass().isArray()) {
int length = Array.getLength(stackTrace);
for (int i = 0; i < length; i++) {
Object stackElement = Array.get(stackTrace, i);
String failClass = (String) clsStackTraceElement.getMethod("getClassName").invoke(stackElement);
if (failClass.equals(failClassName)) {
failMethod = (String) clsStackTraceElement.getMethod("getMethodName").invoke(stackElement);
failLine = (Integer) clsStackTraceElement.getMethod("getLineNumber").invoke(stackElement);
break;
}
}
}
String trace = (String) clsFailure.getMethod("getTrace").invoke(failure);
dtoFailure.setFailingClass(failClassName);
dtoFailure.setFailingMethod(failMethod);
dtoFailure.setFailingLine(failLine);
dtoFailure.setMessage(message);
dtoFailure.setTrace(trace);
jUnitFailures.add(dtoFailure);
}
dtoResult.setTestFramework("JUnit4x");
dtoResult.setSuccess(isSuccess);
dtoResult.setFailureCount(jUnitFailures.size());
dtoResult.setFailures(jUnitFailures);
return dtoResult;
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class RunAllTestAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Project project = appContext.getRootProject();
Map<String, String> parameters = new HashMap<>();
parameters.put("updateClasspath", "true");
Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
presenter.handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
Aggregations