use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method stopSucceedsDoesNotCallUnSubscribeIfNotStarted.
@Test
public void stopSucceedsDoesNotCallUnSubscribeIfNotStarted() throws IOException {
//arrange
MqttDeviceMethod testMethod = new MqttDeviceMethod();
//act
testMethod.stop();
//assert
new Verifications() {
{
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveSucceeds.
/*
Tests_SRS_MqttDeviceMethod_25_024: [**This method shall call parseTopic to parse the topic from the received Messages queue looking for presence of $iothub/methods/ in the topics .**]**
Tests_SRS_MqttDeviceMethod_25_026: [**This method shall call parsePayload to get the message payload from the recevived Messages queue corresponding to the messaging client's operation.**]**
Tests_SRS_MqttDeviceMethod_25_028: [**If the topic is of type post topic then this method shall parse further for method name and set it for the message by calling setMethodName for the message**]**
Tests_SRS_MqttDeviceMethod_25_030: [**If the topic is of type post topic then this method shall parse further to look for request id which if found is set by calling setRequestId**]**
Tests_SRS_MqttDeviceMethod_25_032: [**If the topic is of type post topic and if method name and request id has been successfully parsed then this method shall set operation type as DEVICE_OPERATION_METHOD_RECEIVE_REQUEST **]**
*/
@Test
public void receiveSucceeds() throws IOException {
//arrange
String topic = "$iothub/methods/POST/testMethod/?$rid=10";
byte[] actualPayload = "TestPayload".getBytes();
ConcurrentSkipListMap<String, byte[]> testAllReceivedMessages = new ConcurrentSkipListMap<>();
testAllReceivedMessages.put(topic, actualPayload);
Deencapsulation.setField(mockedMqtt, "allReceivedMessages", testAllReceivedMessages);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
Message testMessage = testMethod.receive();
DeviceMethodMessage testDMMessage = (DeviceMethodMessage) testMessage;
//assert
assertNotNull(testMessage);
assertTrue(testMessage.getMessageType().equals(MessageType.DeviceMethods));
assertTrue(testDMMessage.getRequestId().equals(String.valueOf(10)));
assertTrue(testDMMessage.getMethodName().equals("testMethod"));
assertTrue(testDMMessage.getDeviceOperationType().equals(DEVICE_OPERATION_METHOD_RECEIVE_REQUEST));
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method stopSucceedsCallsUnSubscribe.
/*
Tests_SRS_MqttDeviceMethod_25_015: [**stop method shall unsubscribe from method subscribe topic ($iothub/methods/POST/#) and throw IoException otherwise.**]**
*/
@Test
public void stopSucceedsCallsUnSubscribe() throws IOException {
//arrange
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
testMethod.stop();
//assert
new Verifications() {
{
Deencapsulation.invoke(mockedMqtt, "unsubscribe", anyString);
maxTimes = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendThrowsIfNotStarted.
/*
Tests_SRS_MqttDeviceMethod_25_018: [**send method shall throw an IoException if device method has not been started yet.**]**
*/
@Test(expected = IOException.class)
public void sendThrowsIfNotStarted() throws IOException {
final byte[] actualPayload = "TestMessage".getBytes();
final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
//act
testMethod.send(testMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveThrowsIfMethodNameCouldNotBeParsed.
/*
Tests_SRS_MqttDeviceMethod_25_029: [**If method name not found or is null then receive shall throw IOException **]**
*/
@Test(expected = IOException.class)
public void receiveThrowsIfMethodNameCouldNotBeParsed() throws IOException {
//arrange
String topic = "$iothub/methods/POST/";
byte[] actualPayload = "TestPayload".getBytes();
ConcurrentSkipListMap<String, byte[]> testAllReceivedMessages = new ConcurrentSkipListMap<>();
testAllReceivedMessages.put(topic, actualPayload);
Deencapsulation.setField(mockedMqtt, "allReceivedMessages", testAllReceivedMessages);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
Message testMessage = testMethod.receive();
}
Aggregations