@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); }
@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 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 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 testProcessUpdatesAccountIfNoCapabilities() throws Exception { // Enqueue a wavelet so that the robot actually runs. enqueueEmptyWavelet(); robot.run(); assertEquals("The robot should be initialized", INITIALIZED_ACCOUNT, robot.getAccount()); }
public void testProcessUpdatesAccountIfNoCapabilities() throws Exception { // Enqueue a wavelet so that the robot actually runs. enqueueEmptyWavelet(); robot.run(); assertEquals("The robot should be initialized", INITIALIZED_ACCOUNT, robot.getAccount()); }
/** * Synchronously sends an {@link EventMessageBundle} off to a robot and hands * back the response in the form of a list of {@link OperationRequest}s. * * @param bundle the bundle to send to the robot. * @param robot the {@link RobotAccountData} of the robot. * @param version the version that we should speak to the robot. * @returns list of {@link OperationRequest}s that the robot wants to have * executed. */ public List<OperationRequest> sendMessageBundle( EventMessageBundle bundle, Robot robot, ProtocolVersion version) { String serializedBundle = serializer.serialize(bundle, version); String robotUrl = robot.getAccount().getUrl() + Robot.RPC_URL; LOG.info("Sending: " + serializedBundle + " to " + robotUrl); try { String response = connection.postJson(robotUrl, serializedBundle); LOG.info("Received: " + response + " from " + robotUrl); return serializer.deserializeOperations(response); } catch (RobotConnectionException e) { LOG.info("Failed to receive a response from " + robotUrl, e); } catch (InvalidRequestException e) { LOG.info("Failed to deserialize passive API response", e); } // Return an empty list and let the caller ignore the failure return Collections.emptyList(); }