use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class JobClientSample method queryDeviceJobs.
private static void queryDeviceJobs(JobClient jobClient) throws IOException, IotHubException {
System.out.println("Query device job");
Query deviceJobQuery = jobClient.queryDeviceJob(SqlQuery.createSqlQuery("*", SqlQuery.FromType.JOBS, null, null).getQuery());
while (jobClient.hasNextJob(deviceJobQuery)) {
System.out.println("Query device job response");
System.out.println(jobClient.getNextJob(deviceJobQuery));
}
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class RawTwinQueryTest method hasNextSucceeds.
// Tests_SRS_RAW_QUERY_25_011: [ The method shall check if a response to query is avaliable by calling hasNext on the query object.]
// Tests_SRS_RAW_QUERY_25_012: [ If a queryResponse is available, this method shall return true as is to the user. ]
@Test
public void hasNextSucceeds() 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 = true;
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
boolean result = rawTwinQuery.hasNext(testQuery);
// assert
assertTrue(result);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.
the class RawTwinQueryTest method nextThrowsIfNonStringRetrieved.
// Tests_SRS_RAW_QUERY_25_017: [ If the next element from the query response is an object other than String, then this method shall throw IOException ]
@Test(expected = IOException.class)
public void nextThrowsIfNonStringRetrieved() 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 = true;
Deencapsulation.invoke(mockedQuery, "next");
result = 5;
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
String result = 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 nextThrowsIfNoNewElements.
// Tests_SRS_RAW_QUERY_25_015: [ The method shall check if hasNext returns true and throw NoSuchElementException otherwise ]
@Test(expected = NoSuchElementException.class)
public void nextThrowsIfNoNewElements() 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 = false;
Deencapsulation.invoke(mockedQuery, "next");
result = new NoSuchElementException();
}
};
Query testQuery = rawTwinQuery.query(VALID_SQL_QUERY);
// act
String result = 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 nextThrowsOnNullQuery.
// Tests_SRS_RAW_QUERY_25_018: [ If the input query is null, then this method shall throw IllegalArgumentException ]
@Test(expected = IllegalArgumentException.class)
public void nextThrowsOnNullQuery() 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.next(null);
}
Aggregations