use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class QueryTest method hasNextReturnsFalseIfContinueQueryHasNothing.
@Test
public void hasNextReturnsFalseIfContinueQueryHasNothing() 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());
testHeaderResponseMap.put("x-ms-continuation", testResponseToken);
Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
new NonStrictExpectations() {
{
mockHttpResponse.getHeaderFields();
result = testHeaderResponseMap;
mockedQueryResponse.hasNext();
result = false;
}
};
// continue query setup
setupSendQuery(testQuery, testResponseToken);
Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
// act
boolean hasNext = Deencapsulation.invoke(testQuery, "hasNext");
// assert
assertFalse(hasNext);
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", anyString);
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 RawTwinQueryTest method hasNextThrowsOnNullQuery.
// Tests_SRS_RAW_QUERY_25_010: [ The method shall throw IllegalArgumentException if query is null ]
@Test(expected = IllegalArgumentException.class)
public void hasNextThrowsOnNullQuery() throws IotHubException, IOException {
// arrange
RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.RAW);
result = mockedQuery;
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
rawTwinQuery.hasNext(null);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class RawTwinQueryTest method hasNextThrowsIfQueryHasNextThrows.
@Test(expected = IotHubException.class)
public void hasNextThrowsIfQueryHasNextThrows() throws IotHubException, IOException {
// arrange
RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.RAW);
result = mockedQuery;
Deencapsulation.invoke(mockedQuery, "hasNext");
result = new IotHubException();
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
boolean result = rawTwinQuery.hasNext(testQuery);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class RawTwinQueryTest method nextThrowsOnQueryNextThrows.
@Test(expected = IotHubException.class)
public void nextThrowsOnQueryNextThrows() throws IotHubException, IOException {
// arrange
RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.RAW);
result = mockedQuery;
Deencapsulation.invoke(mockedQuery, "next");
result = new IotHubException();
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
rawTwinQuery.next(testQuery);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class RawTwinQueryTest method nextRetrievesCorrectly.
// Tests_SRS_RAW_QUERY_25_016: [ The method shall return the next element from the query response.]
@Test
public void nextRetrievesCorrectly() throws IotHubException, IOException {
// arrange
RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
final String expectedString = "testJsonAsNext";
new NonStrictExpectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.RAW);
result = mockedQuery;
Deencapsulation.invoke(mockedQuery, "hasNext");
result = true;
Deencapsulation.invoke(mockedQuery, "next");
result = expectedString;
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
String result = rawTwinQuery.next(testQuery);
// assert
assertEquals(expectedString, result);
}
Aggregations