private void parseRobotDescriptionXmlFile() throws CapabilityFetchException { String xmlContent = connection.get(capabilitiesXmlUrl); if (xmlContent == null || xmlContent.isEmpty()) { throw new CapabilityFetchException("Empty capabilities.xml");
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 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 testFetchCapabilities() throws Exception { when(connection.get(TEST_CAPABILITIES_ENDPOINT)).thenReturn(CAPABILITIES_XML); RobotAccountData accountData = connector.fetchCapabilities(ROBOT_ACCOUNT, ""); RobotCapabilities capabilities = accountData.getCapabilities(); assertEquals("Expected capabilities hash as specified in the xml", CAPABILITIES_HASH, capabilities.getCapabilitiesHash()); assertEquals("Expected protocol version as specified in the xml", ProtocolVersion.V2_2, capabilities.getProtocolVersion()); Map<EventType, Capability> capabilitiesMap = capabilities.getCapabilitiesMap(); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.size() == 2); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.containsKey(EventType.WAVELET_SELF_ADDED)); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.containsKey(EventType.OPERATION_ERROR)); // Only one connection should be made verify(connection).get(TEST_CAPABILITIES_ENDPOINT); } }
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 testFetchCapabilities() throws Exception { when(connection.get(TEST_CAPABILITIES_ENDPOINT)).thenReturn(CAPABILITIES_XML); RobotAccountData accountData = connector.fetchCapabilities(ROBOT_ACCOUNT, ""); RobotCapabilities capabilities = accountData.getCapabilities(); assertEquals("Expected capabilities hash as specified in the xml", CAPABILITIES_HASH, capabilities.getCapabilitiesHash()); assertEquals("Expected protocol version as specified in the xml", ProtocolVersion.V2_2, capabilities.getProtocolVersion()); Map<EventType, Capability> capabilitiesMap = capabilities.getCapabilitiesMap(); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.size() == 2); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.containsKey(EventType.WAVELET_SELF_ADDED)); assertTrue("Expected capabilities as specified in the xml", capabilitiesMap.containsKey(EventType.OPERATION_ERROR)); // Only one connection should be made verify(connection).get(TEST_CAPABILITIES_ENDPOINT); } }
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 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 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()); }
/** * 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(); }