Search in sources :

Example 6 with TestResult

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);
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) HashMap(java.util.HashMap) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) TestResult(org.eclipse.che.api.testing.shared.TestResult) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FileNode(org.eclipse.che.ide.resources.tree.FileNode) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with TestResult

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());
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TestResult(org.eclipse.che.api.testing.shared.TestResult) Matchers.anyString(org.mockito.Matchers.anyString) OperationException(org.eclipse.che.api.promises.client.OperationException) Test(org.junit.Test)

Example 8 with TestResult

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());
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TestResult(org.eclipse.che.api.testing.shared.TestResult) Matchers.anyString(org.mockito.Matchers.anyString) OperationException(org.eclipse.che.api.promises.client.OperationException) Test(org.junit.Test)

Example 9 with TestResult

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"));
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) DtoWithPid(org.eclipse.che.api.machine.shared.dto.execagent.event.DtoWithPid) ArrayList(java.util.ArrayList) TestResult(org.eclipse.che.api.testing.shared.TestResult) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with TestResult

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;
}
Also used : TestRunner(org.eclipse.che.api.testing.server.framework.TestRunner) TestResult(org.eclipse.che.api.testing.shared.TestResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

TestResult (org.eclipse.che.api.testing.shared.TestResult)18 OperationException (org.eclipse.che.api.promises.client.OperationException)9 PromiseError (org.eclipse.che.api.promises.client.PromiseError)9 Operation (org.eclipse.che.api.promises.client.Operation)7 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)5 CommandImpl (org.eclipse.che.ide.api.command.CommandImpl)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Failure (org.eclipse.che.api.testing.shared.Failure)4 Project (org.eclipse.che.ide.api.resources.Project)4 URLClassLoader (java.net.URLClassLoader)3 Test (org.junit.Test)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Map (java.util.Map)2 Machine (org.eclipse.che.api.core.model.machine.Machine)2 DtoWithPid (org.eclipse.che.api.machine.shared.dto.execagent.event.DtoWithPid)2 Promise (org.eclipse.che.api.promises.client.Promise)2