use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandConsoleFactory 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();
}
Aggregations