use of org.ovirt.engine.core.common.errors.EngineFault in project ovirt-engine by oVirt.
the class FrontendActionTest method testHandleActionResult_isRaiseErrorModalPanel_withActionMessageSize1.
/**
* Run the following test case.
* <ol>
* <li>Run a single action</li>
* <li>Return logical failure, validate=false.</li>
* <li>isRaiseErrorModalPanel returns true.</li>
* <li>Check to make sure the failure event is fired</li>
* <li>Check to make sure the callback is called</li>
* </ol>
* Test just the handler method.
*/
@Test
public void testHandleActionResult_isRaiseErrorModalPanel_withActionMessageSize1() {
EngineFault testFault = new EngineFault();
// $NON-NLS-1$
ArrayList<String> translatedErrors = new ArrayList<>(Collections.singletonList("Translated Message 1"));
when(mockEventsHandler.isRaiseErrorModalPanel(ActionType.AddDisk, testFault)).thenReturn(true);
when(mockValidateErrorsTranslator.translateErrorText(any())).thenReturn(translatedErrors);
ActionParametersBase testParameters = new ActionParametersBase();
ActionReturnValue returnValue = new ActionReturnValue();
returnValue.setFault(testFault);
// $NON-NLS-1$
returnValue.setDescription("This is a description");
// $NON-NLS-1$
returnValue.getValidationMessages().add("Message 1");
// Yes this is the default, but to make sure.
returnValue.setValid(false);
frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, true);
verify(mockActionCallback).executed(callbackParam.capture());
// $NON-NLS-1$
assertEquals("Parameters should match", testParameters, callbackParam.getValue().getParameters());
// $NON-NLS-1$
assertEquals("Result should match", returnValue, callbackParam.getValue().getReturnValue());
// $NON-NLS-1$
assertEquals("States should match", testState, callbackParam.getValue().getState());
assertEquals(// $NON-NLS-1$
"Action type should match", // $NON-NLS-1$
ActionType.AddDisk, callbackParam.getValue().getActionType());
ArgumentCaptor<FrontendFailureEventArgs> failureCaptor = ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
verify(mockFrontendFailureEvent).raise(eq(Frontend.class), failureCaptor.capture());
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
"Descriptions should match", // $NON-NLS-1$ //$NON-NLS-2$
"This is a description", failureCaptor.getValue().getMessages().get(0).getDescription());
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
"Text should match translation", // $NON-NLS-1$ //$NON-NLS-2$
"Translated Message 1", failureCaptor.getValue().getMessages().get(0).getText());
}
use of org.ovirt.engine.core.common.errors.EngineFault in project ovirt-engine by oVirt.
the class FrontendActionTest method testHandleActionResult_isRaiseErrorModalPanel_actionMessageSize_1_or_less.
/**
* Run the following test case.
* <ol>
* <li>Run a single action</li>
* <li>Return logical failure, validate=false.</li>
* <li>isRaiseErrorModalPanel returns true.</li>
* <li>Check to make sure the failure event is fired</li>
* <li>Check to make sure the callback is called</li>
* </ol>
* Test just the handler method.
*/
@Test
public void testHandleActionResult_isRaiseErrorModalPanel_actionMessageSize_1_or_less() {
EngineFault testFault = new EngineFault();
when(mockEventsHandler.isRaiseErrorModalPanel(ActionType.AddDisk, testFault)).thenReturn(true);
ActionParametersBase testParameters = new ActionParametersBase();
ActionReturnValue returnValue = new ActionReturnValue();
returnValue.setFault(testFault);
// $NON-NLS-1$
returnValue.setDescription("This is a description");
// Yes this is the default, but to make sure.
returnValue.setValid(false);
frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, true);
verify(mockActionCallback).executed(callbackParam.capture());
// $NON-NLS-1$
assertEquals("Parameters should match", testParameters, callbackParam.getValue().getParameters());
// $NON-NLS-1$
assertEquals("Result should match", returnValue, callbackParam.getValue().getReturnValue());
// $NON-NLS-1$
assertEquals("States should match", testState, callbackParam.getValue().getState());
assertEquals(// $NON-NLS-1$
"Action type should match", // $NON-NLS-1$
ActionType.AddDisk, callbackParam.getValue().getActionType());
ArgumentCaptor<FrontendFailureEventArgs> failureCaptor = ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
verify(mockFrontendFailureEvent).raise(eq(Frontend.class), failureCaptor.capture());
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
"Descriptions should match", // $NON-NLS-1$ //$NON-NLS-2$
"This is a description", failureCaptor.getValue().getMessages().get(0).getDescription());
assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
"Text should match", // $NON-NLS-1$ //$NON-NLS-2$
NO_MESSAGE, failureCaptor.getValue().getMessages().get(0).getText());
}
use of org.ovirt.engine.core.common.errors.EngineFault in project ovirt-engine by oVirt.
the class FrontendActionTest method testHandleActionResult_SucceededFalse.
/**
* Run the following test case.
* <ol>
* <li>Run a single action</li>
* <li>Return logical failure, validate=true.</li>
* <li>Get succeeded is false.</li>
* <li>IsSyncronious is true.</li>
* <li>showDialog is true.</li>
* <li>Check to make sure the failure event is fired</li>
* <li>Check to make sure the callback is called</li>
* </ol>
* Test just the handler method.
*/
@Test
public void testHandleActionResult_SucceededFalse() {
ActionParametersBase testParameters = new ActionParametersBase();
ActionReturnValue returnValue = new ActionReturnValue();
returnValue.setValid(true);
returnValue.setIsSynchronous(true);
// Yes this is the default, but to make sure.
returnValue.setSucceeded(false);
EngineFault testFault = new EngineFault();
returnValue.setFault(testFault);
frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, true);
verify(mockActionCallback).executed(callbackParam.capture());
// $NON-NLS-1$
assertEquals("Parameters should match", testParameters, callbackParam.getValue().getParameters());
// $NON-NLS-1$
assertEquals("Result should match", returnValue, callbackParam.getValue().getReturnValue());
// $NON-NLS-1$
assertEquals("States should match", testState, callbackParam.getValue().getState());
assertEquals(// $NON-NLS-1$
"Action type should match", // $NON-NLS-1$
ActionType.AddDisk, callbackParam.getValue().getActionType());
verify(mockEventsHandler).runActionExecutionFailed(ActionType.AddDisk, testFault);
}
use of org.ovirt.engine.core.common.errors.EngineFault in project ovirt-engine by oVirt.
the class Frontend method handleActionResult.
/**
* Handle the result(s) of an action.
* @param actionType The action type.
* @param parameters The parameters of the action.
* @param result The result of the action.
* @param callback The callback to call.
* @param state The state before the action happened.
* @param showErrorDialog Should we show an error dialog?
*/
void handleActionResult(final ActionType actionType, final ActionParametersBase parameters, final ActionReturnValue result, final IFrontendActionAsyncCallback callback, final Object state, final boolean showErrorDialog) {
// $NON-NLS-1$
logger.log(Level.FINER, "Retrieved action result from RunAction.");
FrontendActionAsyncResult f = new FrontendActionAsyncResult(actionType, parameters, result, state);
boolean failedOnValidate = !result.isValid();
if (failedOnValidate) {
result.setValidationMessages((ArrayList<String>) translateError(result));
} else if (!result.getSucceeded()) {
EngineFault fault = result.getFault();
String message = result.getExecuteFailedMessages().size() > 1 ? translateExecuteFailedMessages(result.getExecuteFailedMessages()) : translateEngineFault(fault);
fault.setMessage(message);
if (showErrorDialog && result.getIsSynchronous() && getEventsHandler() != null) {
getEventsHandler().runActionExecutionFailed(actionType, fault);
}
}
callback.executed(f);
// only needed for validate failure
if (showErrorDialog && failedOnValidate && (getEventsHandler() != null) && getEventsHandler().isRaiseErrorModalPanel(actionType, result.getFault())) {
ArrayList<String> messages = result.getValidationMessages();
failureEventHandler(result.getDescription(), // $NON-NLS-1$
messages.isEmpty() ? Collections.singletonList(getConstants().noValidateMessage()) : messages);
}
}
use of org.ovirt.engine.core.common.errors.EngineFault in project ovirt-engine by oVirt.
the class AddStorageDomainCommand method executeCommand.
@Override
protected void executeCommand() {
initializeStorageDomain();
addStorageDomainInDb();
// check connection to storage
Pair<Boolean, Integer> connectReturnValue = connectStorage();
if (!connectReturnValue.getFirst()) {
EngineFault fault = new EngineFault();
fault.setError(EngineError.forValue(connectReturnValue.getSecond()));
getReturnValue().setFault(fault);
setSucceeded(false);
} else if (addStorageDomainInIrs()) {
updateStorageDomainDynamicFromIrs();
setSucceeded(true);
}
}
Aggregations