Search in sources :

Example 1 with Query

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));
    }
}
Also used : SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query)

Example 2 with Query

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);
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) Test(org.junit.Test)

Example 3 with Query

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);
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 4 with Query

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);
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 5 with Query

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);
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) Test(org.junit.Test)

Aggregations

Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)63 Test (org.junit.Test)51 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)49 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)34 HashMap (java.util.HashMap)17 NonStrictExpectations (mockit.NonStrictExpectations)17 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)10 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)10 RawTwinQuery (com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery)8 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)8 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)6 HttpRequest (com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest)6 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)4 IOException (java.io.IOException)3 NoSuchElementException (java.util.NoSuchElementException)3 Verifications (mockit.Verifications)3 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)2 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 JobClientOptions (com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions)2 Proxy (java.net.Proxy)2