Search in sources :

Example 21 with TwinState

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));
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 22 with TwinState

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());
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Date(java.util.Date) Test(org.junit.Test)

Example 23 with TwinState

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());
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Date(java.util.Date) Test(org.junit.Test)

Example 24 with TwinState

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));
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 25 with TwinState

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"));
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TwinState (com.microsoft.azure.sdk.iot.deps.twin.TwinState)36 Test (org.junit.Test)31 Date (java.util.Date)27 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)15 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)13 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)12 NonStrictExpectations (mockit.NonStrictExpectations)12 JobsParser (com.microsoft.azure.sdk.iot.deps.serializer.JobsParser)8 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)8 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)8 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)8 HashSet (java.util.HashSet)8 Expectations (mockit.Expectations)5 Verifications (mockit.Verifications)5 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)4 Proxy (java.net.Proxy)3 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2