public static ActionReturnValue instantiate(SerializationStreamReader streamReader) throws SerializationException { return new ActionReturnValue(); }
/** * Log the user out. * @param callback The callback to call when the operation is complete. */ @Override public void logout(final UserCallback callback) { //Remove the rpc token when logging out. xsrfRequestBuilder.setXsrfToken(null); ActionReturnValue retVal = new ActionReturnValue(); retVal.setSucceeded(true); callback.onSuccess(retVal); } }
@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); }
@Test public void testGetOperationResult_One() { VdcOperation<ActionType, ActionParametersBase> testOperation1 = new VdcOperation<>(ActionType.ActivateVds, new ActionParametersBase(), null); List<VdcOperation<?, ?>> testOperationList = new ArrayList<>(); testOperationList.add(testOperation1); List<VdcOperation<?, ?>> allOperationList = new ArrayList<>(); allOperationList.add(testOperation1); ActionReturnValue testResult1 = new ActionReturnValue(); List<ActionReturnValue> allResults = new ArrayList<>(); allResults.add(testResult1); List<?> result = testProvider.getOperationResult(testOperationList, allOperationList, allResults); assertEquals(1, result.size(), "Result should have one results"); //$NON-NLS-1$ }
@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); assertEquals(1, result.size(), "Result should have one results"); //$NON-NLS-1$ assertEquals(testResult2, result.get(0), "Result should match"); //$NON-NLS-1$ }
@Test public void testTransmitOperationAction_success() { ActionParametersBase testParameters = new ActionParametersBase(); final ActionReturnValue testResult = new ActionReturnValue(); final List<VdcOperation<ActionType, ActionParametersBase>> operationList = new ArrayList<>(); 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) { assertEquals(testResult, result, "Test results should match"); //$NON-NLS-1$ assertEquals(operationList.get(0), operation, "Operations should match"); //$NON-NLS-1$ } @Override public void onFailure(VdcOperation<ActionType, ActionParametersBase> operation, Throwable caught) { fail("Should not get here"); //$NON-NLS-1$ } }); operationList.add(testOperation); testProvider.transmitOperation(testOperation); verify(mockService).runAction(eq(ActionType.AddDisk), eq(testParameters), actionCallback.capture()); actionCallback.getValue().onSuccess(testResult); }
@Test public void testTransmitOperationList_twoItems_success() { final ActionReturnValue testResult = new ActionReturnValue(); List<VdcOperation<?, ?>> testList = new ArrayList<>(); ActionParametersBase testParameters = new ActionParametersBase(); VdcOperation<ActionType, ActionParametersBase> testOperation1 = new VdcOperation<>(ActionType.ActivateVds, testParameters, mockOperationCallbackList1); VdcOperation<ActionType, ActionParametersBase> testOperation2 = new VdcOperation<>(ActionType.ActivateVds, testParameters, mockOperationCallbackList1); List<ActionParametersBase> testParameterList = createActionParameterList(testParameters, 2); List<ActionReturnValue> testResultList = createActionResultList(testResult, 2); testList.add(testOperation1); testList.add(testOperation2); testProvider.transmitOperationList(testList); verify(mockService).runMultipleActions(eq(ActionType.ActivateVds), (ArrayList<ActionParametersBase>) eq(testParameterList), eq(false), eq(true), actionCallbackList.capture()); actionCallbackList.getValue().onSuccess((ArrayList<ActionReturnValue>) testResultList); verify(mockOperationCallbackList1).onSuccess(eq(testList), eq(testResultList)); }
@Test public void testOnOperationAvailableMultiple_success_samecallback() { ActionParametersBase testParameter = new ActionParametersBase(); VdcOperation testOperation1 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback1); VdcOperation testOperation2 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback1); when(mockOperationManager.pollOperation()).thenReturn(testOperation1).thenReturn(testOperation2). thenReturn(null); testProcessor.processAvailableOperations(mockOperationManager); verify(mockProvider).transmitOperationList(operationListCaptor.capture()); assertNotEquals(operationListCaptor.getValue().get(0).getCallback(), mockCallbackList1, "The callbacks should NOT match"); //$NON-NLS-1$ assertNotEquals(operationListCaptor.getValue().get(1).getCallback(), mockCallbackList2, "The callbacks should NOT match"); //$NON-NLS-1$ ActionReturnValue result1 = new ActionReturnValue(); operationListCaptor.getValue().get(0).getCallback().onSuccess(operationListCaptor.getValue().get(0), result1); verify(mockCallback1).onSuccess(testOperation1, result1); verify(mockCallback2, never()).onSuccess(eq(testOperation2), any()); }
@Test public void testOnOperationAvailableMultiple_success() { ActionParametersBase testParameter = new ActionParametersBase(); VdcOperation testOperation1 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback1); VdcOperation testOperation2 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback2); when(mockOperationManager.pollOperation()).thenReturn(testOperation1).thenReturn(testOperation2). thenReturn(null); testProcessor.processAvailableOperations(mockOperationManager); verify(mockProvider).transmitOperationList(operationListCaptor.capture()); assertNotEquals(operationListCaptor.getValue().get(0).getCallback(), mockCallback1, "The callbacks should not match"); //$NON-NLS-1$ assertNotEquals(operationListCaptor.getValue().get(1).getCallback(), mockCallback2, "The callbacks should not match"); //$NON-NLS-1$ List<ActionReturnValue> resultList1 = new ArrayList<>(); List<ActionReturnValue> resultList2 = new ArrayList<>(); ActionReturnValue result1 = new ActionReturnValue(); ActionReturnValue result2 = new ActionReturnValue(); resultList1.add(result1); resultList2.add(result2); operationListCaptor.getValue().get(0).getCallback().onSuccess(operationListCaptor.getValue().get(0), resultList1); verify(mockCallback1).onSuccess(testOperation1, resultList1); operationListCaptor.getValue().get(1).getCallback().onSuccess(operationListCaptor.getValue().get(1), resultList2); verify(mockCallback2).onSuccess(testOperation2, resultList2); }
@Test public void testTransmitOperationList_query_and_action_success() { QueryParametersBase testQueryParameters = new QueryParametersBase(); ActionParametersBase testActionParameters = new ActionParametersBase(); VdcOperation<QueryType, QueryParametersBase> testOperation1 = new VdcOperation<>(QueryType.Search, testQueryParameters, mockOperationCallbackSingle1); VdcOperation<ActionType, ActionParametersBase> testOperation2 = new VdcOperation<>(ActionType.ActivateVds, testActionParameters, mockOperationCallbackSingle2); List<VdcOperation<?, ?>> operationList = new ArrayList<>(); operationList.add(testOperation1); operationList.add(testOperation2); testProvider.transmitOperationList(operationList); verify(mockService).runQuery(eq(QueryType.Search), eq(testQueryParameters), queryCallback.capture()); QueryReturnValue testQueryResult = new QueryReturnValue(); queryCallback.getValue().onSuccess(testQueryResult); verify(mockOperationCallbackSingle1).onSuccess(testOperation1, testQueryResult); ActionReturnValue testActionResult = new ActionReturnValue(); verify(mockService).runAction(eq(ActionType.ActivateVds), eq(testActionParameters), actionCallback.capture()); actionCallback.getValue().onSuccess(testActionResult); verify(mockOperationCallbackSingle2).onSuccess(testOperation2, testActionResult); }
@Test public void testOnOperationAvailableMultiple_success_with_retry() { ActionParametersBase testParameter = new ActionParametersBase(); VdcOperation testOperation1 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback1); // This is the 'retry'. testOperation1 = new VdcOperation(testOperation1, mockCallback3); VdcOperation testOperation2 = new VdcOperation(ActionType.AddEventSubscription, testParameter, mockCallback2); when(mockOperationManager.pollOperation()).thenReturn(testOperation1).thenReturn(testOperation2). thenReturn(null); testProcessor.processAvailableOperations(mockOperationManager); verify(mockProvider).transmitOperationList(operationListCaptor.capture()); assertNotEquals(operationListCaptor.getValue().get(0).getCallback(), mockCallbackList1, "The callbacks should NOT match"); //$NON-NLS-1$ assertNotEquals(operationListCaptor.getValue().get(1).getCallback(), mockCallbackList2, "The callbacks should NOT match"); //$NON-NLS-1$ List<ActionReturnValue> resultList = new ArrayList<>(); ActionReturnValue result1 = new ActionReturnValue(); ActionReturnValue result2 = new ActionReturnValue(); resultList.add(result1); resultList.add(result2); operationListCaptor.getValue().get(0).getCallback().onSuccess(operationListCaptor.getValue().get(0), result1); operationListCaptor.getValue().get(1).getCallback().onSuccess(operationListCaptor.getValue().get(1), result2); verify(mockCallback1).onSuccess(testOperation1, resultList.get(0)); verify(mockCallback2).onSuccess(testOperation2, resultList.get(1)); verify(mockCallback3, never()).onSuccess((VdcOperation) any(), any()); }
private void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendMultipleActionAsyncCallback> callbacks, boolean waitForResult) { Collections.shuffle(callbacks); for (IFrontendMultipleActionAsyncCallback callback : callbacks) { assertNotAllDone(flowState); ActionReturnValue result = new ActionReturnValue(); result.setValid(waitForResult || success); result.setSucceeded(waitForResult && success); callback.executed(new FrontendMultipleActionAsyncResult(ACTION_TYPE, null, Collections.singletonList(result))); } }
@Test public void testTransmitOperationList_threeItems_twoActionTypes_success() { final ActionReturnValue testResult = new ActionReturnValue(); List<VdcOperation<?, ?>> testList = new ArrayList<>(); List<VdcOperation<?, ?>> activateVdsList = new ArrayList<>();
/** * Run the following test case. * <ol> * <li>Run MultipleActions with a single action, that is successful.</li> * <li>Check to make sure the callback is called</li> * </ol> */ @Test public void testrunMultipleActions_1action() { List<ActionType> actionTypes = new ArrayList<>(); actionTypes.add(ActionType.AddDisk); List<ActionParametersBase> testParameters = new ArrayList<>(); testParameters.add(new ActionParametersBase()); List<IFrontendActionAsyncCallback> callbacks = new ArrayList<>(); 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()); assertEquals(0, actionTypes.size(), "List size should be 0"); //$NON-NLS-1$ assertEquals(0, testParameters.size(), "List size should be 0"); //$NON-NLS-1$ assertEquals(0, callbacks.size(), "List size should be 0"); //$NON-NLS-1$ verifyAsyncActionStartedAndSucceeded(); }
@Override protected void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendActionAsyncCallback> callbacks) { Collections.shuffle(callbacks); for (IFrontendActionAsyncCallback callback : callbacks) { assertNotAllDone(flowState); ActionReturnValue result = new ActionReturnValue(); result.setValid(true); result.setSucceeded(success); callback.executed(new FrontendActionAsyncResult(ACTION_TYPE, null, result)); } }
/** * 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()); assertEquals(testParameters, callbackParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertEquals(returnValue, callbackParam.getValue().getReturnValue(), "Result should match"); //$NON-NLS-1$ assertEquals(testState, callbackParam.getValue().getState(), "States should match"); //$NON-NLS-1$ assertEquals(ActionType.AddDisk, callbackParam.getValue().getActionType(), "Action type should match"); //$NON-NLS-1$ verifyAsyncActionStartedAndSucceeded(); }
/** * Run the following test case. * <ol> * <li>Run a single action</li> * <li>Return logical failure, validate=false.</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() { ActionParametersBase testParameters = new ActionParametersBase(); ActionReturnValue returnValue = new ActionReturnValue(); returnValue.setValid(false); // Yes this is the default, but to make sure. frontend.handleActionResult(ActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, false); verify(mockActionCallback).executed(callbackParam.capture()); assertEquals(testParameters, callbackParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertEquals(returnValue, callbackParam.getValue().getReturnValue(), "Result should match"); //$NON-NLS-1$ assertEquals(testState, callbackParam.getValue().getState(), "States should match"); //$NON-NLS-1$ assertEquals(ActionType.AddDisk, callbackParam.getValue().getActionType(), "Action type should match"); //$NON-NLS-1$ }
@Test public void testUpdateWithClusterId() { setUpGetEntityExpectations(3); setUriInfo(setUpActionExpectations(ActionType.ChangeVDSCluster, ChangeVDSClusterParameters.class, new String[] { "ClusterId", "VdsId" }, new Object[] { GUIDS[1], GUIDS[0]}, true, true, new ActionReturnValue(), false)); setUriInfo(setUpActionExpectations(ActionType.UpdateVds, UpdateVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true)); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setId(GUIDS[1].toString()); Host host = getModel(0); host.setCluster(cluster); verifyModel(resource.update(host), 0); }
@Test public void testUpdateWithClusterName() { String clusterName = "Default"; setUpGetEntityExpectations(3); setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { clusterName }, getCluster(clusterName, GUIDS[1])); setUriInfo(setUpActionExpectations(ActionType.ChangeVDSCluster, ChangeVDSClusterParameters.class, new String[] { "ClusterId", "VdsId" }, new Object[] { GUIDS[1], GUIDS[0] }, true, true, new ActionReturnValue(), false)); setUriInfo(setUpActionExpectations(ActionType.UpdateVds, UpdateVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true)); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setName(clusterName); Host host = getModel(0); host.setCluster(cluster); verifyModel(resource.update(host), 0); }
@Test public void testApproveChangingCluster() { setUpGetEntityExpectations(4); setUriInfo(setUpActionExpectations(ActionType.ChangeVDSCluster, ChangeVDSClusterParameters.class, new String[] { "ClusterId", "VdsId" }, new Object[] { GUIDS[0], GUIDS[0]}, true, true, new ActionReturnValue(), false)); setUriInfo(setUpActionExpectations(ActionType.UpdateVds, UpdateVdsActionParameters.class, new String[] { }, new Object[] { }, true, true)); setUriInfo(setUpActionExpectations(ActionType.ApproveVds, ApproveVdsParameters.class, new String[] { "VdsId" }, new Object[] { GUIDS[0] })); org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster(); cluster.setId(GUIDS[0].toString()); Action action = new Action(); action.setCluster(cluster); verifyActionResponse(resource.approve(action)); }