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 testReturnsEmptyResponse() throws Exception { // Type of operation doesn't matter in this case OperationRequest request = new OperationRequest("wavelet.fetch", "op1"); WaveletProvider waveletProvider = mock(WaveletProvider.class); EventDataConverter converter = mock(EventDataConverter.class); ConversationUtil conversationUtil = mock(ConversationUtil.class); OperationContextImpl context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operationService.execute(request, context, BOB); JsonRpcResponse response = context.getResponse(request.getId()); assertFalse("Expected non error response", response.isError()); assertTrue("Empty Response must be set", response.getData().isEmpty()); } }
public void testReturnsEmptyResponse() throws Exception { // Type of operation doesn't matter in this case OperationRequest request = new OperationRequest("wavelet.fetch", "op1"); WaveletProvider waveletProvider = mock(WaveletProvider.class); EventDataConverter converter = mock(EventDataConverter.class); ConversationUtil conversationUtil = mock(ConversationUtil.class); OperationContextImpl context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operationService.execute(request, context, BOB); JsonRpcResponse response = context.getResponse(request.getId()); assertFalse("Expected non error response", response.isError()); assertTrue("Empty Response must be set", response.getData().isEmpty()); } }
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 testConstructResponse() { Map<ParamsProperty, Object> data = Maps.newHashMap(); data.put(ParamsProperty.PARTICIPANT_ID, USERNAME); operationContext.constructResponse(request, data); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertFalse("Expected non-error response", response.isError()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); assertEquals("Expected payload not to change", data, response.getData()); }
public void testConstructResponse() { Map<ParamsProperty, Object> data = Maps.newHashMap(); data.put(ParamsProperty.PARTICIPANT_ID, USERNAME); operationContext.constructResponse(request, data); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertFalse("Expected non-error response", response.isError()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); assertEquals("Expected payload not to change", data, response.getData()); }
public void testAppendBlip() throws Exception { OperationRequest operation = operationRequest(OperationType.WAVELET_APPEND_BLIP, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); OperationContextImpl context = helper.getContext(); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationBlip> it = conversation.getRootThread().getBlips().iterator(); it.next(); // skip, root assertEquals("New blip should be the second blip in the root thread", newBlip, it.next()); }
public void testAppendBlip() throws Exception { OperationRequest operation = operationRequest(OperationType.WAVELET_APPEND_BLIP, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); OperationContextImpl context = helper.getContext(); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationBlip> it = conversation.getRootThread().getBlips().iterator(); it.next(); // skip, root assertEquals("New blip should be the second blip in the root thread", newBlip, it.next()); }
public void testProcessEvent() throws Exception { // A randomly selected non-error event Event event = new WaveletBlipCreatedEvent(null, null, USERNAME, 0L, "root", "newBlip"); operationContext.processEvent(request, event); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertFalse("Expected non-error response", response.isError()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testProcessEvent() throws Exception { // A randomly selected non-error event Event event = new WaveletBlipCreatedEvent(null, null, USERNAME, 0L, "root", "newBlip"); operationContext.processEvent(request, event); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertFalse("Expected non-error response", response.isError()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testConstructErrorResponse() { operationContext.constructErrorResponse(request, ERROR_MESSAGE); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertTrue("Expected error response", response.isError()); assertEquals("Expected provided error message", ERROR_MESSAGE, response.getErrorMessage()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testConstructErrorResponse() { operationContext.constructErrorResponse(request, ERROR_MESSAGE); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertTrue("Expected error response", response.isError()); assertEquals("Expected provided error message", ERROR_MESSAGE, response.getErrorMessage()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testProcessErrorEvent() throws Exception { // A randomly selected non-error event Event event = new OperationErrorEvent(null, null, USERNAME, 0L, OPERATION_ID, ERROR_MESSAGE); operationContext.processEvent(request, event); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertTrue("Expected error response", response.isError()); assertEquals("Expected provided error message", ERROR_MESSAGE, response.getErrorMessage()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testProcessErrorEvent() throws Exception { // A randomly selected non-error event Event event = new OperationErrorEvent(null, null, USERNAME, 0L, OPERATION_ID, ERROR_MESSAGE); operationContext.processEvent(request, event); JsonRpcResponse response = operationContext.getResponse(request.getId()); assertTrue("Expected error response", response.isError()); assertEquals("Expected provided error message", ERROR_MESSAGE, response.getErrorMessage()); assertEquals("Expected operation id not to change", OPERATION_ID, response.getId()); }
public void testDeleteBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Delete the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_DELETE, rootBlipId); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); assertNull("Blip should have been deleted", conversation.getBlip(rootBlipId)); }
public void testDeleteBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Delete the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_DELETE, rootBlipId); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); assertNull("Blip should have been deleted", conversation.getBlip(rootBlipId)); }
public void testCreateChild() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually make a new child blip conversation.getRootThread().appendBlip(); // Create a child to the rootblip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CREATE_CHILD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationThread> it = conversation.getRootThread().getFirstBlip().getReplyThreads().iterator(); assertEquals("New blip should be the first blip in the first reply thread", it.next().getFirstBlip(), newBlip); }
public void testCreateChild() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually make a new child blip conversation.getRootThread().appendBlip(); // Create a child to the rootblip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CREATE_CHILD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationThread> it = conversation.getRootThread().getFirstBlip().getReplyThreads().iterator(); assertEquals("New blip should be the first blip in the first reply thread", it.next().getFirstBlip(), newBlip); }
public void testAppendCustomMarkup() throws Exception { String markup = "<custom>this is custom markup</custom>"; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the custom markup to the newly created blip. ConversationBlip markupBlip = conversation.getRootThread().appendBlip(); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("CustomMarkup generated error in service execution.", response.isError()); // The xml in new blip should match custom markup. String actualContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the custom markup as specified in the " + "operation. actualcontent: " + actualContent, actualContent.contains(markup)); }
public void testAppendCustomMarkup() throws Exception { String markup = "<custom>this is custom markup</custom>"; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the custom markup to the newly created blip. ConversationBlip markupBlip = conversation.getRootThread().appendBlip(); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("CustomMarkup generated error in service execution.", response.isError()); // The xml in new blip should match custom markup. String actualContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the new blip to contain the custom markup as specified in the " + "operation. actualcontent: " + actualContent, actualContent.contains(markup)); }