use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method sendQueryRequestThrowsOnNullConnectionString.
// Tests_SRS_QUERY_25_019: [This method shall throw IllegalArgumentException if any of the parameters are null or empty.]
@Test(expected = IllegalArgumentException.class)
public void sendQueryRequestThrowsOnNullConnectionString() throws IotHubException, IOException {
// arrange
final String testToken = UUID.randomUUID().toString();
final Map<String, String> testHeaderResponseMap = new HashMap<>();
testHeaderResponseMap.put("x-ms-continuation", testToken);
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
testQuery.sendQueryRequest(null, mockUrl, mockHttpMethod, (long) 0);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method constructorWithSQLQueryThrowsOnEmptyQuery.
@Test(expected = IllegalArgumentException.class)
public void constructorWithSQLQueryThrowsOnEmptyQuery() throws IllegalArgumentException {
// arrange
final String sqlQuery = "";
// act
Query testQuery = Deencapsulation.newInstance(Query.class, sqlQuery, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method nextThrowsIfNextDoesNotExists.
// Tests_SRS_QUERY_25_022: [The method shall check if any further elements are available by calling hasNext and if none is available then it shall throw NoSuchElementException.]
@Test(expected = NoSuchElementException.class)
public void nextThrowsIfNextDoesNotExists() throws IotHubException, IOException {
// arrange
final Object mockObject = new Object();
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
Object next = Deencapsulation.invoke(testQuery, "next");
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method continueQuerySetsPageSize.
@Test
public void continueQuerySetsPageSize() 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"));
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method getTokenGets.
// Tests_SRS_QUERY_25_014: [The method shall return the continuation token found in response to a query (which can be null).]
@Test
public void getTokenGets() throws IotHubException, IOException {
// arrange
final String testResponseToken = UUID.randomUUID().toString();
final Map<String, String> testHeaderResponseMap = new HashMap<>();
testHeaderResponseMap.put("x-ms-continuation", testResponseToken);
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;
}
};
Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
// act
String actualContinuationToken = Deencapsulation.invoke(testQuery, "getContinuationToken");
// assert
assertEquals(actualContinuationToken, testResponseToken);
}
Aggregations