use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class RunClassContextTestAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Selection<?> selection = selectionAgent.getSelection();
final Object possibleNode = selection.getHeadElement();
if (possibleNode instanceof FileNode) {
VirtualFile file = ((FileNode) possibleNode).getData();
final Project project = appContext.getRootProject();
String fqn = JavaUtil.resolveFQN(file);
Map<String, String> parameters = new HashMap<>();
parameters.put("fqn", fqn);
parameters.put("runClass", "true");
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);
}
});
}
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class TestServiceClientTest method cancelledTestsBecauseCompilationNotStarted.
@Test
public void cancelledTestsBecauseCompilationNotStarted() {
Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
when(devMachine.getDescriptor()).thenReturn(machine);
Promise<TestResult> result = testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
triggerProcessEvents(processStartResponse(false));
verify(testServiceClient, never()).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
verify(statusNotification).setContent("Compiling the project before starting the test session.");
result.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError promiseError) throws OperationException {
Throwable cause = promiseError.getCause();
Assert.assertNotNull(cause);
Assert.assertEquals(TestServiceClient.PROJECT_BUILD_NOT_STARTED_MESSAGE, cause.getMessage());
}
});
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class TestServiceClientTest method cancelledTestsBecauseCompilationFailed.
@Test
public void cancelledTestsBecauseCompilationFailed() {
Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
when(devMachine.getDescriptor()).thenReturn(machine);
Promise<TestResult> result = testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
triggerProcessEvents(processStartResponse(true), processStarted(), processStdErr("A small warning"), processStdOut("BUILD FAILURE"), processDied());
verify(testServiceClient, never()).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
verify(statusNotification).setContent("Compiling the project before starting the test session.");
result.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError promiseError) throws OperationException {
Throwable cause = promiseError.getCause();
Assert.assertNotNull(cause);
Assert.assertEquals(TestServiceClient.PROJECT_BUILD_FAILED_MESSAGE, cause.getMessage());
}
});
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class TestServiceClientTest method sucessfulTestsAfterCompilation.
@Test
public void sucessfulTestsAfterCompilation() {
Promise<CommandImpl> compileCommandPromise = createCommandPromise(new CommandImpl("test-compile", "mvn test-compile -f ${current.project.path}", "mvn"));
when(devMachine.getDescriptor()).thenReturn(machine);
Promise<TestResult> resultPromise = testServiceClient.runTestsAfterCompilation(projectPath, testFramework, parameters, statusNotification, compileCommandPromise);
triggerProcessEvents(processStartResponse(true), processStarted(), processStdErr("A small warning"), processStdOut("BUILD SUCCESS"), processDied());
verify(testServiceClient).sendTests(projectPath, testFramework, parameters);
verify(statusNotification).setContent("Compiling the project before starting the test session.");
verify(execAgentCommandManager).startProcess("DevMachineId", new CommandImpl("test-compile", "mvn test-compile -f " + rootOfProjects + "/" + projectPath, "mvn"));
verify(statusNotification).setContent(TestServiceClient.EXECUTING_TESTS_MESSAGE);
resultPromise.then(testResult -> {
Assert.assertNotNull(testResult);
});
ArrayList<String> eventStrings = new ArrayList<>();
for (DtoWithPid event : consoleEvents) {
eventStrings.add(event.toString());
}
Assert.assertEquals(eventStrings, Arrays.asList("Started", "StdErr - A small warning", "StdOut - BUILD SUCCESS", "Died"));
}
use of org.eclipse.che.api.testing.shared.TestResult in project che by eclipse.
the class TestingService method run.
/**
* Execute the Java test cases and return the test result.
*
* <pre>
* Required request parameters.
* <em>projectPath</em> : Relative path to the project directory.
* <em>testFramework</em> : Name of the test framework where the tests should be run on. This should match with
* the name returned by {@link TestRunner#getName()} implementation.
* </pre>
*
* @param uriInfo
* JAX-RS implementation of UrlInfo with set of query parameters.
* @return the test result of test case
* @throws Exception
* when the test runner failed to execute test cases.
*/
@GET
@Path("run")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Execute Java tests and return results", notes = "The GET parameters are passed to the test framework implementation.")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") })
public TestResult run(@Context UriInfo uriInfo) throws Exception {
Map<String, String> queryParameters = getMap(uriInfo.getQueryParameters());
String projectPath = queryParameters.get("projectPath");
String absoluteProjectPath = ResourcesPlugin.getPathToWorkspace() + projectPath;
queryParameters.put("absoluteProjectPath", absoluteProjectPath);
String testFramework = queryParameters.get("testFramework");
TestRunner runner = frameworkRegistry.getTestRunner(testFramework);
if (runner == null) {
throw new Exception("No test frameworks found: " + testFramework);
}
TestResult result = frameworkRegistry.getTestRunner(testFramework).execute(queryParameters);
return result;
}
Aggregations