Search in sources :

Example 11 with DevMachine

use of org.eclipse.che.ide.api.machine.DevMachine in project che by eclipse.

the class NavigateToFilePresenterTest method setUp.

@Before
public void setUp() {
    DevMachine devMachine = mock(DevMachine.class);
    when(devMachine.getId()).thenReturn("id");
    when(appContext.getDevMachine()).thenReturn(devMachine);
    when(appContext.getWorkspaceRoot()).thenReturn(container);
    when(container.getFile(any(Path.class))).thenReturn(optFilePromise);
    when(messageBusProvider.getMachineMessageBus()).thenReturn(messageBus);
    presenter = new NavigateToFilePresenter(view, eventBus, dtoUnmarshallerFactory, messageBusProvider, appContext);
    presenter.onWsAgentStarted(wsAgentStateEvent);
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Before(org.junit.Before)

Example 12 with DevMachine

use of org.eclipse.che.ide.api.machine.DevMachine in project che by eclipse.

the class JsonRpcWebSocketAgentEventListener method internalInitialize.

private void internalInitialize() {
    DevMachine devMachine = appContext.getDevMachine();
    String devMachineId = devMachine.getId();
    String wsAgentWebSocketUrl = devMachine.getWsAgentWebSocketUrl();
    String wsAgentUrl = wsAgentWebSocketUrl.replaceFirst("(api)(/)(ws)", "websocket" + "$2" + ENDPOINT_ID);
    String execAgentUrl = devMachine.getExecAgentUrl();
    initializer.initialize("ws-agent", singletonMap("url", wsAgentUrl));
    initializer.initialize(devMachineId, singletonMap("url", execAgentUrl));
    for (MachineEntity machineEntity : appContext.getActiveRuntime().getMachines()) {
        if (!machineEntity.isDev()) {
            initializer.initialize(machineEntity.getId(), singletonMap("url", machineEntity.getExecAgentUrl()));
        }
    }
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) DevMachine(org.eclipse.che.ide.api.machine.DevMachine)

Example 13 with DevMachine

use of org.eclipse.che.ide.api.machine.DevMachine in project che by eclipse.

the class AddToIndexAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    checkState(resources != null);
    final DevMachine devMachine = appContext.getDevMachine();
    final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
    consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
    service.getStatus(devMachine, appContext.getRootProject().getLocation()).then(status -> {
        if (containsInSelected(status.getUntracked())) {
            presenter.showDialog();
        } else if (containsInSelected(status.getModified()) || containsInSelected(status.getMissing())) {
            addToIndex(console);
        } else {
            String message = resources.length > 1 ? constant.nothingAddToIndexMultiSelect() : constant.nothingAddToIndex();
            console.print(message);
            notificationManager.notify(message);
        }
    }).catchError(error -> {
        console.printError(constant.statusFailed());
        notificationManager.notify(constant.statusFailed(), FAIL, FLOAT_MODE);
    });
}
Also used : GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent) Inject(com.google.inject.Inject) GitServiceClient(org.eclipse.che.ide.api.git.GitServiceClient) FAIL(org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL) Resource(org.eclipse.che.ide.api.resources.Resource) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) AddToIndexPresenter(org.eclipse.che.ide.ext.git.client.add.AddToIndexPresenter) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) FontAwesome(org.eclipse.che.ide.FontAwesome) FLOAT_MODE(org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE) AppContext(org.eclipse.che.ide.api.app.AppContext) GitLocalizationConstant(org.eclipse.che.ide.ext.git.client.GitLocalizationConstant) GitOutputConsoleFactory(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsoleFactory) NotificationManager(org.eclipse.che.ide.api.notification.NotificationManager) Singleton(com.google.inject.Singleton) ProcessesPanelPresenter(org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter) Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 14 with DevMachine

use of org.eclipse.che.ide.api.machine.DevMachine in project che by eclipse.

the class TestServiceClientTest method initMocks.

