use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadShallThrowIOExceptionIfQueueIsEmpty.
@Test(expected = IOException.class)
public void parsePayloadShallThrowIOExceptionIfQueueIsEmpty(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic = "devices/" + clientId + "/messages/devicebound/abc";
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic);
assertNull(retrieveMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parseTopicReturnsNullIfQueueIsEmpty.
/*
**Tests_SRS_MqttMessaging_25_007: [**If received messages queue is empty then parseTopic shall return null string.**]**
*/
@Test
public void parseTopicReturnsNullIfQueueIsEmpty(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
String retrieveTopic = Deencapsulation.invoke(testMqttMessaging, "parseTopic");
assertNull(retrieveTopic);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method sendShallThrowIOExceptionIfMessageIsEmpty.
@Test(expected = IOException.class)
public void sendShallThrowIOExceptionIfMessageIsEmpty(@Mocked final Mqtt mockMqtt) throws IOException {
final byte[] messageBody = {};
new NonStrictExpectations() {
{
mockMessage.getBytes();
result = messageBody;
Deencapsulation.invoke(mockMqtt, "publish", anyString, messageBody);
result = mockIOException;
}
};
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
testMqttMessaging.send(null);
new Verifications() {
{
mockMessage.getBytes();
times = 1;
Deencapsulation.invoke(mockMqtt, "publish", mockParseTopic, new byte[1]);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttTest method receiveReturnsNullMessageWhenParseTopicReturnsNull.
/*
**Tests_SRS_Mqtt_25_022: [**If the call parseTopic returns null or empty string then this method shall do nothing and return null**]**
*/
@Test
public void receiveReturnsNullMessageWhenParseTopicReturnsNull() throws IOException, MqttException {
//arrange
final byte[] payload = { 0x61, 0x62, 0x63 };
baseConstructorExpectations(true);
baseConnectExpectation();
new MockUp<MqttMessaging>() {
@Mock
String parseTopic() throws IOException {
return null;
}
@Mock
byte[] parsePayload(String topic) throws IOException {
return payload;
}
};
final Mqtt mockMqtt = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
try {
new NonStrictExpectations() {
{
mockMqttAsyncClient.isConnected();
result = true;
}
};
Deencapsulation.invoke(mockMqtt, "connect");
//act
Message receivedMessage = mockMqtt.receive();
//assert
assertNull(receivedMessage);
} finally {
testCleanUp(mockMqtt);
}
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging in project azure-iot-sdk-java by Azure.
the class MqttMessagingTest method parsePayloadRemovesTheKeyValuePairFromQueueIfFound.
/*
**Tests_SRS_MqttMessaging_25_014: [**If the topic is found in the message queue then parsePayload shall delete it from the queue.**]**
*/
@Test
public void parsePayloadRemovesTheKeyValuePairFromQueueIfFound(@Mocked final Mqtt mockMqtt) throws IOException {
MqttMessaging testMqttMessaging = new MqttMessaging(serverUri, clientId, userName, password, mockIotHubSSLContext);
;
final String insertTopic = "devices/" + clientId + "/messages/devicebound/abc";
final byte[] insertMessage = { 0x61, 0x62, 0x63 };
ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
testMap.put(insertTopic, insertMessage);
Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
byte[] retrieveMessage = Deencapsulation.invoke(testMqttMessaging, "parsePayload", insertTopic);
assertTrue(testMap.isEmpty());
}
Aggregations