use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method scheduleDeviceMethodThrowsOnNullStartTimeUtc.
/* Tests_SRS_JOBCLIENT_21_016: [If the startTimeUtc is null, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowsOnNullStartTimeUtc() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "ValidJobId";
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
final Set<String> payload = new HashSet<>();
final Date startTimeUtc = null;
final long maxExecutionTimeInSeconds = 10;
JobClient testJobClient = null;
try {
testJobClient = JobClient.createFromConnectionString(connectionString);
} catch (IllegalArgumentException e) {
assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
}
// act
testJobClient.scheduleDeviceMethod(jobId, queryCondition, methodName, null, null, payload, startTimeUtc, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method scheduleUpdateTwinCreateJsonWithEtag.
/* Tests_SRS_JOBCLIENT_21_004: [The scheduleUpdateTwin shall create a json String that represent the twin job using the JobsParser class.] */
@Test
public void scheduleUpdateTwinCreateJsonWithEtag() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
final String deviceId = "validDeviceId";
final String queryCondition = "validQueryCondition";
final DeviceTwinDevice updateTwin = mockedDeviceTwinDevice;
final Date startTimeUtc = new Date();
final long maxExecutionTimeInSeconds = 10;
final String json = "validJson";
Set<Pair> testTags = new HashSet<>();
testTags.add(new Pair("testTag", "tagObject"));
new Expectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
mockedDeviceTwinDevice.getTags();
result = testTags;
mockedDeviceTwinDevice.getDesiredProperties();
result = null;
mockedDeviceTwinDevice.getReportedProperties();
result = null;
new TwinState((TwinCollection) any, null, null);
result = mockedTwinState;
mockedDeviceTwinDevice.getDeviceId();
result = deviceId;
mockedDeviceTwinDevice.getETag();
result = "1234";
new JobsParser(jobId, mockedTwinState, queryCondition, startTimeUtc, maxExecutionTimeInSeconds);
result = mockedJobsParser;
mockedJobsParser.toJson();
result = json;
IotHubConnectionString.getUrlJobs(anyString, jobId);
result = mockedURL;
DeviceOperations.request(anyString, mockedURL, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), (String) any, anyInt, anyInt, (Proxy) any);
result = mockedHttpResponse;
Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, (byte[]) any);
result = mockedJobResult;
}
};
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
// act
JobResult jobResult = testJobClient.scheduleUpdateTwin(jobId, queryCondition, updateTwin, startTimeUtc, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method getJobThrowsOnEmptyJobId.
/* Tests_SRS_JOBCLIENT_21_024: [If the JobId is null, empty, or invalid, the getJob shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void getJobThrowsOnEmptyJobId() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "";
JobClient testJobClient = null;
try {
testJobClient = JobClient.createFromConnectionString(connectionString);
} catch (IllegalArgumentException e) {
assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
}
// act
testJobClient.getJob(jobId);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method getJobThrowsOnNullJobId.
/* Tests_SRS_JOBCLIENT_21_024: [If the JobId is null, empty, or invalid, the getJob shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void getJobThrowsOnNullJobId() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = null;
JobClient testJobClient = null;
try {
testJobClient = JobClient.createFromConnectionString(connectionString);
} catch (IllegalArgumentException e) {
assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
}
// act
testJobClient.getJob(jobId);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method cancelJobParseResponse.
/* Tests_SRS_JOBCLIENT_21_035: [The cancelJob shall parse the iothub response and return it as JobResult.] */
@Test
public void cancelJobParseResponse() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
JobClient testJobClient = null;
new Expectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
IotHubConnectionString.getUrlJobsCancel(anyString, jobId);
result = mockedURL;
DeviceOperations.request(anyString, mockedURL, (HttpMethod) any, (byte[]) any, (String) any, anyInt, anyInt, (Proxy) any);
result = mockedHttpResponse;
Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, (byte[]) any);
result = mockedJobResult;
}
};
try {
testJobClient = JobClient.createFromConnectionString(connectionString);
} catch (IllegalArgumentException e) {
assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
}
// act
JobResult jobResult = testJobClient.cancelJob(jobId);
// assert
assertNotNull(jobResult);
}
Aggregations