use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage 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.DeviceTwin.DeviceMethodMessage 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);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method receiveReturnsEmptyPayLoadIfNullPayloadParsed.
@Test
public void receiveReturnsEmptyPayLoadIfNullPayloadParsed() throws IOException {
//arrange
String topic = "$iothub/methods/POST/testMethod/?$rid=10";
byte[] actualPayload = "".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.getBytes().length == 0);
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.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class MqttDeviceMethodTest method sendThrowsOnMismatchedRequestType.
/*
Tests_SRS_MqttDeviceMethod_25_019: [**send method shall throw an IoException if the getDeviceOperationType() is not of type DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST or DEVICE_OPERATION_METHOD_SEND_RESPONSE .**]**
*/
@Test(expected = IOException.class)
public void sendThrowsOnMismatchedRequestType() 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_SUBSCRIBE_REQUEST);
Deencapsulation.setField(testMethod, "requestMap", testRequestMap);
testMethod.start();
//act
testMethod.send(testMessage);
}
use of com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method receiveDeviceMethodMessageSucceeds.
@Test
public void receiveDeviceMethodMessageSucceeds() throws IOException {
baseExpectations();
openExpectations();
final byte[] expectedMessageBody = { 0x61, 0x62, 0x63 };
new NonStrictExpectations() {
{
mockDeviceMethods.receive();
result = new DeviceMethodMessage(expectedMessageBody);
}
};
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
Message message = connection.receiveMessage();
byte[] actualMessageBody = message.getBytes();
assertNotNull(message);
for (int i = 0; i < expectedMessageBody.length; i++) {
assertEquals(expectedMessageBody[i], actualMessageBody[i]);
}
new Verifications() {
{
mockDeviceMethods.receive();
times = 1;
mockDeviceTwin.receive();
times = 0;
mockDeviceMessaging.receive();
times = 0;
}
};
}
Aggregations