use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class OrionEditorPresenter method initializeEditor.
@Override
protected void initializeEditor(final EditorAgent.OpenEditorCallback callback) {
QuickAssistProcessor processor = configuration.getQuickAssistProcessor();
if (quickAssistantFactory != null && processor != null) {
quickAssistant = quickAssistantFactory.createQuickAssistant(this);
quickAssistant.setQuickAssistProcessor(processor);
}
editorInit = new OrionEditorInit(configuration, this.codeAssistantFactory, this.quickAssistant, this);
Promise<Void> initializerPromise = editorModule.getInitializerPromise();
initializerPromise.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
displayErrorPanel(constant.editorInitErrorMessage());
callback.onInitializationFailed();
}
}).thenPromise(new Function<Void, Promise<String>>() {
@Override
public Promise<String> apply(Void arg) throws FunctionException {
return documentStorage.getDocument(input.getFile());
}
}).then(new Operation<String>() {
@Override
public void apply(String content) throws OperationException {
createEditor(content);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
displayErrorPanel(constant.editorFileErrorMessage());
callback.onInitializationFailed();
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class RunTestXMLAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Project project = appContext.getRootProject();
Map<String, String> parameters = new HashMap<>();
parameters.put("updateClasspath", "true");
parameters.put("testngXML", project.getPath() + "/" + MavenAttributes.DEFAULT_TEST_RESOURCES_FOLDER + "/testng.xml");
Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
presenter.handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class RunTestActionDelegate method doRunTests.
public void doRunTests(ActionEvent e, Map<String, String> parameters) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
source.getNotificationManager().notify(notification);
final Project project = source.getAppContext().getRootProject();
parameters.put("updateClasspath", "true");
Promise<TestResult> testResultPromise = source.getService().getTestResult(project.getPath(), "junit", parameters, notification);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
source.getPresenter().handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class RunAllTestAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Project project = appContext.getRootProject();
Map<String, String> parameters = new HashMap<>();
parameters.put("updateClasspath", "true");
Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
presenter.handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.
the class RunClassTestAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
notificationManager.notify(notification);
final Project project = appContext.getRootProject();
EditorPartPresenter editorPart = editorAgent.getActiveEditor();
final VirtualFile file = editorPart.getEditorInput().getFile();
String fqn = JavaUtil.resolveFQN(file);
Map<String, String> parameters = new HashMap<>();
parameters.put("fqn", fqn);
parameters.put("runClass", "true");
parameters.put("updateClasspath", "true");
Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
testResultPromise.then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
notification.setStatus(SUCCESS);
if (result.isSuccess()) {
notification.setTitle("Test runner executed successfully");
notification.setContent("All tests are passed");
} else {
notification.setTitle("Test runner executed successfully with test failures.");
notification.setContent(result.getFailureCount() + " test(s) failed.\n");
}
presenter.handleResponse(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError exception) throws OperationException {
final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
notification.setContent(errorMessage);
notification.setStatus(FAIL);
}
});
}
Aggregations