Search in sources :

Example 51 with Query

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

Example 52 with Query

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);
}
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 53 with Query

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);
}
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) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 54 with Query

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);
}
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) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 55 with Query

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);
}
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)

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