use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method getJobCreateURL.
/* Tests_SRS_JOBCLIENT_21_025: [The getJob shall create a URL for Jobs using the iotHubConnectionString.] */
@Test
public void getJobCreateURL() 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, new byte[] {}, (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() {
{
IotHubConnectionString.getUrlJobs(anyString, jobId);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method queryDeviceJobSucceeds.
// Tests_SRS_JOBCLIENT_25_039: [The queryDeviceJob shall create a query object for the type DEVICE_JOB.]
// Tests_SRS_JOBCLIENT_25_040: [The queryDeviceJob shall send a query request on the query object using Query URL, HTTP POST method and wait for the response by calling sendQueryRequest.]
@Test
public void queryDeviceJobSucceeds(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new Expectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
}
};
// act
testJobClient.queryDeviceJob(VALID_SQL_QUERY);
// assert
new Verifications() {
{
mockedQuery.sendQueryRequest((TokenCredentialCache) any, (AzureSasCredential) any, (IotHubConnectionString) any, (URL) any, HttpMethod.POST, 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 scheduleDeviceMethodThrowsOnInvalidMethodName.
/* Tests_SRS_JOBCLIENT_21_015: [If the methodName is null or empty, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowsOnInvalidMethodName() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "ValidJobId";
final String queryCondition = "validQueryCondition";
final String methodName = "invalidMethodName";
final Set<String> payload = new HashSet<>();
final Date startTimeUtc = new Date();
final long maxExecutionTimeInSeconds = 10;
JobClient testJobClient = null;
new NonStrictExpectations() {
{
new MethodParser(methodName, null, null, payload);
result = new IllegalArgumentException();
}
};
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 scheduleUpdateThrowsOnNullMaxExecutionTimeInSeconds.
/* Tests_SRS_JOBCLIENT_21_008: [If the maxExecutionTimeInSeconds is negative, the scheduleUpdateTwin shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleUpdateThrowsOnNullMaxExecutionTimeInSeconds() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
final String queryCondition = "validQueryCondition";
final DeviceTwinDevice updateTwin = mockedDeviceTwinDevice;
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.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 queryDeviceJobThrowsOnEmptyQuery.
@Test(expected = IllegalArgumentException.class)
public void queryDeviceJobThrowsOnEmptyQuery() throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
// act
testJobClient.queryDeviceJob("");
}
Aggregations