use of org.eclipse.che.api.promises.client.Operation 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.api.promises.client.Operation in project che by eclipse.
the class DebugConfigurationsManagerImplTest method testShouldApplyNewConfiguration.
@Test
public void testShouldApplyNewConfiguration() throws Exception {
final String debugId = "debug";
final String host = "localhost";
final int port = 9000;
when(debugConfiguration.getConnectionProperties()).thenReturn(ImmutableMap.of("prop", "value"));
when(debugConfigurationType.getId()).thenReturn(debugId);
when(debugConfiguration.getHost()).thenReturn(host);
when(debugConfiguration.getPort()).thenReturn(port);
when(debugConfiguration.getType()).thenReturn(debugConfigurationType);
when(debuggerManager.getDebugger(debugId)).thenReturn(debugger);
when(debugger.connect(anyMap())).thenReturn(mock(Promise.class));
when(currentProjectPathMacro.expand()).thenReturn(mock(Promise.class));
when(currentProjectPathMacro.getName()).thenReturn("key");
debugConfigurationsManager.apply(debugConfiguration);
ArgumentCaptor<Operation> operationArgumentCaptor = ArgumentCaptor.forClass(Operation.class);
verify(currentProjectPathMacro.expand()).then(operationArgumentCaptor.capture());
operationArgumentCaptor.getValue().apply("project path");
verify(debuggerManager).setActiveDebugger(debugger);
ArgumentCaptor<Map> properties = ArgumentCaptor.forClass(Map.class);
verify(debugger).connect(properties.capture());
Map<String, String> m = properties.getValue();
assertEquals(m.get("HOST"), host);
assertEquals(m.get("PORT"), String.valueOf(port));
assertEquals(m.get("prop"), "value");
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class AbstractDebugger method addBreakpoint.
@Override
public void addBreakpoint(final VirtualFile file, final int lineNumber) {
if (isConnected()) {
String fqn = pathToFqn(file);
if (fqn == null) {
return;
}
final String filePath = file.getLocation().toString();
LocationDto locationDto = dtoFactory.createDto(LocationDto.class).withLineNumber(lineNumber + 1).withTarget(fqn).withResourcePath(filePath).withResourceProjectPath(getProject(file).getPath());
BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class).withLocation(locationDto).withEnabled(true);
Promise<Void> promise = service.addBreakpoint(debugSessionDto.getId(), breakpointDto);
promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, filePath, file, true);
for (DebuggerObserver observer : observers) {
observer.onBreakpointAdded(breakpoint);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(AbstractDebugger.class, arg.getMessage());
}
});
} else {
Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false);
for (DebuggerObserver observer : observers) {
observer.onBreakpointAdded(breakpoint);
}
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class AbstractDebugger method setValue.
@Override
public void setValue(final Variable variable) {
if (isConnected()) {
Promise<Void> promise = service.setValue(debugSessionDto.getId(), asDto(variable));
promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
for (DebuggerObserver observer : observers) {
observer.onValueChanged(variable.getVariablePath().getPath(), variable.getValue());
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(AbstractDebugger.class, arg.getMessage());
}
});
}
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class DebuggerPresenter method onDebuggerAttached.
@Override
public void onDebuggerAttached(final DebuggerDescriptor debuggerDescriptor, Promise<Void> connect) {
final String address = debuggerDescriptor.getAddress();
final StatusNotification notification = notificationManager.notify(constant.debuggerConnectingTitle(address), PROGRESS, FLOAT_MODE);
connect.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
DebuggerPresenter.this.debuggerDescriptor = debuggerDescriptor;
notification.setTitle(constant.debuggerConnectedTitle());
notification.setContent(constant.debuggerConnectedDescription(address));
notification.setStatus(SUCCESS);
showAndUpdateView();
showDebuggerPanel();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notification.setTitle(constant.failedToConnectToRemoteDebuggerDescription(address, arg.getMessage()));
notification.setStatus(FAIL);
notification.setDisplayMode(FLOAT_MODE);
}
});
}
Aggregations