Search in sources :

Example 1 with RawTwinQuery

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

the class RawTwinQueryTest method rawQueryThrowsOnNegativePageSize.

// Tests_SRS_RAW_QUERY_25_005: [ The method shall throw IllegalArgumentException if the page size is zero or negative.]
@Test(expected = IllegalArgumentException.class)
public void rawQueryThrowsOnNegativePageSize() throws IotHubException, IOException {
    // arrange
    RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
    // act
    rawTwinQuery.query(VALID_SQL_QUERY, -1);
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) Test(org.junit.Test)

Example 2 with RawTwinQuery

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

the class RawTwinQueryTest method rawQueryThrowsOnEmptyQuery.

@Test(expected = IllegalArgumentException.class)
public void rawQueryThrowsOnEmptyQuery() throws IotHubException, IOException {
    // arrange
    RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
    // act
    rawTwinQuery.query("");
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) Test(org.junit.Test)

Example 3 with RawTwinQuery

use of com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery 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 4 with RawTwinQuery

use of com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery 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 5 with RawTwinQuery

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

the class RawTwinQueryTest method rawQuerySucceeds.

// Tests_SRS_RAW_QUERY_25_006: [ The method shall build the URL for this operation by calling getUrlTwinQuery ]
// Tests_SRS_RAW_QUERY_25_007: [ The method shall create a new Query Object of Type Raw. ]
// Tests_SRS_RAW_QUERY_25_008: [ The method shall send a Query Request to IotHub as HTTP Method Post on the query Object by calling sendQueryRequest.]
// Tests_SRS_RAW_QUERY_25_009: [ If the pagesize if not provided then a default pagesize of 100 is used for the query.]
@Test
public void rawQuerySucceeds() throws IotHubException, IOException {
    // arrange
    RawTwinQuery rawTwinQuery = RawTwinQuery.createFromConnectionString(VALID_CONNECTION_STRING);
    new Expectations() {

        {
            Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.RAW);
            result = mockedQuery;
        }
    };
    // act
    rawTwinQuery.query(VALID_SQL_QUERY);
// assert
}
Also used : RawTwinQuery(com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery) Test(org.junit.Test)

Aggregations

RawTwinQuery (com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery)13 Test (org.junit.Test)13 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)8 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)8 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 NoSuchElementException (java.util.NoSuchElementException)1