@Provides @Inject @Singleton protected RobotConnector provideRobotConnector( RobotConnection connection, RobotSerializer serializer) { return new RobotConnector(connection, serializer); }
@Override protected void setUp() throws Exception { accountStore = mock(AccountStore.class); connector = mock(RobotConnector.class); context = mock(OperationContext.class); operationService = new NotifyOperationService(accountStore, connector); when(accountStore.getAccount(ROBOT)).thenReturn(ROBOT_ACCOUNT); when(connector.fetchCapabilities(eq(ROBOT_ACCOUNT), anyString())).thenReturn(NEW_ROBOT_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() throws Exception { accountStore = mock(AccountStore.class); connector = mock(RobotConnector.class); context = mock(OperationContext.class); operationService = new NotifyOperationService(accountStore, connector); when(accountStore.getAccount(ROBOT)).thenReturn(ROBOT_ACCOUNT); when(connector.fetchCapabilities(eq(ROBOT_ACCOUNT), anyString())).thenReturn(NEW_ROBOT_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() throws Exception { connection = mock(RobotConnection.class); serializer = mock(RobotSerializer.class); connector = new RobotConnector(connection, serializer); robot = mock(Robot.class); when(robot.getAccount()).thenReturn(ROBOT_ACCOUNT); }
/** * Updates the account for the given {@link Robot}. * * @param robot the {@link Robot} to update. * @throws CapabilityFetchException if the capabilities could not be fetched * or parsed. */ public void updateRobotAccount(Robot robot) throws CapabilityFetchException, PersistenceException { // TODO: Pass in activeAPIUrl String activeApiUrl = ""; RobotAccountData newAccount = connector.fetchCapabilities(robot.getAccount(), activeApiUrl); accountStore.putAccount(newAccount); robot.setAccount(newAccount); } }
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); }
@Override protected void setUp() throws Exception { connection = mock(RobotConnection.class); serializer = mock(RobotSerializer.class); connector = new RobotConnector(connection, serializer); robot = mock(Robot.class); when(robot.getAccount()).thenReturn(ROBOT_ACCOUNT); }
public void testUpdateRobotAccount() throws Exception { Robot robot = mock(Robot.class); RobotAccountData account = mock(RobotAccountData.class); when(robot.getAccount()).thenReturn(account); // Return newAccount when updated RobotAccountData newAccount = mock(RobotAccountData.class); when(robotConnector.fetchCapabilities(eq(account), any(String.class))).thenReturn(newAccount); gateway.updateRobotAccount(robot); verify(accountStore).putAccount(newAccount); } }
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 testUpdateRobotAccount() throws Exception { Robot robot = mock(Robot.class); RobotAccountData account = mock(RobotAccountData.class); when(robot.getAccount()).thenReturn(account); // Return newAccount when updated RobotAccountData newAccount = mock(RobotAccountData.class); when(robotConnector.fetchCapabilities(eq(account), any(String.class))).thenReturn(newAccount); gateway.updateRobotAccount(robot); verify(accountStore).putAccount(newAccount); } }
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 testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
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 testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
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 testUpdateCapabilites() throws Exception { OperationRequest operation = new OperationRequest( "robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); operationService.execute(operation, context, ROBOT); verify(connector).fetchCapabilities(eq(ROBOT_ACCOUNT), anyString()); verify(accountStore).putAccount(NEW_ROBOT_ACCOUNT); }
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 testUpdateCapabilites() throws Exception { OperationRequest operation = new OperationRequest( "robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); operationService.execute(operation, context, ROBOT); verify(connector).fetchCapabilities(eq(ROBOT_ACCOUNT), anyString()); verify(accountStore).putAccount(NEW_ROBOT_ACCOUNT); }