@Before
public void initMocks() {
    MockitoAnnotations.initMocks(this);
    testServiceClient = spy(new TestServiceClient(appContext, asyncRequestFactory, dtoUnmarshallerFactory, dtoFactory, commandManager, execAgentCommandManager, promiseProvider, macroProcessor, commandConsoleFactory, processesPanelPresenter));
    doReturn(new PromiseMocker<TestResult>().getPromise()).when(testServiceClient).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
    doAnswer(new FunctionAnswer<Executor.ExecutorBody<TestResult>, Promise<TestResult>>(executorBody -> {
        ExecutorPromiseMocker<TestResult> mocker = new ExecutorPromiseMocker<TestResult>(executorBody, (testResult, thisMocker) -> {
            thisMocker.applyOnThenOperation(testResult);
            return null;
        }, (promiseError, thisMocker) -> {
            thisMocker.applyOnCatchErrorOperation(promiseError);
            return null;
        });
        executorBody.apply(mocker.getResolveFunction(), mocker.getRejectFunction());
        return mocker.getPromise();
    })).when(testServiceClient).promiseFromExecutorBody(Matchers.<Executor.ExecutorBody<TestResult>>any());
    doAnswer(new FunctionAnswer<Throwable, PromiseError>(throwable -> {
        PromiseError promiseError = mock(PromiseError.class);
        when(promiseError.getCause()).thenReturn(throwable);
        return promiseError;
    })).when(testServiceClient).promiseFromThrowable(any(Throwable.class));
    when(appContext.getDevMachine()).thenReturn(devMachine);
    when(machine.getId()).thenReturn("DevMachineId");
    doAnswer(new FunctionAnswer<String, Promise<String>>(commandLine -> {
        String processedCommandLine = commandLine.replace("${current.project.path}", rootOfProjects + "/" + projectPath);
        return new PromiseMocker<String>().applyOnThenOperation(processedCommandLine).getPromise();
    })).when(macroProcessor).expandMacros(anyString());
    when(commandConsoleFactory.create(any(CommandImpl.class), any(Machine.class))).then(createCall -> {
        CommandOutputConsole commandOutputConsole = mock(CommandOutputConsole.class);
        when(commandOutputConsole.getProcessStartedOperation()).thenReturn(processStartedEvent -> {
            consoleEvents.add(processStartedEvent);
        });
        when(commandOutputConsole.getProcessDiedOperation()).thenReturn(processDiedEvent -> {
            consoleEvents.add(processDiedEvent);
        });
        when(commandOutputConsole.getStdErrOperation()).thenReturn(processStdErrEvent -> {
            consoleEvents.add(processStdErrEvent);
        });
        when(commandOutputConsole.getStdOutOperation()).thenReturn(processStdOutEvent -> {
            consoleEvents.add(processStdOutEvent);
        });
        return commandOutputConsole;
    });
    consoleEvents.clear();
    when(execAgentCommandManager.startProcess(anyString(), any(Command.class))).then(startProcessCall -> {
        @SuppressWarnings("unchecked") ExecAgentPromise<ProcessStartResponseDto> execAgentPromise = (ExecAgentPromise<ProcessStartResponseDto>) mock(ExecAgentPromise.class);
        class ProcessEventForward<DtoType> extends FunctionAnswer<Operation<DtoType>, ExecAgentPromise<ProcessStartResponseDto>> {

            public ProcessEventForward(Class<DtoType> dtoClass) {
                super(new java.util.function.Function<Operation<DtoType>, ExecAgentPromise<ProcessStartResponseDto>>() {

                    @Override
                    public ExecAgentPromise<ProcessStartResponseDto> apply(Operation<DtoType> op) {
                        operationsOnProcessEvents.put(dtoClass, op);
                        return execAgentPromise;
                    }
                });
            }
        }
        when(execAgentPromise.then(any())).then(new ProcessEventForward<>(ProcessStartResponseDto.class));
        when(execAgentPromise.thenIfProcessStartedEvent(any())).then(new ProcessEventForward<>(ProcessStartedEventDto.class));
        when(execAgentPromise.thenIfProcessDiedEvent(any())).then(new ProcessEventForward<>(ProcessDiedEventDto.class));
        when(execAgentPromise.thenIfProcessStdErrEvent(any())).then(new ProcessEventForward<>(ProcessStdErrEventDto.class));
        when(execAgentPromise.thenIfProcessStdOutEvent(any())).then(new ProcessEventForward<>(ProcessStdOutEventDto.class));
        return execAgentPromise;
    });
    operationsOnProcessEvents.clear();
}
Also used : Arrays(java.util.Arrays) AsyncRequestFactory(org.eclipse.che.ide.rest.AsyncRequestFactory) ProcessStartedEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStartedEventDto) Executor(org.eclipse.che.api.promises.client.js.Executor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) MockitoAnnotations(org.mockito.MockitoAnnotations) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) Mockito.doReturn(org.mockito.Mockito.doReturn) Operation(org.eclipse.che.api.promises.client.Operation) CommandConsoleFactory(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandConsoleFactory) DtoUnmarshallerFactory(org.eclipse.che.ide.rest.DtoUnmarshallerFactory) OperationException(org.eclipse.che.api.promises.client.OperationException) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Collectors(java.util.stream.Collectors) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ProcessStartResponseDto(org.eclipse.che.api.machine.shared.dto.execagent.ProcessStartResponseDto) Mockito.mock(org.mockito.Mockito.mock) Command(org.eclipse.che.api.core.model.machine.Command) ProcessStdOutEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStdOutEventDto) CommandManager(org.eclipse.che.ide.api.command.CommandManager) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ProcessDiedEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessDiedEventDto) ArrayList(java.util.ArrayList) Promise(org.eclipse.che.api.promises.client.Promise) Matchers.anyMapOf(org.mockito.Matchers.anyMapOf) ProcessStdErrEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStdErrEventDto) AppContext(org.eclipse.che.ide.api.app.AppContext) Before(org.junit.Before) DtoFactory(org.eclipse.che.ide.dto.DtoFactory) DtoWithPid(org.eclipse.che.api.machine.shared.dto.execagent.event.DtoWithPid) PromiseProvider(org.eclipse.che.api.promises.client.PromiseProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Machine(org.eclipse.che.api.core.model.machine.Machine) ExecAgentCommandManager(org.eclipse.che.ide.api.machine.ExecAgentCommandManager) Mockito.never(org.mockito.Mockito.never) ExecAgentPromise(org.eclipse.che.ide.api.machine.execagent.ExecAgentPromise) TestResult(org.eclipse.che.api.testing.shared.TestResult) Assert(org.junit.Assert) Collections(java.util.Collections) MacroProcessor(org.eclipse.che.ide.api.macro.MacroProcessor) ProcessesPanelPresenter(org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter) ProcessStdErrEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStdErrEventDto) Matchers.anyString(org.mockito.Matchers.anyString) Operation(org.eclipse.che.api.promises.client.Operation) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) ExecAgentPromise(org.eclipse.che.ide.api.machine.execagent.ExecAgentPromise) Executor(org.eclipse.che.api.promises.client.js.Executor) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) ProcessStdOutEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStdOutEventDto) CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) TestResult(org.eclipse.che.api.testing.shared.TestResult) ProcessDiedEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessDiedEventDto) ProcessStartResponseDto(org.eclipse.che.api.machine.shared.dto.execagent.ProcessStartResponseDto) Promise(org.eclipse.che.api.promises.client.Promise) ExecAgentPromise(org.eclipse.che.ide.api.machine.execagent.ExecAgentPromise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Command(org.eclipse.che.api.core.model.machine.Command) ProcessStartedEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessStartedEventDto) Before(org.junit.Before)

