@Override public void onFailure(final List<VdcOperation<ActionType, ActionParametersBase>> operation, final Throwable caught) { if (ignoreFailure(caught)) { return; } logger.log(Level.SEVERE, "Failed to execute runMultipleAction: " + caught, caught); //$NON-NLS-1$ failureEventHandler(caught); if (callback != null) { callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, null, state)); } fireAsyncActionFailedEvent(state); } };
@Override public void onSuccess(final List<VdcOperation<ActionType, ActionParametersBase>> operationList, final List<ActionReturnValue> resultObject) { logger.finer("Frontend: successfully executed runMultipleAction, determining result!"); //$NON-NLS-1$ List<ActionReturnValue> failed = resultObject.stream() .filter(v -> !v.isValid()) .collect(Collectors.toList()); if (showErrorDialog && !failed.isEmpty()) { translateErrors(failed); getEventsHandler().runMultipleActionFailed(actionType, failed); } if (callback != null) { callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, resultObject, state)); } fireAsyncActionSucceededEvent(state); }
if (callback != null) { List<ActionReturnValue> emptyResult = new ArrayList<>(); callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, emptyResult, state));
/** * 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()); StatusCodeException exception = new StatusCodeException(0, "0 status code"); //$NON-NLS-1$ callbackMultipleActions.getValue().onFailure(exception); verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any()); verify(mockMultipleActionCallback, never()).executed(callbackMultipleParam.capture()); verifyAsyncActionStartedButNotCompleted(); }
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))); } }
/** * Run the following test case. * <ol> * <li>Run a multiple actions, 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 proper values are passed to the callback.</li> * </ol> */ @Test public void testrunMultipleActions_404_failure_multiple() { ArrayList<ActionParametersBase> parameters = new ArrayList<>(); parameters.add(new ActionParametersBase()); frontend.runMultipleAction(ActionType.AddLocalStorageDomain, parameters, false, mockMultipleActionCallback, testState); verify(mockService).runMultipleActions(eq(ActionType.AddLocalStorageDomain), eq(parameters), eq(false), eq(false), callbackMultipleActions.capture()); StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); //$NON-NLS-1$ callbackMultipleActions.getValue().onFailure(exception); verify(mockFrontendFailureEvent).raise(eq(Frontend.class), (FrontendFailureEventArgs) any()); verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture()); assertEquals(ActionType.AddLocalStorageDomain, callbackMultipleParam.getValue().getActionType(), "ActionType should be 'AddLocalStorageDomain'"); //$NON-NLS-1$ assertEquals(parameters, callbackMultipleParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$ assertNull(callbackMultipleParam.getValue().getReturnValue(), "There should be no result"); //$NON-NLS-1$ assertEquals(testState, callbackMultipleParam.getValue().getState(), "States should match"); //$NON-NLS-1$ verifyAsyncActionStartedAndFailed(); }
assertEquals(1, failedCaptor.getValue().size(), "There is one failure"); //$NON-NLS-1$ assertEquals(returnValues.get(1), failedCaptor.getValue().get(0), "Failures should match"); //$NON-NLS-1$ verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture()); assertEquals(parameters, callbackMultipleParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$
callbackMultipleActions.getValue().onSuccess(returnValues); verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (FrontendFailureEventArgs) any()); verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture()); assertEquals(parameters, callbackMultipleParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$
assertEquals(returnValues.get(1), failedCaptor.getValue().get(0), "Failures should match"); //$NON-NLS-1$ assertEquals(returnValues.get(3), failedCaptor.getValue().get(1), "Failures should match"); //$NON-NLS-1$ verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture()); assertEquals(parameters, callbackMultipleParam.getValue().getParameters(), "Parameters should match"); //$NON-NLS-1$