Search in sources :

Example 1 with EngineFault

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());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 2 with EngineFault

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());
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 3 with EngineFault

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);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 4 with EngineFault

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);
    }
}
Also used : FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) EngineFault(org.ovirt.engine.core.common.errors.EngineFault)

Example 5 with EngineFault

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);
    }
}
Also used : EngineFault(org.ovirt.engine.core.common.errors.EngineFault)

Aggregations

EngineFault (org.ovirt.engine.core.common.errors.EngineFault)20 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)6 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)6 Test (org.junit.Test)4 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)4 Pair (org.ovirt.engine.core.common.utils.Pair)3 ArrayList (java.util.ArrayList)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 StorageServerConnectionManagementVDSParameters (org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 Map (java.util.Map)1 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)1 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 LUNStorageServerConnectionMap (org.ovirt.engine.core.common.businessentities.storage.LUNStorageServerConnectionMap)1 Event (org.ovirt.engine.core.common.eventqueue.Event)1 EventResult (org.ovirt.engine.core.common.eventqueue.EventResult)1 DestroyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DestroyImageVDSCommandParameters)1