diff --git a/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwin.java b/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwin.java index 39d0c94eaa..1690b5a7c4 100644 --- a/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwin.java +++ b/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwin.java @@ -342,6 +342,7 @@ else if (topic.length() > PATCH.length() && topic.startsWith(PATCH)) { message = new IotHubTransportMessage(data, MessageType.DEVICE_TWIN); message.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE); + message.setQualityOfService(messagePair.getValue().getQos()); } // Case for $iothub/twin/PATCH/properties/desired/?$version={new version} diff --git a/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwinTest.java b/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwinTest.java index a8c162eb7a..214a8559d0 100644 --- a/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwinTest.java +++ b/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttTwinTest.java @@ -904,6 +904,33 @@ public void receiveDoesNotSetVersionForDesiredPropNotifRespIfNotFound() throws T } } + @Test + public void receiveSetQosForDesiredProp() throws TransportException + { + final byte[] actualPayload = "NotificationResponseDataContainingDesiredPropertiesDocument".getBytes(StandardCharsets.UTF_8); + final String expectedTopic = "$iothub/twin/PATCH/properties/desired/"; + IotHubTransportMessage receivedMessage = null; + int expectedQualityOfService = 2; + try + { + //arrange + Queue> testreceivedMessages = new ConcurrentLinkedQueue<>(); + MqttMessage mqttMessage = new MqttMessage(actualPayload); + mqttMessage.setQos(expectedQualityOfService); + testreceivedMessages.add(new MutablePair<>(expectedTopic, mqttMessage)); + MqttTwin testTwin = new MqttTwin("", mockedConnectOptions, new HashMap<>(), testreceivedMessages); + + //act + receivedMessage = testTwin.receive(); + } + finally + { + //assert + assertNotNull(receivedMessage); + assertEquals(expectedQualityOfService, receivedMessage.getQualityOfService()); + } + } + /* **Tests_SRS_MQTTDEVICETWIN_25_042: [If the topic is of type patch for desired properties then this method shall parse further to look for version which if found is set by calling setVersion] */