use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodMessageTest method constructorSucceeds.
/*
**Tests_SRS_DEVICEMETHODMESSAGE_25_001: [**The constructor shall save the message body by calling super with the body as parameter.**]**
**Tests_SRS_DEVICEMETHODMESSAGE_25_002: [**If the message body is null, the constructor shall throw an IllegalArgumentException thrown by base constructor.**]**
*/
@Test
public void constructorSucceeds() {
//act
DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
//assert
assertTrue(testDMMessage.getMessageType() == MessageType.DeviceMethods);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodMessageTest method setMethodNameSets.
/*
**Tests_SRS_DEVICEMETHODMESSAGE_25_003: [**This method shall set the methodName.**]**
*/
@Test
public void setMethodNameSets() {
//arrange
DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
//act
testDMMessage.setMethodName("TestName");
//assert
assertEquals(testDMMessage.getMethodName(), "TestName");
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class DeviceMethodMessageTest method setMethodNameThrowsOnNull.
/*
**Tests_SRS_DEVICEMETHODMESSAGE_25_004: [**This method shall throw IllegalArgumentException if the methodName is null.**]**
*/
@Test(expected = IllegalArgumentException.class)
public void setMethodNameThrowsOnNull() {
//arrange
DeviceMethodMessage testDMMessage = new DeviceMethodMessage(new byte[0]);
//act
testDMMessage.setMethodName(null);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendSucceedsCallsSubscribe.
/*
Tests_SRS_MqttDeviceMethod_25_004: [**parseTopic shall look for the method topic($iothub/methods) prefix from received message queue as per spec and if found shall return it as string.**]**
Tests_SRS_MqttDeviceMethod_25_005: [**If none of the topics from the received queue match the methods topic prefix then this method shall return null string .**]**
Tests_SRS_MqttDeviceMethod_25_006: [**If received messages queue is empty then parseTopic shall return null string.**]**
Tests_SRS_MqttDeviceMethod_25_020: [**send method shall subscribe to topic from spec ($iothub/methods/POST/#) if the operation is of type DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST.**]**
*/
@Test
public void sendSucceedsCallsSubscribe() throws IOException {
//arrange
final String actualSubscribeTopic = "$iothub/methods/POST/#";
byte[] actualPayload = "TestMessage".getBytes();
DeviceMethodMessage testMessage = new DeviceMethodMessage(actualPayload);
testMessage.setDeviceOperationType(DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST);
MqttDeviceMethod testMethod = new MqttDeviceMethod();
testMethod.start();
//act
testMethod.send(testMessage);
//assert
new Verifications() {
{
Deencapsulation.invoke(mockedMqtt, "subscribe", actualSubscribeTopic);
maxTimes = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage 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());
}
Aggregations