Search in sources :

Example 46 with Query

use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.

the class QueryTest method sendQueryRequestThrowsOnNullConnectionString.

// Tests_SRS_QUERY_25_019: [This method shall throw IllegalArgumentException if any of the parameters are null or empty.]
@Test(expected = IllegalArgumentException.class)
public void sendQueryRequestThrowsOnNullConnectionString() 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(null, mockUrl, mockHttpMethod, (long) 0);
}
Also used : 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 47 with Query

use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.

the class QueryTest method constructorWithSQLQueryThrowsOnEmptyQuery.

@Test(expected = IllegalArgumentException.class)
public void constructorWithSQLQueryThrowsOnEmptyQuery() throws IllegalArgumentException {
    // arrange
    final String sqlQuery = "";
    // act
    Query testQuery = Deencapsulation.newInstance(Query.class, sqlQuery, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
}
Also used : Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 48 with Query

use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.

the class QueryTest method nextThrowsIfNextDoesNotExists.

// Tests_SRS_QUERY_25_022: [The method shall check if any further elements are available by calling hasNext and if none is available then it shall throw NoSuchElementException.]
@Test(expected = NoSuchElementException.class)
public void nextThrowsIfNextDoesNotExists() throws IotHubException, IOException {
    // arrange
    final Object mockObject = new Object();
    final Map<String, String> testHeaderResponseMap = new HashMap<>();
    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;
            mockedQueryResponse.hasNext();
            result = false;
        }
    };
    Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
    // act
    Object next = Deencapsulation.invoke(testQuery, "next");
}
Also used : 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 49 with Query

use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.

the class QueryTest method continueQuerySetsPageSize.

@Test
public void continueQuerySetsPageSize() throws IOException, IotHubException {
    // arrange
    final String testToken = UUID.randomUUID().toString();
    Query testQuery = Deencapsulation.newInstance(Query.class, DEFAULT_QUERY, DEFAULT_PAGE_SIZE, DEFAULT_QUERY_TYPE);
    setupSendQuery(testQuery, testToken);
    testQuery.sendQueryRequest(mockIotHubConnectionString, mockUrl, mockHttpMethod, DEFAULT_TIMEOUT);
    // act
    Deencapsulation.invoke(testQuery, "continueQuery", testToken);
    // assert
    assertEquals(testToken, Deencapsulation.getField(testQuery, "requestContinuationToken"));
}
Also used : Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 50 with Query

use of com.microsoft.azure.sdk.iot.service.devicetwin.Query in project azure-iot-sdk-java by Azure.

the class QueryTest method getTokenGets.

// Tests_SRS_QUERY_25_014: [The method shall return the continuation token found in response to a query (which can be null).]
@Test
public void getTokenGets() throws IotHubException, IOException {
    // arrange
    final String testResponseToken = UUID.randomUUID().toString();
    final Map<String, String> testHeaderResponseMap = new HashMap<>();
    testHeaderResponseMap.put("x-ms-continuation", testResponseToken);
    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;
        }
    };
    Deencapsulation.invoke(testQuery, "sendQueryRequest", mockIotHubConnectionString, mockUrl, mockHttpMethod, (long) 0);
    // act
    String actualContinuationToken = Deencapsulation.invoke(testQuery, "getContinuationToken");
    // assert
    assertEquals(actualContinuationToken, testResponseToken);
}
Also used : 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)

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