Search in sources :

Example 36 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class PropertyEditorPresenter method editProperty.

private void editProperty(Project project) {
    final String propertyName = view.getSelectedProperty();
    final Depth depth = view.getDepth();
    final String propertyValue = view.getPropertyValue();
    final boolean force = view.isForceSelected();
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    checkState(resources.length == 1);
    final StatusNotification notification = new StatusNotification(constants.propertyModifyStart(), PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    service.propertySet(project.getLocation(), propertyName, propertyValue, depth, force, toRelative(project, resources[0])).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandProperty());
            notification.setTitle(constants.propertyModifyFinished());
            notification.setStatus(SUCCESS);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notification.setTitle(constants.propertyModifyFailed());
            notification.setStatus(FAIL);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Depth(org.eclipse.che.plugin.svn.shared.Depth) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 37 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError 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 38 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError 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 39 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class DeleteResourceManager method onConfirm.

private ConfirmCallback onConfirm(final Resource[] resources, final AsyncCallback<Void> callback) {
    return new ConfirmCallback() {

        @Override
        public void accepted() {
            if (resources == null) {
                //sometimes we may occur NPE here while reading length
                callback.onFailure(new IllegalStateException());
                return;
            }
            Promise<?>[] deleteAll = new Promise<?>[resources.length];
            for (int i = 0; i < resources.length; i++) {
                final Resource resource = resources[i];
                deleteAll[i] = resource.delete().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify("Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
                    }
                });
            }
            promiseProvider.all(deleteAll).then(new Operation<JsArrayMixed>() {

                @Override
                public void apply(JsArrayMixed arg) throws OperationException {
                    callback.onSuccess(null);
                }
            });
        }
    };
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 40 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class DebuggerTest method testAttachDebugger.

@Test
public void testAttachDebugger() throws Exception {
    debugger.setDebugSession(null);
    final String debugSessionJson = "debugSession";
    doReturn(debugSessionJson).when(dtoFactory).toJson(debugSessionDto);
    doReturn(mock(StartActionDto.class)).when(dtoFactory).createDto(StartActionDto.class);
    Map<String, String> connectionProperties = mock(Map.class);
    Promise<DebugSessionDto> promiseDebuggerInfo = mock(Promise.class);
    doReturn(promiseDebuggerInfo).when(service).connect("id", connectionProperties);
    doReturn(promiseVoid).when(promiseDebuggerInfo).then((Function<DebugSessionDto, Void>) any());
    doReturn(promiseVoid).when(promiseVoid).catchError((Operation<PromiseError>) any());
    Promise<Void> result = debugger.connect(connectionProperties);
    assertEquals(promiseVoid, result);
    verify(promiseDebuggerInfo).then(argumentCaptorFunctionJavaDebugSessionVoid.capture());
    argumentCaptorFunctionJavaDebugSessionVoid.getValue().apply(debugSessionDto);
    verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
    try {
        operationPromiseErrorCaptor.getValue().apply(promiseError);
        fail("Operation Exception expected");
    } catch (OperationException e) {
        verify(promiseError).getMessage();
        verify(promiseError).getCause();
    }
    verify(observer).onDebuggerAttached(debuggerDescriptor, promiseVoid);
    assertTrue(debugger.isConnected());
    verify(localStorage).setItem(eq(AbstractDebugger.LOCAL_STORAGE_DEBUGGER_SESSION_KEY), eq(debugSessionJson));
    verify(messageBus).subscribe(eq("id:events:"), any(SubscriptionHandler.class));
}
Also used : SubscriptionHandler(org.eclipse.che.ide.websocket.rest.SubscriptionHandler) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) Matchers.anyString(org.mockito.Matchers.anyString) StartActionDto(org.eclipse.che.api.debug.shared.dto.action.StartActionDto) OperationException(org.eclipse.che.api.promises.client.OperationException) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Aggregations

PromiseError (org.eclipse.che.api.promises.client.PromiseError)137 OperationException (org.eclipse.che.api.promises.client.OperationException)123 Operation (org.eclipse.che.api.promises.client.Operation)109 Project (org.eclipse.che.ide.api.resources.Project)48 Resource (org.eclipse.che.ide.api.resources.Resource)40 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)20 Promise (org.eclipse.che.api.promises.client.Promise)19 List (java.util.List)15 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)13 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 Path (org.eclipse.che.ide.resource.Path)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 DebuggerObserver (org.eclipse.che.ide.debug.DebuggerObserver)11 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 HashMap (java.util.HashMap)9 Function (org.eclipse.che.api.promises.client.Function)8 FunctionException (org.eclipse.che.api.promises.client.FunctionException)8