use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method getInvokeJobClient.
/* Tests_SRS_JOB_21_018: [The get shall invoke getJob on JobClient with the current jobId and return its result.] */
@Test
public void getInvokeJobClient() throws IOException, IotHubException {
// arrange
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.getJob((String) any);
result = mockedJobResult;
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
JobResult jobResult = job.get();
// assert
assertNotNull(jobResult);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method constructorCreateUniqueJobId.
/* Tests_SRS_JOB_21_003: [If no jobId is provided, the constructor shall generate a unique jobId to identify the Job in the Iothub.] */
@Test
public void constructorCreateUniqueJobId() {
// arrange
final String connectionString = "validConnectionString";
// act
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// assert
assertNotNull(Deencapsulation.getField(job, "jobId"));
assertFalse(Deencapsulation.getField(job, "jobId").toString().isEmpty());
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method scheduleUpdateTwinThrowOnScheduleUpdateTwin.
/* Tests_SRS_JOB_21_010: [If scheduleUpdateTwin failed, the scheduleUpdateTwin shall throws IotHubException. Threw by the scheduleUpdateTwin.] */
@Test(expected = IotHubException.class)
public void scheduleUpdateTwinThrowOnScheduleUpdateTwin() throws IOException, IotHubException {
// arrange
final String queryCondition = "validQueryCondition";
final DeviceTwinDevice deviceTwin = mockedDeviceTwinDevice;
final Date now = new Date();
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.scheduleUpdateTwin((String) any, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
result = new IotHubException();
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
Deencapsulation.invoke(job, "scheduleUpdateTwin", new Class[] { String.class, DeviceTwinDevice.class, Date.class, Long.class }, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method scheduleDeviceMethodThrowOnNullStartTimeUtc.
/* Tests_SRS_JOB_21_013: [If the startTimeUtc is null, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnNullStartTimeUtc() throws IOException {
// arrange
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
final String payload = "validPayload";
final Date now = null;
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
Deencapsulation.invoke(job, "scheduleDeviceMethod", new Class[] { String.class, String.class, Long.class, Long.class, Object.class, Date.class, Long.class }, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method cancelInvokeJobClient.
/* Tests_SRS_JOB_21_020: [The cancel shall invoke cancelJob on JobClient with the current jobId and return its result.] */
@Test
public void cancelInvokeJobClient() throws IOException, IotHubException {
// arrange
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.cancelJob((String) any);
result = mockedJobResult;
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
JobResult jobResult = job.cancel();
// assert
assertNotNull(jobResult);
}
Aggregations