use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection in project azure-iot-sdk-java by Azure.
the class JobResultTest method toStringReturnClassContent.
/* Tests_SRS_JOBRESULT_21_020: [The toString shall return a String with a pretty print json that represents this class.] */
@Test
public void toStringReturnClassContent() throws IOException {
// arrange
final String json = "validJson";
final Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT_JSON);
String nowString = dateFormat.format(now);
final String expectedPrettyPrint = "{\n" + " \"jobId\": \"validJobId\",\n" + " \"queryCondition\": \"DeviceId IN ['validDevice']\",\n" + " \"createdTime\": \"" + nowString + "\",\n" + " \"startTime\": \"" + nowString + "\",\n" + " \"lastUpdatedDateTime\": \"" + nowString + "\",\n" + " \"endTime\": \"" + nowString + "\",\n" + " \"maxExecutionTimeInSeconds\": 100,\n" + " \"jobType\": \"scheduleUpdateTwin\",\n" + " \"jobStatus\": \"enqueued\",\n" + " \"updateTwin\": {\n" + " \"deviceId\": \"validDeviceId\",\n" + " \"eTag\": \"validETag\",\n" + " \"tag\": {\n" + " \"tag1\": \"val1\"\n" + " },\n" + " \"desiredProperties\": {},\n" + " \"parentScopes\": []\n" + " },\n" + " \"failureReason\": \"This is a valid failure reason\",\n" + " \"statusMessage\": \"This is a valid status message\",\n" + " \"jobStatistics\": {\n" + " \"deviceCount\": 0,\n" + " \"failedCount\": 0,\n" + " \"succeededCount\": 0,\n" + " \"runningCount\": 0,\n" + " \"pendingCount\": 0\n" + " },\n" + " \"deviceId\": \"validDeviceId\",\n" + " \"parentJobId\": \"validParentJobId\"\n" + "}";
TwinCollection tags = new TwinCollection();
tags.putFinal("tag1", "val1");
TwinState twinState = new TwinState(tags, null, null);
twinState.setDeviceId(DEVICE_ID);
twinState.setETag(ETAG);
JobsResponseParserExpectations(json, twinState, null, now, null, "scheduleUpdateTwin");
JobResult jobResult = Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, json.getBytes(StandardCharsets.UTF_8));
// act
String prettyPrint = jobResult.toString();
// assert
assertThat(prettyPrint, is(expectedPrettyPrint));
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection in project azure-iot-sdk-java by Azure.
the class JobResultTest method constructorStoreJsonContent.
/* Tests_SRS_JOBRESULT_21_004: [The constructor shall locally store all results information in the provided body.] */
@Test
public void constructorStoreJsonContent() throws IOException {
// arrange
final String json = "validJson";
final Date now = new Date();
TwinCollection tags = new TwinCollection();
tags.putFinal("tag1", "val1");
TwinState twinState = new TwinState(tags, null, null);
twinState.setDeviceId(DEVICE_ID);
twinState.setETag(ETAG);
JobsResponseParserExpectations(json, twinState, null, now, null, "scheduleUpdateTwin");
// act
JobResult jobResult = Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, json.getBytes(StandardCharsets.UTF_8));
// assert
assertEquals(JOB_ID, Deencapsulation.getField(jobResult, "jobId"));
assertEquals(QUERY_CONDITION, Deencapsulation.getField(jobResult, "queryCondition"));
assertEquals(now, Deencapsulation.getField(jobResult, "createdTime"));
assertEquals(now, Deencapsulation.getField(jobResult, "startTime"));
assertEquals(now, Deencapsulation.getField(jobResult, "endTime"));
assertEquals(MAX_EXECUTION_TIME_IN_SECONDS, (long) Deencapsulation.getField(jobResult, "maxExecutionTimeInSeconds"));
assertEquals(JobType.scheduleUpdateTwin, Deencapsulation.getField(jobResult, "jobType"));
assertEquals(JobStatus.enqueued, Deencapsulation.getField(jobResult, "jobStatus"));
assertNull(Deencapsulation.getField(jobResult, "cloudToDeviceMethod"));
assertNotNull(Deencapsulation.getField(jobResult, "updateTwin"));
assertEquals(FAILURE_REASON, Deencapsulation.getField(jobResult, "failureReason"));
assertEquals(STATUS_MESSAGE, Deencapsulation.getField(jobResult, "statusMessage"));
assertNotNull(Deencapsulation.getField(jobResult, "jobStatistics"));
assertEquals(DEVICE_ID, Deencapsulation.getField(jobResult, "deviceId"));
assertEquals(PARENT_JOB_ID, Deencapsulation.getField(jobResult, "parentJobId"));
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection in project azure-iot-sdk-java by Azure.
the class DesiredPropertiesTests method testSubscribeToDesiredPropertiesBatch.
// This test is for the startDeviceTwin/startTwin API that takes the TwinPropertiesCallback rather than the TwinPropertyCallback
// This callback should receive the full twin update in one callback, rather than one callback per updated
// desired property
@Test
@StandardTierHubOnlyTest
public void testSubscribeToDesiredPropertiesBatch() throws Exception {
super.setUpNewDeviceAndModule(false);
String expectedKey1 = UUID.randomUUID().toString();
String expectedValue1 = UUID.randomUUID().toString();
String expectedKey2 = UUID.randomUUID().toString();
String expectedValue2 = UUID.randomUUID().toString();
TwinCollection expectedDesiredProperties = new TwinCollection();
expectedDesiredProperties.putFinal(expectedKey1, expectedValue1);
expectedDesiredProperties.putFinal(expectedKey2, expectedValue2);
TwinPropertiesCallback twinPropertiesCallback = new TwinPropertiesCallbackImpl(expectedDesiredProperties);
Success desiredPropertiesCallbackState = new Success();
testInstance.testIdentity.getClient().open();
if (testInstance.testIdentity.getClient() instanceof DeviceClient) {
((DeviceClient) testInstance.testIdentity.getClient()).startDeviceTwin(new DeviceTwinStatusCallBack(), testInstance.deviceUnderTest, twinPropertiesCallback, desiredPropertiesCallbackState);
} else {
((ModuleClient) testInstance.testIdentity.getClient()).startTwin(new DeviceTwinStatusCallBack(), testInstance.deviceUnderTest, twinPropertiesCallback, desiredPropertiesCallbackState);
}
long startTime = System.currentTimeMillis();
while (testInstance.deviceUnderTest.deviceTwinStatus != IotHubStatusCode.OK) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > START_TWIN_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for twin to start");
}
}
DeviceTwinDevice serviceClientTwin;
if (testInstance.clientType == ClientType.DEVICE_CLIENT) {
serviceClientTwin = new DeviceTwinDevice(testInstance.testIdentity.getClient().getConfig().getDeviceId());
} else {
serviceClientTwin = new DeviceTwinDevice(testInstance.testIdentity.getClient().getConfig().getDeviceId(), testInstance.testIdentity.getClient().getConfig().getModuleId());
}
Set<com.microsoft.azure.sdk.iot.service.devicetwin.Pair> desiredProperties = new HashSet<>();
desiredProperties.add(new com.microsoft.azure.sdk.iot.service.devicetwin.Pair(expectedKey1, expectedValue1));
desiredProperties.add(new com.microsoft.azure.sdk.iot.service.devicetwin.Pair(expectedKey2, expectedValue2));
serviceClientTwin.setDesiredProperties(desiredProperties);
testInstance.twinServiceClient.updateTwin(serviceClientTwin);
startTime = System.currentTimeMillis();
while (!desiredPropertiesCallbackState.wasCallbackFired()) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > DESIRED_PROPERTIES_PROPAGATION_TIME_MILLISECONDS) {
fail("Timed out waiting for desired properties callback to execute");
}
}
assertTrue("Desired properties callback executed, but with unexpected properties", desiredPropertiesCallbackState.getResult());
}
Aggregations