use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveThrowsIfRIDCouldNotBeParsed.
/*
Tests_SRS_MqttDeviceMethod_25_031: [**If request id is not found or is null then receive shall throw IOException **]**
*/
@Test(expected = IOException.class)
public void receiveThrowsIfRIDCouldNotBeParsed() throws IOException {
//arrange
String topic = "$iothub/methods/POST/testMethod/";
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();
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendSucceedsCallsPublish.
/*
Tests_SRS_MqttDeviceMethod_25_022: [**send method shall build the publish topic of the format mentioned in spec ($iothub/methods/res/{status}/?$rid={request id}) and publish if the operation is of type DEVICE_OPERATION_METHOD_SEND_RESPONSE.**]**
*/
@Test
public void sendSucceedsCallsPublish() throws IOException {
final byte[] actualPayload = "TestMessage".getBytes();
final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SEND_RESPONSE);
testMessage.setRequestId("ReqId");
testMessage.setStatus("testStatus");
MqttDeviceMethod testMethod = new MqttDeviceMethod();
Map<String, DeviceOperations> testRequestMap = new HashMap<>();
testRequestMap.put("ReqId", DEVICE_OPERATION_METHOD_RECEIVE_REQUEST);
Deencapsulation.setField(testMethod, "requestMap", testRequestMap);
testMethod.start();
//act
testMethod.send(testMessage);
//assert
new Verifications() {
{
Deencapsulation.invoke(mockedMqtt, "publish", anyString, actualPayload);
maxTimes = 1;
}
};
assertTrue(testRequestMap.isEmpty());
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendThrowsOnInvalidOperation.
@Test(expected = IOException.class)
public void sendThrowsOnInvalidOperation() throws IOException {
final byte[] actualPayload = "TestMessage".getBytes();
final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
testMessage.setDeviceOperationType(DEVICE_OPERATION_UNKNOWN);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//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 constructorSucceeds.
/*
Tests_SRS_MqttDeviceMethod_25_001: [**The constructor shall instantiate super class without any parameters.**]**
Tests_SRS_MqttDeviceMethod_25_002: [**The constructor shall create subscribe and response topics strings for device methods as per the spec.**]**
*/
@Test
public void constructorSucceeds() throws IOException {
//arrange
String actualSubscribeTopic = "$iothub/methods/POST/#";
String actualResTopic = "$iothub/methods/res";
//act
MqttDeviceMethod testMethod = new MqttDeviceMethod();
//assert
String testSubscribeTopic = Deencapsulation.getField(testMethod, "subscribeTopic");
String testResTopic = Deencapsulation.getField(testMethod, "responseTopic");
assertNotNull(testSubscribeTopic);
assertNotNull(testResTopic);
assertTrue(testSubscribeTopic.equals(actualSubscribeTopic));
assertTrue(testResTopic.equals(actualResTopic));
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendThrowsOnSendingResponseWithoutReceivingMethodInvoke.
/*
Tests_SRS_MqttDeviceMethod_25_023: [**send method shall throw an exception if a response is sent without having a method invoke on the request id if the operation is of type DEVICE_OPERATION_METHOD_SEND_RESPONSE.**]**
*/
@Test(expected = IOException.class)
public void sendThrowsOnSendingResponseWithoutReceivingMethodInvoke() throws IOException {
final byte[] actualPayload = "TestMessage".getBytes();
final DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SEND_RESPONSE);
testMessage.setRequestId("ReqId");
testMessage.setStatus("testStatus");
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
testMethod.send(testMessage);
}
Aggregations