use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method sendQueryRequestSetsHeadersIfFound.
// Tests_SRS_QUERY_25_007: [The method shall set the http headers x-ms-continuation and x-ms-max-item-count with request continuation token and page size if they were not null.]
@Test
public void sendQueryRequestSetsHeadersIfFound() throws IotHubException, IOException {
// arrange
final String testToken = UUID.randomUUID().toString();
final int newPageSize = 5;
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
Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
Deencapsulation.invoke(testQuery, "continueQuery", testToken);
// assert
new Verifications() {
{
new HttpRequest(mockUrl, mockHttpMethod, (byte[]) any);
times = 2;
mockHttpRequest.setHeaderField("x-ms-continuation", testToken);
times = 1;
mockHttpRequest.setHeaderField(anyString, anyString);
minTimes = 5;
}
};
assertEquals(testToken, Deencapsulation.getField(testQuery, "responseContinuationToken"));
assertEquals(DEFAULT_QUERY_TYPE, Deencapsulation.getField(testQuery, "responseQueryType"));
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method sendQueryRequestThrowsOnNullURL.
@Test(expected = IllegalArgumentException.class)
public void sendQueryRequestThrowsOnNullURL() 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(mockIotHubConnectionString, null, 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 constructorWithSQLQueryThrowsOnNullQuery.
@Test(expected = IllegalArgumentException.class)
public void constructorWithSQLQueryThrowsOnNullQuery() throws IllegalArgumentException {
// arrange
final String sqlQuery = null;
// act
Query testQuery = Deencapsulation.newInstance(Query.class, String.class, 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 constructorWithSQLQueryThrowsOnInvalidQuery.
// Tests_SRS_QUERY_25_002: [If the query is null or empty or is not a valid sql query (containing select and from), the constructor shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void constructorWithSQLQueryThrowsOnInvalidQuery() throws IllegalArgumentException {
// arrange
final String sqlQuery = "invalid query";
// 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 constructorWithOutSQLQuerySucceeds.
// Tests_SRS_QUERY_25_001: [The constructor shall validate query and save query, pagesize and request type]
// Tests_SRS_QUERY_25_017: [If the query is avaliable then isSqlQuery shall be set to true, and false otherwise.]
@Test
public void constructorWithOutSQLQuerySucceeds() throws IllegalArgumentException {
// act
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
// assert
assertNotNull(Deencapsulation.getField(testQuery, "pageSize"));
assertEquals(DEFAULT_PAGE_SIZE, (int) Deencapsulation.getField(testQuery, "pageSize"));
assertNull(Deencapsulation.getField(testQuery, "query"));
assertFalse(Deencapsulation.getField(testQuery, "isSqlQuery"));
assertEquals(DEFAULT_QUERY_TYPE, Deencapsulation.getField(testQuery, "requestQueryType"));
assertEquals(QueryType.UNKNOWN, Deencapsulation.getField(testQuery, "responseQueryType"));
assertNull(Deencapsulation.getField(testQuery, "requestContinuationToken"));
assertNull(Deencapsulation.getField(testQuery, "responseContinuationToken"));
assertNull(Deencapsulation.getField(testQuery, "queryResponse"));
}
Aggregations