use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobTest method constructor1CreateJobClient.
/* Tests_SRS_JOB_21_004: [The constructor shall create a new instance of JobClient to manage the Job.] */
@Test
public void constructor1CreateJobClient() throws IOException {
// arrange
final String connectionString = "validConnectionString";
// act
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// assert
assertNotNull(Deencapsulation.getField(job, "jobClient"));
new Verifications() {
{
new JobClient(connectionString);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobTest method constructor1ThrowOnJobClientCreation.
/* Tests_SRS_JOB_21_005: [The constructor shall throw IOException if it failed to create a new instance of the JobClient. Threw by the JobClient constructor.] */
@Test(expected = IOException.class)
public void constructor1ThrowOnJobClientCreation() throws IOException {
// arrange
final String connectionString = "validConnectionString";
new NonStrictExpectations() {
{
new JobClient(connectionString);
result = new IOException();
times = 1;
}
};
// act
Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method scheduleDeviceMethodSendPUT.
/* Tests_SRS_JOBCLIENT_21_020: [The scheduleDeviceMethod shall send a PUT request to the iothub using the created url and json.] */
@Test
public void scheduleDeviceMethodSendPUT() 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 = new Date();
final long maxExecutionTimeInSeconds = 10;
final String json = "validJson";
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
new MethodParser(methodName, null, null, payload);
result = mockedMethodParser;
new JobsParser(jobId, mockedMethodParser, 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
testJobClient.scheduleDeviceMethod(jobId, queryCondition, methodName, null, null, payload, startTimeUtc, maxExecutionTimeInSeconds);
// assert
new Verifications() {
{
DeviceOperations.request(anyString, mockedURL, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), (String) any, anyInt, anyInt, (Proxy) any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method scheduleDeviceMethodThrowsOnNullMethodName.
/* Tests_SRS_JOBCLIENT_21_015: [If the methodName is null or empty, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowsOnNullMethodName() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "ValidJobId";
final String queryCondition = "validQueryCondition";
final String methodName = null;
final Set<String> payload = new HashSet<>();
final Date startTimeUtc = new Date();
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 constructorSucceed.
/* Tests_SRS_JOBCLIENT_21_002: [The constructor shall create an IotHubConnectionStringBuilder object from the given connection string.] */
/* Tests_SRS_JOBCLIENT_21_003: [The constructor shall create a new DeviceMethod instance and return it.] */
@Test
public void constructorSucceed() throws IOException {
// arrange
final String connectionString = "testString";
// act
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
// assert
assertNotNull(testJobClient);
}
Aggregations