Search in sources :

Example 1 with ActionType

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

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

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

the class GWTRPCCommunicationProviderTest method testGetOperationResult_One_of_Two.

@Test
public void testGetOperationResult_One_of_Two() {
    VdcOperation<ActionType, ActionParametersBase> testOperation1 = new VdcOperation<>(ActionType.ActivateVds, new ActionParametersBase(), null);
    VdcOperation<ActionType, ActionParametersBase> testOperation2 = new VdcOperation<>(ActionType.AddBookmark, new ActionParametersBase(), null);
    List<VdcOperation<?, ?>> testOperationList = new ArrayList<>();
    testOperationList.add(testOperation2);
    List<VdcOperation<?, ?>> allOperationList = new ArrayList<>();
    allOperationList.add(testOperation1);
    allOperationList.add(testOperation2);
    ActionReturnValue testResult1 = new ActionReturnValue();
    ActionReturnValue testResult2 = new ActionReturnValue();
    List<ActionReturnValue> allResults = new ArrayList<>();
    allResults.add(testResult1);
    allResults.add(testResult2);
    List<?> result = testProvider.getOperationResult(testOperationList, allOperationList, allResults);
    // $NON-NLS-1$
    assertEquals("Result should have one results", 1, result.size());
    // $NON-NLS-1$
    assertEquals("Result should match", testResult2, result.get(0));
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) 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 4 with ActionType

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

the class GWTRPCCommunicationProviderTest method testTransmitOperationAction_failure.

@Test
public void testTransmitOperationAction_failure() {
    ActionParametersBase testParameters = new ActionParametersBase();
    final List<VdcOperation<ActionType, ActionParametersBase>> operationList = new ArrayList<>();
    // $NON-NLS-1$
    final Exception testException = new Exception("This is an exception");
    final VdcOperation<ActionType, ActionParametersBase> testOperation = new VdcOperation<>(ActionType.AddDisk, testParameters, new VdcOperationCallback<VdcOperation<ActionType, ActionParametersBase>, ActionReturnValue>() {

        @Override
        public void onSuccess(VdcOperation<ActionType, ActionParametersBase> operation, ActionReturnValue result) {
            // $NON-NLS-1$
            fail("Should not get here");
        }

        @Override
        public void onFailure(VdcOperation<ActionType, ActionParametersBase> operation, Throwable exception) {
            // $NON-NLS-1$
            assertEquals("Operations should match", operationList.get(0), operation);
            // $NON-NLS-1$
            assertEquals("Exceptions should match", testException, exception);
        }
    });
    operationList.add(testOperation);
    testProvider.transmitOperation(testOperation);
    verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), actionCallback.capture());
    actionCallback.getValue().onFailure(testException);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) 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 ActionType

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

the class GWTRPCCommunicationProviderTest method testTransmitOperationList_oneAction_success.

@Test
public void testTransmitOperationList_oneAction_success() {
    final ActionReturnValue testResult = new ActionReturnValue();
    List<VdcOperation<?, ?>> testList = new ArrayList<>();
    ActionParametersBase testParameters = new ActionParametersBase();
    VdcOperation<ActionType, ActionParametersBase> testOperation1 = new VdcOperation<>(ActionType.ActivateVds, testParameters, mockOperationCallbackSingle1);
    testList.add(testOperation1);
    testProvider.transmitOperationList(testList);
    verify(mockService).runAction(eq(ActionType.ActivateVds), eq(testParameters), actionCallback.capture());
    actionCallback.getValue().onSuccess(testResult);
    verify(mockOperationCallbackSingle1).onSuccess(testOperation1, testResult);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) Test(org.junit.Test)

Aggregations

ActionType (org.ovirt.engine.core.common.action.ActionType)58 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)37 ArrayList (java.util.ArrayList)31 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)24 Test (org.junit.Test)23 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)16 Guid (org.ovirt.engine.core.compat.Guid)15 List (java.util.List)13 QueryType (org.ovirt.engine.core.common.queries.QueryType)11 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)11 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)11 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)10 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)10 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)9 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)9 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)9 Arrays (java.util.Arrays)7 HashSet (java.util.HashSet)7 Set (java.util.Set)7