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);
}
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()));
}
}
}
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);
});
}
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();
}
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));
}
Aggregations