/** * Get the GWT RPC service. * @param callback The callback to use when determining the service. */ private void getService(final ServiceCallback callback) { if (xsrfRequestBuilder.getXsrfToken() != null) { callback.serviceFound(service); } else { xsrfService.getNewXsrfToken(new AsyncCallback<XsrfToken>() { @Override public void onSuccess(XsrfToken token) { xsrfRequestBuilder.setXsrfToken(token); callback.serviceFound(service); } @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } }); } }
@Override public void onSuccess(XsrfToken token) { xsrfRequestBuilder.setXsrfToken(token); callback.serviceFound(service); }
@BeforeEach public void setUp() { mockXsrfRpcRequestBuilder = new XsrfRpcRequestBuilder(); testProvider = new GWTRPCCommunicationProvider(mockService, mockXsrfService, mockXsrfRpcRequestBuilder); mockXsrfRpcRequestBuilder.setXsrfToken(new XsrfToken("Something")); //$NON-NLS-1$ }
private void handleRunMultipleActionFailure(final List<VdcOperation<?, ?>> operations, final Throwable exception) { //Clear out the token, and let the retry mechanism try again. xsrfRequestBuilder.setXsrfToken(null); Map<VdcOperationCallback<?, ?>, List<VdcOperation<?, ?>>> callbackMap = getCallbackMap(operations); for (Map.Entry<VdcOperationCallback<?, ?>, List<VdcOperation<?, ?>>> callbackEntry: callbackMap.entrySet()) { if (callbackEntry.getKey() instanceof VdcOperationCallbackList) { ((VdcOperationCallbackList) callbackEntry.getKey()).onFailure(callbackEntry.getValue(), exception); } else { ((VdcOperationCallback) callbackEntry.getKey()).onFailure(callbackEntry.getValue().get(0), exception); } } }
@BeforeEach public void setUp() { mockService = mock(GenericApiGWTServiceAsync.class, withSettings().extraInterfaces(ServiceDefTarget.class)); fakeScheduler = new FakeGWTScheduler(); CommunicationProvider communicationsProvider = new GWTRPCCommunicationProvider(mockService, mockXsrfService, mockXsrfRpcRequestBuilder); when(mockXsrfRpcRequestBuilder.getXsrfToken()).thenReturn(new XsrfToken("Something")); //$NON-NLS-1$ OperationProcessor operationProcessor = new OperationProcessor(communicationsProvider); operationProcessor.setScheduler(fakeScheduler); VdcOperationManager operationsManager = new VdcOperationManager(mockEventBus, operationProcessor); frontend = new Frontend(operationsManager, mockValidateErrorsTranslator, mockVdsmErrorsTranslator, mockEventBus); frontend.frontendFailureEvent = mockFrontendFailureEvent; frontend.frontendNotLoggedInEvent = mockFrontendNotLoggedInEvent; frontend.setEventsHandler(mockEventsHandler); frontend.setConstants(mockConstants); when(mockAsyncQuery.getModel()).thenReturn(ASYNC_OPERATION_TARGET); when(mockAsyncQuery.getAsyncCallback()).thenReturn(mockAsyncCallback); }
/** * Multiple queries failure handler. * @param queriesList The queries list. * @param exception The exception causing the failure. */ private void handleMultipleQueriesFailure(final List<VdcOperation<?, ?>> queriesList, final Throwable exception) { //Clear out the token, and let the retry mechanism try again. xsrfRequestBuilder.setXsrfToken(null); Map<VdcOperationCallback<?, ?>, List<VdcOperation<?, ?>>> callbackMap = getCallbackMap(queriesList); for (Map.Entry<VdcOperationCallback<?, ?>, List<VdcOperation<?, ?>>> callbackEntry: callbackMap.entrySet()) { if (callbackEntry.getKey() instanceof VdcOperationCallbackList) { ((VdcOperationCallbackList) callbackEntry.getKey()).onFailure(callbackEntry.getValue(), exception); } else { ((VdcOperationCallback) callbackEntry.getKey()).onFailure(callbackEntry.getValue().get(0), exception); } } }
@BeforeEach public void setUp() { mockService = mock(GenericApiGWTServiceAsync.class, withSettings().extraInterfaces(ServiceDefTarget.class)); fakeScheduler = new FakeGWTScheduler(); CommunicationProvider communicationsProvider = new GWTRPCCommunicationProvider(mockService, mockXsrfService, mockXsrfRpcRequestBuilder); when(mockXsrfRpcRequestBuilder.getXsrfToken()).thenReturn(new XsrfToken("Something")); //$NON-NLS-1$ OperationProcessor operationProcessor = new OperationProcessor(communicationsProvider); operationProcessor.setScheduler(fakeScheduler); VdcOperationManager operationsManager = new VdcOperationManager(mockEventBus, operationProcessor); frontend = new Frontend(operationsManager, mockValidateErrorsTranslator, mockVdsmErrorsTranslator, mockEventBus); frontend.setEventsHandler(mockEventsHandler); frontend.setConstants(mockConstants); frontend.frontendFailureEvent = mockFrontendFailureEvent; when(mockConstants.noValidateMessage()).thenReturn(NO_MESSAGE); }
/** * 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); } }
@SuppressWarnings("unchecked") @Test public void testMissingXsrfToken() { //Remove token so there should be a request for it. mockXsrfRpcRequestBuilder.setXsrfToken(null); QueryParametersBase testParameters = new QueryParametersBase(); final List<VdcOperation<QueryType, QueryParametersBase>> operationList = new ArrayList<>(); final VdcOperation<QueryType, QueryParametersBase> testOperation = new VdcOperation<>(QueryType.Search, testParameters, null); operationList.add(testOperation); testProvider.transmitOperation(testOperation); verify(mockXsrfService).getNewXsrfToken((AsyncCallback<XsrfToken>) any()); }