Search in sources :

Example 6 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class FrontendActionTest method testrunMultipleActions_ignored_failure_multiple.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple actions, a single action</li>
 *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure (escape key pressed)</li>
 *   <li>Check to make sure the failure event is never fired</li>
 * </ol>
 */
@Test
public void testrunMultipleActions_ignored_failure_multiple() {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    parameters.add(new ActionParametersBase());
    testState = null;
    frontend.runMultipleAction(ActionType.AddLocalStorageDomain, parameters, false, mockMultipleActionCallback, testState);
    verify(mockService).runMultipleActions(eq(ActionType.AddLocalStorageDomain), eq(parameters), eq(false), eq(false), callbackMultipleActions.capture());
    // $NON-NLS-1$
    StatusCodeException exception = new StatusCodeException(0, "0 status code");
    callbackMultipleActions.getValue().onFailure(exception);
    verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
    verify(mockMultipleActionCallback, never()).executed(callbackMultipleParam.capture());
    verifyAsyncActionStartedButNotCompleted();
}
Also used : ArrayList(java.util.ArrayList) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 7 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class FrontendActionTest method testrunMultipleActions_multipleaction_success_all.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run MultipleActions with multiple actions, that are successful.</li>
 *   <li>Check to make sure the callback is called</li>
 * </ol>
 */
@Test
public void testrunMultipleActions_multipleaction_success_all() {
    List<ActionType> actionTypes = new ArrayList<>();
    actionTypes.add(ActionType.AddDisk);
    actionTypes.add(ActionType.AddBricksToGlusterVolume);
    List<ActionParametersBase> testParameters = new ArrayList<>();
    testParameters.add(new ActionParametersBase());
    testParameters.add(new ActionParametersBase());
    List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    callbacks.add(mockActionCallback);
    callbacks.add(mockActionCallback);
    frontend.runMultipleActions(actionTypes, testParameters, callbacks, mockActionFailureCallback, testState);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters.get(0)), callbackAction.capture());
    ActionReturnValue returnValue = new ActionReturnValue();
    returnValue.setValid(true);
    returnValue.setSucceeded(true);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionCallback).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    // Second call to runAction, the size of the parameters should have decreased
    verify(mockService).runAction(eq(ActionType.AddBricksToGlusterVolume), eq(testParameters.get(0)), callbackAction.capture());
    returnValue = new ActionReturnValue();
    returnValue.setValid(true);
    returnValue.setSucceeded(true);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionCallback, times(2)).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 8 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase 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 9 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class FrontendActionTest method testrunMultipleActions_multipleaction_success_first_failure_second_success.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run MultipleActions with multiple actions, first failure, and second success.</li>
 *   <li>Check to make sure the failure callback is called for the first action</li>
 *   <li>Make sure the success callback is never called for the second action</li>
 * </ol>
 */
@Test
public void testrunMultipleActions_multipleaction_success_first_failure_second_success() {
    List<ActionType> actionTypes = new ArrayList<>();
    actionTypes.add(ActionType.AddDisk);
    actionTypes.add(ActionType.AddBricksToGlusterVolume);
    List<ActionParametersBase> testParameters = new ArrayList<>();
    testParameters.add(new ActionParametersBase());
    testParameters.add(new ActionParametersBase());
    List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    callbacks.add(mockActionCallback);
    callbacks.add(mockActionCallback);
    frontend.runMultipleActions(actionTypes, testParameters, callbacks, mockActionFailureCallback, testState);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters.get(0)), callbackAction.capture());
    ActionReturnValue returnValue = new ActionReturnValue();
    returnValue.setValid(false);
    returnValue.setSucceeded(false);
    callbackAction.getValue().onSuccess(returnValue);
    verify(mockActionFailureCallback).executed(callbackParam.capture());
    assertEquals(returnValue, callbackParam.getValue().getReturnValue());
    // Second call to runAction, the size of the parameters should have decreased
    verify(mockService, never()).runAction(eq(ActionType.AddBricksToGlusterVolume), eq(testParameters.get(0)), callbackAction.capture());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 10 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase 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)

Aggregations

ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)204 ArrayList (java.util.ArrayList)149 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)53 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)52 ActionType (org.ovirt.engine.core.common.action.ActionType)45 Test (org.junit.Test)44 Guid (org.ovirt.engine.core.compat.Guid)35 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 List (java.util.List)23 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)23 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)20 VM (org.ovirt.engine.core.common.businessentities.VM)19 QueryType (org.ovirt.engine.core.common.queries.QueryType)18 Frontend (org.ovirt.engine.ui.frontend.Frontend)18 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)18 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)18 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)16 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)16 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)15