use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveSetsVersionOnResTopic.
/*
**Tests_SRS_MQTTDEVICETWIN_25_041: [**If the topic is of type response topic then this method shall parse further to look for version which if found is set by calling setVersion**]**
*/
@Test
public void receiveSetsVersionOnResTopic(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] actualPayload = "GetTwinResponseDataContainingDesiredAndReportedPropertiesDocument".getBytes();
final String expectedTopic = "$iothub/twin/res/" + "201" + "/?$rid=" + mockReqId + "&$version=" + mockVersion;
DeviceTwinMessage receivedMessage = null;
try {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
String insertTopic = expectedTopic;
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, actualPayload);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
Map<String, DeviceOperations> requestMap = new HashMap<>();
requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_GET_REQUEST);
Deencapsulation.setField(testTwin, "requestMap", requestMap);
//act
receivedMessage = (DeviceTwinMessage) testTwin.receive();
} finally {
//assert
assertNotNull(receivedMessage);
assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_GET_RESPONSE);
assertTrue(receivedMessage.getRequestId().equals(mockReqId));
assertTrue(receivedMessage.getStatus().equals("201"));
assertTrue(receivedMessage.getVersion().equals(mockVersion));
}
}
use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method receiveParsesResponseTopicForUpdateReportedPropertiesSucceeds.
@Test
public void receiveParsesResponseTopicForUpdateReportedPropertiesSucceeds(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] actualPayload = "".getBytes();
/*
The following does not work
final byte[] actualPayload = null;
*/
final String expectedTopic = "$iothub/twin/res/" + "200" + "/?$rid=" + mockReqId + "&$version=" + mockVersion;
DeviceTwinMessage receivedMessage = null;
try {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
String insertTopic = expectedTopic;
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, actualPayload);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
Map<String, DeviceOperations> requestMap = new HashMap<>();
requestMap.put(mockReqId, DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST);
Deencapsulation.setField(testTwin, "requestMap", requestMap);
//act
receivedMessage = (DeviceTwinMessage) testTwin.receive();
} finally {
//assert
assertNotNull(receivedMessage);
assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
assertTrue(receivedMessage.getStatus().equals("200"));
assertTrue(receivedMessage.getRequestId().equals(mockReqId));
assertTrue(receivedMessage.getVersion().equals(mockVersion));
}
}
use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.
the class MqttDeviceTwinTest method parsePayloadRemovesTopicIfFound.
/*
**Tests_SRS_MQTTDEVICETWIN_25_013: [**If the topic is found in the message queue then parsePayload shall delete it from the queue.**]**
*/
@Test
public void parsePayloadRemovesTopicIfFound(@Mocked final Mqtt mockMqtt) throws IOException {
//arrange
MqttDeviceTwin testTwin = new MqttDeviceTwin();
String insertTopic = "$iothub/twin/" + anyString;
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, insertMessage);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
//act
byte[] parsedPayload = Deencapsulation.invoke(testTwin, "parsePayload", insertTopic);
//assert
ConcurrentSkipListMap<String, byte[]> retrieveTestMap = Deencapsulation.getField(mockMqtt, "allReceivedMessages");
assertFalse(retrieveTestMap.containsKey(insertTopic));
}
use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadShallThrowIOExceptionIfTopicIsNotFound.
/*
**Tests_SRS_MqttMessaging_25_012: [**If the topic is non-null and received messagesqueue could not locate the payload then this method shall throw IOException**]**
*/
@Test(expected = IOException.class)
public void parsePayloadShallThrowIOExceptionIfTopicIsNotFound(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic_actual = "$iothub/twin/PATCH/properties/desired/#";
final String insertTopic_messaging = "devices/" + clientId + "/messages/devicebound/abc";
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic_actual, insertMessage);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic_messaging);
}
use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.
the class HttpMonitorIT method callTestMatchingTextInResponse.
public void callTestMatchingTextInResponse(boolean preferIPv6) throws UnknownHostException {
if (m_runTests == false)
return;
PollStatus status = null;
ServiceMonitor monitor = new HttpMonitor();
final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
final MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", preferIPv6), "HTTP");
final int port = JUnitHttpServerExecutionListener.getPort();
if (port > 0) {
m.put("port", String.valueOf(port));
} else {
throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
}
m.put("retry", "0");
m.put("timeout", "500");
m.put("response", "100-499");
m.put("verbose", "true");
m.put("host-name", "localhost");
m.put("url", "/");
m.put("response-text", "opennmsrulz");
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status.getStatusCode());
assertNotNull(status.getReason());
m.put("response-text", "written by monkeys");
MockUtil.println("\nliteral text check: \"written by monkeys\"");
monitor = new HttpMonitor();
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
m.put("response-text", "~.*[Tt]est HTTP [Ss]erver.*");
MockUtil.println("\nregex check: \".*[Tt]est HTTP [Ss]erver.*\"");
monitor = new HttpMonitor();
status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
Aggregations