Search in sources :

Example 21 with JobResult

use of com.microsoft.azure.sdk.iot.service.jobs.JobResult 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 22 with JobResult

use of com.microsoft.azure.sdk.iot.service.jobs.JobResult 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 23 with JobResult

use of com.microsoft.azure.sdk.iot.service.jobs.JobResult 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 JobResult

use of com.microsoft.azure.sdk.iot.service.jobs.JobResult 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 JobResult

use of com.microsoft.azure.sdk.iot.service.jobs.JobResult 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

JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)40 Test (org.junit.Test)27 Date (java.util.Date)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)17 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)14 TwinState (com.microsoft.azure.sdk.iot.deps.twin.TwinState)13 HashSet (java.util.HashSet)11 NonStrictExpectations (mockit.NonStrictExpectations)11 JobsParser (com.microsoft.azure.sdk.iot.deps.serializer.JobsParser)9 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)9 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)9 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)9 IOException (java.io.IOException)8 Expectations (mockit.Expectations)8 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)6 MethodParser (com.microsoft.azure.sdk.iot.deps.serializer.MethodParser)5 DeviceTestManager (tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager)5 Job (com.microsoft.azure.sdk.iot.service.devicetwin.Job)4 MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)4 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)4