Search in sources :

Example 1 with ActionParametersBase

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

the class FrontendActionTest method testrunMultipleActionsMultipleSuccess_multipleFailure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple actions, with multiple actions</li>
 *   <li>Have several of them fail. The rest is successful</li>
 *   <li>Check to make sure the failure event is never fired</li>
 * </ol>
 */
@SuppressWarnings("unchecked")
@Test
public void testrunMultipleActionsMultipleSuccess_multipleFailure() {
    // Don't immediately call process until all queries are in the queue.
    fakeScheduler.setThreshold(4);
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    parameters.add(new ActionParametersBase());
    parameters.add(new ActionParametersBase());
    parameters.add(new ActionParametersBase());
    parameters.add(new ActionParametersBase());
    parameters.get(0).setCommandId(Guid.Empty);
    parameters.get(1).setCommandId(Guid.EVERYONE);
    parameters.get(2).setCommandId(Guid.SYSTEM);
    frontend.runMultipleAction(ActionType.AddLocalStorageDomain, parameters, false, mockMultipleActionCallback, testState);
    verify(mockService).runMultipleActions(eq(ActionType.AddLocalStorageDomain), eq(parameters), eq(false), eq(false), callbackMultipleActions.capture());
    ArrayList<ActionReturnValue> returnValues = new ArrayList<>();
    returnValues.add(new ActionReturnValue());
    returnValues.add(new ActionReturnValue());
    returnValues.add(new ActionReturnValue());
    returnValues.add(new ActionReturnValue());
    returnValues.get(0).setValid(true);
    returnValues.get(1).setValid(false);
    returnValues.get(2).setValid(true);
    returnValues.get(3).setValid(false);
    callbackMultipleActions.getValue().onSuccess(returnValues);
    verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
    @SuppressWarnings("rawtypes") ArgumentCaptor<ArrayList> failedCaptor = ArgumentCaptor.forClass(ArrayList.class);
    verify(mockEventsHandler).runMultipleActionFailed(eq(ActionType.AddLocalStorageDomain), failedCaptor.capture());
    // $NON-NLS-1$
    assertEquals("There are two failures", 2, failedCaptor.getValue().size());
    // $NON-NLS-1$
    assertEquals("Failures should match", returnValues.get(1), failedCaptor.getValue().get(0));
    // $NON-NLS-1$
    assertEquals("Failures should match", returnValues.get(3), failedCaptor.getValue().get(1));
    verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture());
    assertEquals(// $NON-NLS-1$
    "Parameters should match", // $NON-NLS-1$
    parameters, callbackMultipleParam.getValue().getParameters());
    assertEquals(// $NON-NLS-1$
    "Result should match", // $NON-NLS-1$
    returnValues, callbackMultipleParam.getValue().getReturnValue());
    // $NON-NLS-1$
    assertEquals("States should match", testState, callbackMultipleParam.getValue().getState());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 2 with ActionParametersBase

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

the class FrontendActionTest method testrunActionImpl_success.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a single action</li>
 *   <li>Return success.</li>
 *   <li>Check to make sure the callback is called</li>
 * </ol>
 */
@Test
public void testrunActionImpl_success() {
    ActionParametersBase testParameters = new ActionParametersBase();
    frontend.runAction(ActionType.AddDisk, testParameters, mockActionCallback, testState, false);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), callbackAction.capture());
    ActionReturnValue returnValue = new ActionReturnValue();
    callbackAction.getValue().onSuccess(returnValue);
    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());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 3 with ActionParametersBase

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

the class FrontendActionTest method testrunActionImpl_ignored_failure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a single action</li>
 *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure</li>
 *   <li>Check to make sure the failure event is never fired</li>
 *   <li>Check to make sure the callback is never called</li>
 * </ol>
 */
@Test
public void testrunActionImpl_ignored_failure() {
    ActionParametersBase testParameters = new ActionParametersBase();
    frontend.runAction(ActionType.AddDisk, testParameters, mockActionCallback, testState, false);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), callbackAction.capture());
    // $NON-NLS-1$
    StatusCodeException exception = new StatusCodeException(0, "0 status code");
    callbackAction.getValue().onFailure(exception);
    verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
    verify(mockActionCallback, never()).executed(any());
    verifyAsyncActionStartedButNotCompleted();
}
Also used : StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 4 with ActionParametersBase

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

the class FrontendActionTest method testrunMultipleActionsMultipleSuccess_oneFailure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple actions, with multiple actions</li>
 *   <li>Have one of them fail. The rest is successful</li>
 *   <li>Check to make sure the failure event is never fired</li>
 * </ol>
 */
@SuppressWarnings("unchecked")
@Test
public void testrunMultipleActionsMultipleSuccess_oneFailure() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    parameters.add(new ActionParametersBase());
    parameters.add(new ActionParametersBase());
    parameters.get(0).setCommandId(Guid.Empty);
    frontend.runMultipleAction(ActionType.AddLocalStorageDomain, parameters, false, mockMultipleActionCallback, testState);
    verify(mockService).runMultipleActions(eq(ActionType.AddLocalStorageDomain), eq(parameters), eq(false), eq(false), callbackMultipleActions.capture());
    ArrayList<ActionReturnValue> returnValues = new ArrayList<>();
    returnValues.add(new ActionReturnValue());
    returnValues.add(new ActionReturnValue());
    returnValues.get(0).setValid(true);
    returnValues.get(1).setValid(false);
    callbackMultipleActions.getValue().onSuccess(returnValues);
    verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
    @SuppressWarnings("rawtypes") ArgumentCaptor<ArrayList> failedCaptor = ArgumentCaptor.forClass(ArrayList.class);
    verify(mockEventsHandler).runMultipleActionFailed(eq(ActionType.AddLocalStorageDomain), failedCaptor.capture());
    // $NON-NLS-1$
    assertEquals("There is one failure", 1, failedCaptor.getValue().size());
    // $NON-NLS-1$
    assertEquals("Failures should match", returnValues.get(1), failedCaptor.getValue().get(0));
    verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture());
    assertEquals(// $NON-NLS-1$
    "Parameters should match", // $NON-NLS-1$
    parameters, callbackMultipleParam.getValue().getParameters());
    assertEquals(// $NON-NLS-1$
    "Result should match", // $NON-NLS-1$
    returnValues, callbackMultipleParam.getValue().getReturnValue());
    // $NON-NLS-1$
    assertEquals("States should match", testState, callbackMultipleParam.getValue().getState());
    verifyAsyncActionStartedAndSucceeded();
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Example 5 with ActionParametersBase

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

the class FrontendActionTest method testrunActionImpl_404_failure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a single action</li>
 *   <li>Force a failure with an HTTP status code = 404</li>
 *   <li>Check to make sure the failure event is fired</li>
 *   <li>Check to make sure the callback is called</li>
 * </ol>
 */
@Test
public void testrunActionImpl_404_failure() {
    ActionParametersBase testParameters = new ActionParametersBase();
    frontend.runAction(ActionType.AddDisk, testParameters, mockActionCallback, testState, false);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), callbackAction.capture());
    StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, // $NON-NLS-1$
    "404 status code");
    callbackAction.getValue().onFailure(exception);
    verify(mockFrontendFailureEvent).raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
    verify(mockActionCallback).executed(callbackParam.capture());
    // $NON-NLS-1$
    assertEquals("Parameters should match", testParameters, callbackParam.getValue().getParameters());
    // $NON-NLS-1$
    assertNull("Result should be null", 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());
    verifyAsyncActionStartedAndFailed();
}
Also used : StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) 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