From 0d1e415ff3c2d7c2da068cf10e237eb1429398dd Mon Sep 17 00:00:00 2001 From: tmahmood-microsoft Date: Wed, 22 Jun 2022 13:29:55 -0700 Subject: [PATCH 1/5] Added getter/setter for missing Twin fields Added getter/setter for missing Twin fields reported by customer (reported using Ava: 2206170060000042) Also updated unit test:: testQueryTwins() to validate the fields. --- .../serviceclient/QueryClientTests.java | 9 ++++++ .../azure/sdk/iot/service/twin/Twin.java | 28 +++++++++++++++++++ .../azure/sdk/iot/service/twin/TwinState.java | 11 ++++++++ 3 files changed, 48 insertions(+) diff --git a/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java b/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java index 6fd556c579..e653d9cbf0 100644 --- a/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java +++ b/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java @@ -121,6 +121,15 @@ public void testQueryTwins() throws IOException, IotHubException, InterruptedExc assertEquals(2, twinList.size()); assertTrue(twinList.get(0).getDeviceId().equals(deviceId1) || twinList.get(0).getDeviceId().equals(deviceId2)); assertTrue(twinList.get(1).getDeviceId().equals(deviceId1) || twinList.get(1).getDeviceId().equals(deviceId2)); + + assertNotNull(twinList.get(0).getStatus()); + assertNotNull(twinList.get(0).getConnectionState()); + assertNotNull(twinList.get(0).getLastActivityTime()); + + assertNotNull(twinList.get(1).getStatus()); + assertNotNull(twinList.get(1).getConnectionState()); + assertNotNull(twinList.get(1).getLastActivityTime()); + } finally { diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java index d70382c291..d1035e1688 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java @@ -28,6 +28,22 @@ public class Twin @Setter private String eTag; + @Getter + @Setter + private TwinStatus status; + + @Getter + @Setter + private String statusUpdateTime; + + @Getter + @Setter + private String lastActivityTime; + + @Getter + @Setter + private String cloudToDeviceMessageCount; + @Getter @Setter(AccessLevel.PACKAGE) private Integer version; @@ -78,6 +94,12 @@ public static Twin fromJson(String json) Twin twin = new Twin(twinState.getDeviceId()); twin.setVersion(twinState.getVersion()); twin.setETag(twinState.getETag()); + twin.setStatus(twinState.getStatus()); + twin.setStatusUpdateTime(twinState.getStatusUpdatedTime()); + twin.setConnectionState(twinState.getConnectionState()); + twin.setLastActivityTime(twinState.getLastActivityTime()); + twin.setCloudToDeviceMessageCount(twinState.getCloudToDeviceMessageCount()); + // Tags twin.getTags().setVersion(twinState.getTags().getVersion()); @@ -256,6 +278,12 @@ public String toString() .append("\n"); } + thisDevice.append("Status: ").append(this.status.toString()).append("\n"); + thisDevice.append("StatusUpdateTime: ").append(this.statusUpdateTime).append("\n"); + thisDevice.append("ConnectionState: ").append(this.connectionState).append("\n"); + thisDevice.append("LastActivityTime: ").append(this.lastActivityTime).append("\n"); + thisDevice.append("CloudToDeviceMessageCount:").append(this.cloudToDeviceMessageCount).append("\n"); + thisDevice.append(tagsToString()); thisDevice.append(reportedPropertiesToString()); thisDevice.append(desiredPropertiesToString()); diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java index 99c3e12d99..c99a9ad9ee 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java @@ -210,6 +210,16 @@ public class TwinState @Setter private String connectionStateUpdatedTime = null; + /** + * Cloud to device message count. + */ + private static final String CLOUD_TO_DEVICE_MESSAGE_COUNT = "cloudToDeviceMessageCount"; + @Expose + @SerializedName(CLOUD_TO_DEVICE_MESSAGE_COUNT) + @Getter + @Setter + private String cloudToDeviceMessageCount = null; + /** * Datetime of last time the device authenticated, received, or sent a message. */ @@ -453,6 +463,7 @@ public TwinState(String json) this.setStatusReason(result.getStatusReason()); this.setStatusUpdatedTime(result.getStatusUpdatedTime()); this.setVersion(result.getVersion()); + this.setCloudToDeviceMessageCount(result.cloudToDeviceMessageCount); } /** From 76cbb7792725c355e4c81ee87fa1274b1119d9e3 Mon Sep 17 00:00:00 2001 From: tmahmood-microsoft Date: Fri, 1 Jul 2022 11:27:58 -0700 Subject: [PATCH 2/5] updated data type for cloudToDeviceMessageCount updated data type for cloudToDeviceMessageCount from String to Integer --- .../java/com/microsoft/azure/sdk/iot/service/twin/Twin.java | 2 +- .../com/microsoft/azure/sdk/iot/service/twin/TwinState.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java index d1035e1688..6002c81dcf 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java @@ -42,7 +42,7 @@ public class Twin @Getter @Setter - private String cloudToDeviceMessageCount; + private Integer cloudToDeviceMessageCount; @Getter @Setter(AccessLevel.PACKAGE) diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java index c99a9ad9ee..fd8e065f79 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinState.java @@ -218,7 +218,7 @@ public class TwinState @SerializedName(CLOUD_TO_DEVICE_MESSAGE_COUNT) @Getter @Setter - private String cloudToDeviceMessageCount = null; + private Integer cloudToDeviceMessageCount = null; /** * Datetime of last time the device authenticated, received, or sent a message. From 463a90e2f2990eb4311730529d43095c9a8feab1 Mon Sep 17 00:00:00 2001 From: tmahmood-microsoft Date: Fri, 1 Jul 2022 11:33:06 -0700 Subject: [PATCH 3/5] Update Twin.java --- .../java/com/microsoft/azure/sdk/iot/service/twin/Twin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java index 6002c81dcf..e94a3e776a 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java @@ -282,7 +282,7 @@ public String toString() thisDevice.append("StatusUpdateTime: ").append(this.statusUpdateTime).append("\n"); thisDevice.append("ConnectionState: ").append(this.connectionState).append("\n"); thisDevice.append("LastActivityTime: ").append(this.lastActivityTime).append("\n"); - thisDevice.append("CloudToDeviceMessageCount:").append(this.cloudToDeviceMessageCount).append("\n"); + thisDevice.append("CloudToDeviceMessageCount:").append(this.cloudToDeviceMessageCount.toString()).append("\n"); thisDevice.append(tagsToString()); thisDevice.append(reportedPropertiesToString()); From 25a37e20e2ae26cca97430b29861dbae31095345 Mon Sep 17 00:00:00 2001 From: tmahmood-microsoft Date: Fri, 1 Jul 2022 11:46:39 -0700 Subject: [PATCH 4/5] Update Twin.java --- .../java/com/microsoft/azure/sdk/iot/service/twin/Twin.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java index e7af7dd6b0..177ca676c4 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/Twin.java @@ -277,12 +277,6 @@ public String toString() .append(String.join(",", this.parentScopes)) .append("\n"); } - - thisDevice.append("Status: ").append(this.status.toString()).append("\n"); - thisDevice.append("StatusUpdateTime: ").append(this.statusUpdateTime).append("\n"); - thisDevice.append("ConnectionState: ").append(this.connectionState).append("\n"); - thisDevice.append("LastActivityTime: ").append(this.lastActivityTime).append("\n"); - thisDevice.append("CloudToDeviceMessageCount:").append(this.cloudToDeviceMessageCount.toString()).append("\n"); if (this.status != null) { thisDevice.append("Status: ").append(this.status.toString()).append("\n"); From c85c679e37f7a4f00301c016cb339faf4eb94364 Mon Sep 17 00:00:00 2001 From: tmahmood-microsoft Date: Fri, 1 Jul 2022 14:25:31 -0700 Subject: [PATCH 5/5] Update QueryClientTests.java --- .../azure/sdk/iot/iothub/serviceclient/QueryClientTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java b/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java index e653d9cbf0..7b95ddd82a 100644 --- a/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java +++ b/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/QueryClientTests.java @@ -125,10 +125,12 @@ public void testQueryTwins() throws IOException, IotHubException, InterruptedExc assertNotNull(twinList.get(0).getStatus()); assertNotNull(twinList.get(0).getConnectionState()); assertNotNull(twinList.get(0).getLastActivityTime()); + assertNotNull(twinList.get(0).getCloudToDeviceMessageCount()); assertNotNull(twinList.get(1).getStatus()); assertNotNull(twinList.get(1).getConnectionState()); assertNotNull(twinList.get(1).getLastActivityTime()); + assertNotNull(twinList.get(0).getCloudToDeviceMessageCount()); } finally