public void testProcessSendsNoBundleWhenNoEvents() throws Exception { enqueueEmptyWavelet(); robot.run(); // Verify that the robot was not called or any operations where processed verify(connector, never()).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator, never()).applyOperations(anyListOf(OperationRequest.class), any(ReadableWaveletData.class), any(HashedVersion.class), eq(ACCOUNT)); }
public void testProcessSendsNoBundleWhenNoEvents() throws Exception { enqueueEmptyWavelet(); robot.run(); // Verify that the robot was not called or any operations where processed verify(connector, never()).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator, never()).applyOperations(anyListOf(OperationRequest.class), any(ReadableWaveletData.class), any(HashedVersion.class), eq(ACCOUNT)); }
public void testDeserializationFailsSafely() throws Exception { when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenThrow( new InvalidRequestException("Invalid Request")); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertTrue("Expected no operations to be returned", operations.isEmpty()); }
public void testSuccessfulSendMessageBundle() throws Exception { final List<OperationRequest> expectedOperations = Collections.unmodifiableList( Lists.newArrayList(new OperationRequest("wavelet.setTitle", "op1"))); when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenReturn(expectedOperations); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertEquals(expectedOperations, operations); }
public void testSuccessfulSendMessageBundle() throws Exception { final List<OperationRequest> expectedOperations = Collections.unmodifiableList( Lists.newArrayList(new OperationRequest("wavelet.setTitle", "op1"))); when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenReturn(expectedOperations); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertEquals(expectedOperations, operations); }
public void testConnectionFailsSafely() throws Exception { when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenThrow( new RobotConnectionException("Connection Failed")); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertTrue("Expected no operations to be returned", operations.isEmpty()); }
public void testConnectionFailsSafely() throws Exception { when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenThrow( new RobotConnectionException("Connection Failed")); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertTrue("Expected no operations to be returned", operations.isEmpty()); }
public void testDeserializationFailsSafely() throws Exception { when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenThrow( new InvalidRequestException("Invalid Request")); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertTrue("Expected no operations to be returned", operations.isEmpty()); }
@SuppressWarnings("unchecked") public void testProcessSendsBundleAndCallsOperationsApplicator() throws Exception { EventMessageBundle messages = new EventMessageBundle(ROBOT_NAME.toEmailAddress(), ""); messages.addEvent(new DocumentChangedEvent(null, null, ALEX.getAddress(), 0L, "b+1234")); when(eventGenerator.generateEvents( any(WaveletAndDeltas.class), anyMap(), any(EventDataConverter.class))).thenReturn(messages); OperationRequest op = new OperationRequest("wavelet.fetch", "op1"); List<OperationRequest> ops = Collections.singletonList(op); when(connector.sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class))).thenReturn(ops); enqueueEmptyWavelet(); robot.run(); verify(connector).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator).applyOperations( eq(ops), any(ReadableWaveletData.class), any(HashedVersion.class), eq(INITIALIZED_ACCOUNT)); }
@SuppressWarnings("unchecked") public void testProcessSendsBundleAndCallsOperationsApplicator() throws Exception { EventMessageBundle messages = new EventMessageBundle(ROBOT_NAME.toEmailAddress(), ""); messages.addEvent(new DocumentChangedEvent(null, null, ALEX.getAddress(), 0L, "b+1234")); when(eventGenerator.generateEvents( any(), anyMap(), any())).thenReturn(messages); OperationRequest op = new OperationRequest("wavelet.fetch", "op1"); List<OperationRequest> ops = Collections.singletonList(op); when(connector.sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class))).thenReturn(ops); enqueueEmptyWavelet(); robot.run(); verify(connector).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator).applyOperations( eq(ops), any(ReadableWaveletData.class), any(HashedVersion.class), eq(INITIALIZED_ACCOUNT)); }
connector.sendMessageBundle(messages, this, capabilities.getProtocolVersion()); LOG.info(robotName + ": received operations");