use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method scheduleDeviceMethodThrowOnInvalidMaxExecutionTimeInSeconds.
/* Tests_SRS_JOB_21_014: [If the maxExecutionTimeInSeconds is negative, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnInvalidMaxExecutionTimeInSeconds() throws IOException {
// arrange
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
final String payload = "validPayload";
final Date now = new Date();
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 scheduleDeviceMethodThrowOnEmptyMethodName.
/* Tests_SRS_JOB_21_012: [If the methodName is null or empty, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnEmptyMethodName() throws IOException {
// arrange
final String queryCondition = "validQueryCondition";
final String methodName = "";
final String payload = "validPayload";
final Date now = new Date();
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 scheduleUpdateTwinCallJobClient.
/* Tests_SRS_JOB_21_009: [The scheduleUpdateTwin shall invoke the scheduleUpdateTwin in the JobClient class with the received parameters.] */
@Test
public void scheduleUpdateTwinCallJobClient() 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 = mockedJobResult;
times = 1;
mockedJobResult.getJobStatus();
result = JobStatus.enqueued;
}
};
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 scheduleDeviceMethodThrowOnInvokeJobClientFail.
/* Tests_SRS_JOB_21_017: [If the Iothub reported fail as result of the scheduleDeviceMethod, the scheduleDeviceMethod shall throws IotHubException.] */
@Test(expected = IotHubException.class)
public void scheduleDeviceMethodThrowOnInvokeJobClientFail() throws IOException, IotHubException {
// arrange
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
final String payload = "validPayload";
final Date now = new Date();
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.scheduleDeviceMethod((String) any, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
result = mockedJobResult;
mockedJobResult.getJobStatus();
result = JobStatus.failed;
}
};
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 scheduleUpdateTwinThrowOnNullDeviceTwinDevice.
/* Tests_SRS_JOB_21_006: [If the updateTwin is null, the scheduleUpdateTwin shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleUpdateTwinThrowOnNullDeviceTwinDevice() throws IOException {
// arrange
final String queryCondition = "validQueryCondition";
final DeviceTwinDevice deviceTwin = null;
final Date now = new Date();
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
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);
}
Aggregations