Example 15 with DevMachine

use of org.eclipse.che.ide.api.machine.DevMachine in project che by eclipse.

the class RunCommandActionTest method actionShouldBePerformed.

@Test
public void actionShouldBePerformed() {
    when(event.getParameters()).thenReturn(Collections.singletonMap(NAME_PROPERTY, "MCI"));
    final DevMachine devMachine = mock(DevMachine.class);
    final Machine machine = mock(Machine.class);
    when(devMachine.getDescriptor()).thenReturn(machine);
    when(appContext.getDevMachine()).thenReturn(devMachine);
    action.actionPerformed(event);
    verify(commandManager).executeCommand(eq(command), any(Machine.class));
}
Also used : DevMachine(org.eclipse.che.ide.api.machine.DevMachine) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) Test(org.junit.Test)

Aggregations

DevMachine (org.eclipse.che.ide.api.machine.DevMachine)15 Operation (org.eclipse.che.api.promises.client.Operation)5 Before (org.junit.Before)5 OperationException (org.eclipse.che.api.promises.client.OperationException)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 Path (org.eclipse.che.ide.resource.Path)4 Test (org.junit.Test)4 List (java.util.List)3 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)2 Machine (org.eclipse.che.api.core.model.machine.Machine)2 AppContext (org.eclipse.che.ide.api.app.AppContext)2 ProcessesPanelPresenter (org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 Singleton (com.google.inject.Singleton)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1