use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class JobClientTest method nextThrowsOnNullQuery.
// Tests_SRS_JOBCLIENT_25_048: [If the input query is null, empty, or invalid, the getNextJob shall throw IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void nextThrowsOnNullQuery(@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
testJobClient.getNextJob(null);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method continueQueryThrowsOnNegativePageSize.
@Test(expected = IllegalArgumentException.class)
public void continueQueryThrowsOnNegativePageSize() throws IOException, IotHubException {
// arrange
final String testToken = UUID.randomUUID().toString();
final int testPageSize = -10;
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
// act
Deencapsulation.invoke(testQuery, "continueQuery", testToken, testPageSize);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method continueQuerySetsTokenAndSends.
// Tests_SRS_QUERY_25_005: [The method shall update the request continuation token and request pagesize which shall be used for processing subsequent query request.]
// Tests_SRS_QUERY_25_018: [The method shall send the query request again.]
@Test
public void continueQuerySetsTokenAndSends() throws IOException, IotHubException {
// arrange
final String testToken = UUID.randomUUID().toString();
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
setupSendQuery(testQuery, testToken);
testQuery.sendQueryRequest(mockIotHubConnectionString, mockUrl, mockHttpMethod, DEFAULT_TIMEOUT);
// act
Deencapsulation.invoke(testQuery, "continueQuery", testToken);
// assert
assertEquals(testToken, Deencapsulation.getField(testQuery, "requestContinuationToken"));
new Verifications() {
{
new HttpRequest(mockUrl, mockHttpMethod, (byte[]) any);
times = 2;
mockHttpRequest.setHeaderField("x-ms-max-item-count", String.valueOf(DEFAULT_PAGE_SIZE));
times = 2;
mockHttpRequest.setHeaderField("x-ms-continuation", testToken);
times = 1;
mockHttpRequest.setHeaderField(anyString, anyString);
minTimes = 10;
}
};
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method hasNextReturnsFalseIfNextDoesNotExistsAndTokenIsNull.
// Tests_SRS_QUERY_25_021: [If no further query response is available, then this method shall continue to request query to IotHub if continuation token is available.]
@Test
public void hasNextReturnsFalseIfNextDoesNotExistsAndTokenIsNull() throws IotHubException, IOException {
// arrange
final Map<String, String> testHeaderResponseMap = new HashMap<>();
testHeaderResponseMap.put("x-ms-item-type", DEFAULT_QUERY_TYPE.getValue());
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
new NonStrictExpectations() {
{
mockHttpResponse.getHeaderFields();
result = testHeaderResponseMap;
mockedQueryResponse.hasNext();
result = false;
}
};
Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
// act
boolean hasNext = Deencapsulation.invoke(testQuery, "hasNext");
// assert
assertFalse(hasNext);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method sendQueryRequestDoesNotSetResContinuationTokenIfNotFound.
@Test
public void sendQueryRequestDoesNotSetResContinuationTokenIfNotFound() throws IotHubException, IOException {
// arrange
final String testResponseToken = UUID.randomUUID().toString();
final Map<String, String> testHeaderResponseMap = new HashMap<>();
testHeaderResponseMap.put("x-ms-item-type", DEFAULT_QUERY_TYPE.getValue());
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
new NonStrictExpectations() {
{
mockHttpResponse.getHeaderFields();
result = testHeaderResponseMap;
}
};
// act
Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
// assert
assertNull(Deencapsulation.getField(testQuery, "responseContinuationToken"));
}
Aggregations