/** * Fetches multiple profiles using Data API. */ private FetchProfilesResult fetchProfilesFromService(ParticipantId user, List<String> addresses) { OperationQueue opQueue = new OperationQueue(); FetchProfilesRequest request = new FetchProfilesRequest(addresses); opQueue.fetchProfiles(request); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(ProtocolVersion.DEFAULT), conversationUtil); OperationRequest operationRequest = opQueue.getPendingOperations().get(0); String opId = operationRequest.getId(); OperationUtil.executeOperation(operationRequest, operationRegistry, context, user); JsonRpcResponse jsonRpcResponse = context.getResponses().get(opId); FetchProfilesResult profileResults = (FetchProfilesResult) jsonRpcResponse.getData().get(ParamsProperty.FETCH_PROFILES_RESULT); return profileResults; }
public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class, new ThrowsException(new InvalidRequestException(""))); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); assertTrue("Expected one response", context.getResponses().size() == 1); assertTrue("Expected an error response", context.getResponse(operationId).isError()); }
public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class, new ThrowsException(new InvalidRequestException(""))); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); assertTrue("Expected one response", context.getResponses().size() == 1); assertTrue("Expected an error response", context.getResponse(operationId).isError()); }
/** * Performs search using Data API. */ protected SearchResult performSearch(SearchRequest searchRequest, ParticipantId user) { OperationQueue opQueue = new OperationQueue(); opQueue.search(searchRequest.getQuery(), searchRequest.getIndex(), searchRequest.getNumResults()); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(ProtocolVersion.DEFAULT), conversationUtil); LOG.fine( "Performing query: " + searchRequest.getQuery() + " [" + searchRequest.getIndex() + ", " + (searchRequest.getIndex() + searchRequest.getNumResults()) + "]"); OperationRequest operationRequest = opQueue.getPendingOperations().get(0); String opId = operationRequest.getId(); OperationUtil.executeOperation(operationRequest, operationRegistry, context, user); JsonRpcResponse jsonRpcResponse = context.getResponses().get(opId); SearchResult searchResult = (SearchResult) jsonRpcResponse.getData().get(ParamsProperty.SEARCH_RESULTS); return searchResult; } }