Search in sources :

Example 16 with TwinCollection

use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection 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 17 with TwinCollection

use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection 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 18 with TwinCollection

use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection in project azure-iot-sdk-java by Azure.

the class JobResultTest method gettersEmptyOutcome.

/* Tests_SRS_JOBRESULT_25_021: [The getOutcomeResult shall return the stored outcome.] */
@Test
public void gettersEmptyOutcome(@Mocked MethodParser mockedMethodParser) throws IOException {
    // arrange
    final String json = "validJson";
    final Date now = new Date();
    MethodParser methodParser = new MethodParser("methodName", null, null, new TwinCollection());
    JobsResponseParserExpectations(json, null, methodParser, now, mockedMethodParser, "scheduleUpdateTwin");
    new NonStrictExpectations() {

        {
            JobsResponseParser.createFromJson(json);
            result = mockedJobsResponseParser;
            mockedJobsResponseParser.getJobId();
            result = JOB_ID;
            mockedJobsResponseParser.getType();
            result = "scheduleDeviceMethod";
            mockedJobsResponseParser.getJobsStatus();
            result = "completed";
            mockedJobsResponseParser.getCloudToDeviceMethod();
            result = methodParser;
            mockedJobsResponseParser.getOutcome();
            result = mockedMethodParser;
            mockedMethodParser.toJson();
            result = json;
            mockedMethodParser.getStatus();
            result = new IllegalArgumentException();
            Deencapsulation.newInstance(JobStatistics.class, mockedJobsStatisticsParser);
            result = mockedJobStatistics;
        }
    };
    // act
    JobResult jobResult = Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, json.getBytes(StandardCharsets.UTF_8));
    // assert
    assertNull(jobResult.getOutcomeResult());
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Date(java.util.Date) MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 19 with TwinCollection

use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection in project azure-iot-sdk-java by Azure.

the class JobResultTest method gettersMethodContent.

/* Tests_SRS_JOBRESULT_21_013: [The getCloudToDeviceMethod shall return the stored cloudToDeviceMethod.] */
/* Tests_SRS_JOBRESULT_25_020: [The getLastUpdatedDateTime shall return the stored LastUpdatedDateTime.] */
/* Tests_SRS_JOBRESULT_25_021: [The getOutcomeResult shall return the stored outcome.] */
/* Tests_SRS_JOBRESULT_25_022: [The getError shall return the stored error message.] */
@Test
public void gettersMethodContent(@Mocked MethodParser mockedMethodParser) throws IOException {
    // arrange
    final String json = "validJson";
    final String methodReturnPayload = "validResult";
    final int methodReturnStatus = 200;
    final Date now = new Date();
    MethodParser methodParser = new MethodParser("methodName", null, null, new TwinCollection());
    JobsResponseParserExpectations(json, null, methodParser, now, mockedMethodParser, "scheduleUpdateTwin");
    new NonStrictExpectations() {

        {
            JobsResponseParser.createFromJson(json);
            result = mockedJobsResponseParser;
            mockedJobsResponseParser.getJobId();
            result = JOB_ID;
            mockedJobsResponseParser.getType();
            result = "scheduleDeviceMethod";
            mockedJobsResponseParser.getJobsStatus();
            result = "completed";
            mockedJobsResponseParser.getCloudToDeviceMethod();
            result = methodParser;
            mockedJobsResponseParser.getOutcome();
            result = mockedMethodParser;
            mockedMethodParser.toJson();
            result = json;
            mockedMethodParser.getStatus();
            result = methodReturnStatus;
            mockedMethodParser.getPayload();
            result = methodReturnPayload;
            Deencapsulation.newInstance(JobStatistics.class, mockedJobsStatisticsParser);
            result = mockedJobStatistics;
        }
    };
    // act
    JobResult jobResult = Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, json.getBytes(StandardCharsets.UTF_8));
    // assert
    assertEquals(JOB_ID, jobResult.getJobId());
    assertEquals(JobType.scheduleDeviceMethod, jobResult.getJobType());
    assertEquals(JobStatus.completed, jobResult.getJobStatus());
    assertNotNull(jobResult.getCloudToDeviceMethod());
    assertNotNull(jobResult.getOutcome());
    MethodResult methodResult = jobResult.getOutcomeResult();
    assertEquals(methodReturnStatus, (long) methodResult.getStatus());
    assertEquals(methodReturnPayload, methodResult.getPayload());
    assertNotNull(jobResult.getLastUpdatedDateTime());
    assertNull(jobResult.getError());
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Date(java.util.Date) MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 20 with TwinCollection

use of com.microsoft.azure.sdk.iot.deps.twin.TwinCollection 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)

Aggregations

TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)23 Test (org.junit.Test)20 TwinState (com.microsoft.azure.sdk.iot.deps.twin.TwinState)12 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)9 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)9 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)9 Date (java.util.Date)9 NonStrictExpectations (mockit.NonStrictExpectations)9 Verifications (mockit.Verifications)5 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)3 Expectations (mockit.Expectations)3 StrictExpectations (mockit.StrictExpectations)3 MethodParser (com.microsoft.azure.sdk.iot.deps.serializer.MethodParser)2 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)2 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)2 SimpleDateFormat (java.text.SimpleDateFormat)2 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)1 Pair (com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair)1 TwinPropertiesCallback (com.microsoft.azure.sdk.iot.device.DeviceTwin.TwinPropertiesCallback)1 ModuleClient (com.microsoft.azure.sdk.iot.device.ModuleClient)1