use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method nextThrowsIfNonStringRetrieved.
// Tests_SRS_JOBCLIENT_25_050: [getNextJob shall throw IOException if next Job Result exist and is not a string.]
@Test(expected = IOException.class)
public void nextThrowsIfNonStringRetrieved(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
Deencapsulation.invoke(mockedQuery, "hasNext");
result = true;
Deencapsulation.invoke(mockedQuery, "next");
result = 5;
}
};
Query testQuery = testJobClient.queryDeviceJob(VALID_SQL_QUERY);
// act
testJobClient.getNextJob(testQuery);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method scheduleUpdateTwinSendPUT.
/* Tests_SRS_JOBCLIENT_21_010: [The scheduleUpdateTwin shall send a PUT request to the iothub using the created uri and json.] */
@Test
public void scheduleUpdateTwinSendPUT() 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 NonStrictExpectations() {
{
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 = null;
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);
// 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 nextThrowsOnQueryNextThrows.
@Test(expected = IotHubException.class)
public void nextThrowsOnQueryNextThrows(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
Deencapsulation.invoke(mockedQuery, "next");
result = new IotHubException();
}
};
Query testQuery = testJobClient.queryDeviceJob(VALID_SQL_QUERY);
// act
testJobClient.getNextJob(testQuery);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method queryDeviceJobThrowsOnNewQueryThrows.
@Test(expected = IotHubException.class)
public void queryDeviceJobThrowsOnNewQueryThrows(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
mockedQuery.sendQueryRequest((TokenCredentialCache) any, (AzureSasCredential) any, (IotHubConnectionString) any, (URL) any, HttpMethod.POST, anyInt, anyInt, (Proxy) any);
result = new IotHubException();
}
};
// act
testJobClient.queryDeviceJob(VALID_SQL_QUERY);
}
use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.
the class JobClientTest method hasNextThrowsOnNullQuery.
// Tests_SRS_JOBCLIENT_25_046: [If the input query is null, empty, or invalid, the hasNextJob shall throw IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void hasNextThrowsOnNullQuery(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
}
};
Query testQuery = testJobClient.queryDeviceJob(VALID_SQL_QUERY);
// act
boolean result = testJobClient.hasNextJob(null);
}
Aggregations