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());
}
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());
}
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());
}
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));
}
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"));
}
Aggregations