@Override protected void setUp() { converterManager = mock(EventDataConverterManager.class); waveletProvider = mock(WaveletProvider.class); operationRegistry = mock(OperationServiceRegistry.class); EventDataConverter converter = mock(EventDataConverter.class); ConversationUtil conversationUtil = mock(ConversationUtil.class); applicator = new RobotOperationApplicator( converterManager, waveletProvider, operationRegistry, conversationUtil); waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, ROBOT_PARTICIPANT, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L); hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); }
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)); }
/** * Applies the operations within the context of the wavelet. * * @param operations the operations to apply * @param wavelet the wavelet which is the context in which this operation is * performed. * @param hashedVersion the version of the wavelet to which to apply the * operations to. * @param account the account for which to apply robot operations. */ void applyOperations(List<OperationRequest> operations, ReadableWaveletData wavelet, HashedVersion hashedVersion, RobotAccountData account) { // The robots we support should be sending us their version in their first // operation ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(operations); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(protocolVersion), conversationUtil, new RobotWaveletData(wavelet, hashedVersion)); executeOperations(context, operations, account); handleResults(context, 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)); }
@Override protected void setUp() { converterManager = mock(EventDataConverterManager.class); waveletProvider = mock(WaveletProvider.class); operationRegistry = mock(OperationServiceRegistry.class); EventDataConverter converter = mock(EventDataConverter.class); ConversationUtil conversationUtil = mock(ConversationUtil.class); applicator = new RobotOperationApplicator( converterManager, waveletProvider, operationRegistry, conversationUtil); waveletData = WaveletDataUtil.createEmptyWavelet(WAVELET_NAME, ROBOT_PARTICIPANT, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L); hashedVersionZero = HASH_FACTORY.createVersionZero(WAVELET_NAME); }
public void testapplyOperationsExecutesAndSubmitsDelta() throws Exception { // Use a special operation service that generates a simple delta; OperationService service = new OperationService() { @Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { context.openWavelet(WAVE_ID, WAVELET_ID, ROBOT_PARTICIPANT).addParticipant(ALEX); } }; when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationRequest operation = new OperationRequest("wavelet.create", "op1"); List<OperationRequest> operations = Collections.singletonList(operation); applicator.applyOperations(operations, waveletData, hashedVersionZero, ACCOUNT); verify(operationRegistry).getServiceFor(any(OperationType.class)); verify(waveletProvider).submitRequest(eq(WAVELET_NAME), any(ProtocolWaveletDelta.class), any(WaveletProvider.SubmitRequestListener.class)); } }
/** * Creates a new {@link Robot}. * * @param robotName the name of the robot. * @param account the {@link RobotAccountData} belonging to the given * {@link RobotName}. */ private Robot createNewRobot(RobotName robotName, RobotAccountData account) { EventGenerator eventGenerator = new EventGenerator(robotName, conversationUtil); RobotOperationApplicator operationApplicator = new RobotOperationApplicator(converterManager, waveletProvider, new OperationServiceRegistryImpl(notifyOpService), conversationUtil); return new Robot(robotName, account, this, connector, converterManager, waveletProvider, eventGenerator, operationApplicator); }
public void testapplyOperationsExecutesAndSubmitsDelta() throws Exception { // Use a special operation service that generates a simple delta; OperationService service = new OperationService() { @Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { context.openWavelet(WAVE_ID, WAVELET_ID, ROBOT_PARTICIPANT).addParticipant(ALEX); } }; when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationRequest operation = new OperationRequest("wavelet.create", "op1"); List<OperationRequest> operations = Collections.singletonList(operation); applicator.applyOperations(operations, waveletData, hashedVersionZero, ACCOUNT); verify(operationRegistry).getServiceFor(any(OperationType.class)); verify(waveletProvider).submitRequest(eq(WAVELET_NAME), any(ProtocolWaveletDelta.class), any(WaveletProvider.SubmitRequestListener.class)); } }
@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)); }
@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)); }
LOG.info(robotName + ": received operations"); operationApplicator.applyOperations( response, wavelet.getSnapshotAfterDeltas(), wavelet.getVersionAfterDeltas(), account);