use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobResultTest method toStringReturnJobTypeUnknown.
/* Tests_SRS_JOBRESULT_21_020: [The toString shall return a String with a pretty print json that represents this class.] */
@Test
public void toStringReturnJobTypeUnknown() 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\": \"unknown\",\n" + " \"jobStatus\": \"enqueued\",\n" + " \"updateTwin\": {\n" + " \"deviceId\": \"validDeviceId\",\n" + " \"eTag\": \"validETag\",\n" + " \"tag\": {\n" + " \"tag1\": \"val1\"\n" + " },\n" + " \"desiredProperties\": {\n" + " \"key1\": \"val1\"\n" + " },\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");
TwinCollection desired = new TwinCollection();
desired.putFinal("key1", "val1");
TwinState twinState = new TwinState(tags, desired, null);
twinState.setDeviceId(DEVICE_ID);
twinState.setETag(ETAG);
JobsResponseParserExpectations(json, twinState, null, now, null, "unknown");
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.TwinState in project azure-iot-sdk-java by Azure.
the class JobResultTest method gettersTwinContent.
/* Tests_SRS_JOBRESULT_21_005: [The getJobId shall return the stored jobId.] */
/* Tests_SRS_JOBRESULT_21_006: [The getQueryCondition shall return the stored queryCondition.] */
/* Tests_SRS_JOBRESULT_21_007: [The getCreatedTime shall return the stored createdTime.] */
/* Tests_SRS_JOBRESULT_21_008: [The getStartTime shall return the stored startTime.] */
/* Tests_SRS_JOBRESULT_21_009: [The getEndTime shall return the stored endTime.] */
/* Tests_SRS_JOBRESULT_21_010: [The getMaxExecutionTimeInSeconds shall return the stored maxExecutionTimeInSeconds.] */
/* Tests_SRS_JOBRESULT_21_011: [The getType shall return the stored jobType.] */
/* Tests_SRS_JOBRESULT_21_012: [The getJobStatus shall return the stored jobStatus.] */
/* Tests_SRS_JOBRESULT_21_014: [The getUpdateTwin shall return the stored updateTwin.] */
/* Tests_SRS_JOBRESULT_21_015: [The getFailureReason shall return the stored failureReason.] */
/* Tests_SRS_JOBRESULT_21_016: [The getStatusMessage shall return the stored statusMessage.] */
/* Tests_SRS_JOBRESULT_21_017: [The getJobStatistics shall return the stored jobStatistics.] */
/* Tests_SRS_JOBRESULT_21_018: [The getDeviceId shall return the stored deviceId.] */
/* Tests_SRS_JOBRESULT_21_019: [The getParentJobId shall return the stored parentJobId.] */
@Test
public void gettersTwinContent() 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, jobResult.getJobId());
assertEquals(QUERY_CONDITION, jobResult.getQueryCondition());
assertEquals(now, jobResult.getCreatedTime());
assertEquals(now, jobResult.getStartTime());
assertEquals(now, jobResult.getEndTime());
assertEquals(MAX_EXECUTION_TIME_IN_SECONDS, (long) jobResult.getMaxExecutionTimeInSeconds());
assertEquals(JobType.scheduleUpdateTwin, jobResult.getJobType());
assertEquals(JobStatus.enqueued, jobResult.getJobStatus());
assertNull(jobResult.getCloudToDeviceMethod());
assertNotNull(jobResult.getUpdateTwin());
assertEquals(FAILURE_REASON, jobResult.getFailureReason());
assertEquals(STATUS_MESSAGE, jobResult.getStatusMessage());
assertNotNull(jobResult.getJobStatistics());
assertEquals(DEVICE_ID, jobResult.getDeviceId());
assertEquals(PARENT_JOB_ID, jobResult.getParentJobId());
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobResultTest method gettersTwinContentWithNullDeviceId.
/* Tests_SRS_JOBRESULT_21_021: [The getUpdateTwin shall return the nullable deviceId.] */
@Test
public void gettersTwinContentWithNullDeviceId() 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.setETag(ETAG);
jobsResponseParserWithNullDeviceIdExpectations(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, jobResult.getJobId());
assertEquals(QUERY_CONDITION, jobResult.getQueryCondition());
assertEquals(now, jobResult.getCreatedTime());
assertEquals(now, jobResult.getStartTime());
assertEquals(now, jobResult.getEndTime());
assertEquals(MAX_EXECUTION_TIME_IN_SECONDS, (long) jobResult.getMaxExecutionTimeInSeconds());
assertEquals(JobType.scheduleUpdateTwin, jobResult.getJobType());
assertEquals(JobStatus.enqueued, jobResult.getJobStatus());
assertNull(jobResult.getCloudToDeviceMethod());
assertNotNull(jobResult.getUpdateTwin());
assertEquals(FAILURE_REASON, jobResult.getFailureReason());
assertEquals(STATUS_MESSAGE, jobResult.getStatusMessage());
assertNotNull(jobResult.getJobStatistics());
assertNull(jobResult.getDeviceId());
assertNull(jobResult.getUpdateTwin().getDeviceId());
assertEquals(PARENT_JOB_ID, jobResult.getParentJobId());
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState 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.TwinState 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"));
}
Aggregations