use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method queryJobResponseSucceeds.
/*
Tests_SRS_JOBCLIENT_25_043: [If the pageSize is not specified, default pageSize of 100 shall be used.] SRS_JOBCLIENT_25_044: [The queryDeviceJob shall create a query object for the type JOB_RESPONSE.]
Tests_SRS_JOBCLIENT_25_045: [The queryDeviceJob shall send a query request on the query object using Query URL, HTTP GET method and wait for the response by calling sendQueryRequest.]
*/
@Test
public void queryJobResponseSucceeds(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new Expectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { Integer.class, QueryType.class }, anyInt, QueryType.JOB_RESPONSE);
result = mockedQuery;
}
};
// act
testJobClient.queryJobResponse(JOB_TYPE_DEFAULT, JOB_STATUS_DEFAULT);
// assert
new Verifications() {
{
mockedQuery.sendQueryRequest((TokenCredentialCache) any, (AzureSasCredential) any, (IotHubConnectionString) any, (URL) any, HttpMethod.GET, 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 cancelJobThrowsOnSendPOST.
/* Tests_SRS_JOBCLIENT_21_033: [If the cancelJob failed to send a POST request, it shall throw IOException.] */
/* Tests_SRS_JOBCLIENT_21_034: [If the cancelJob failed to verify the iothub response, it shall throw IotHubException.] */
@Test(expected = IOException.class)
public void cancelJobThrowsOnSendPOST() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
JobClient testJobClient = null;
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
IotHubConnectionString.getUrlJobsCancel(anyString, jobId);
result = mockedURL;
DeviceOperations.request(anyString, mockedURL, HttpMethod.POST, (byte[]) any, (String) any, anyInt, anyInt, (Proxy) any);
result = new IOException();
}
};
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.cancelJob(jobId);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method cancelJobThrowsOnInvalidJobId.
/* Tests_SRS_JOBCLIENT_21_030: [If the JobId is null, empty, or invalid, the cancelJob shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void cancelJobThrowsOnInvalidJobId() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "invalidJobId";
JobClient testJobClient = null;
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
IotHubConnectionString.getUrlJobsCancel(anyString, jobId);
result = new MalformedURLException();
}
};
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.cancelJob(jobId);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method getJobSendGET.
/* Tests_SRS_JOBCLIENT_21_026: [The getJob shall send a GET request to the iothub using the created url.] */
@Test
public void getJobSendGET() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
JobClient testJobClient = null;
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
IotHubConnectionString.getUrlJobs(anyString, jobId);
result = mockedURL;
DeviceOperations.request(anyString, mockedURL, HttpMethod.GET, (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
testJobClient.getJob(jobId);
// assert
new Verifications() {
{
DeviceOperations.request(anyString, mockedURL, HttpMethod.GET, (byte[]) any, (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 scheduleDeviceMethodThrowsOnNullJobId.
/* Tests_SRS_JOBCLIENT_21_014: [If the JobId is null, empty, or invalid, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowsOnNullJobId() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = null;
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
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);
}
Aggregations