Search in sources :

Example 26 with ContractApiHttp

use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.

the class QueryTest method hasNextReturnsTrue.

/* SRS_QUERY_21_010: [The hasNext shall return the store hasNext.] */
@Test
public void hasNextReturnsTrue() {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String querySpecificationJson = "validJson";
    final int pageSize = 10;
    new NonStrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
        }
    };
    Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
    // act - assert
    assertTrue(query.hasNext());
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 27 with ContractApiHttp

use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.

the class QueryTest method nextStoreContinuationToken.

/* SRS_QUERY_21_019: [The next shall store the provided continuationToken.] */
/* SRS_QUERY_21_020: [The next shall return the next page of results by calling the next().] */
@Test
public void nextStoreContinuationToken() throws ProvisioningServiceClientException {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String continuationToken = "validToken";
    final String querySpecificationJson = "validJson";
    class MockedQuery extends Query {

        MockedQuery() {
            super(contractApiHttp, targetPath, querySpecification, 0);
        }

        @Override
        public QueryResult next() {
            return mockedQueryResult;
        }
    }
    new StrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
        }
    };
    MockedQuery mockedQuery = new MockedQuery();
    // act
    QueryResult queryResult = mockedQuery.next(continuationToken);
    // assert
    assertEquals(continuationToken, Deencapsulation.getField(mockedQuery, "continuationToken"));
    assertEquals(mockedQueryResult, queryResult);
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 28 with ContractApiHttp

use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.

the class QueryTest method setPageSizeThrowsOnNegativePageSize.

/* SRS_QUERY_21_022: [The setPageSize shall throw IllegalArgumentException if the provided pageSize is negative.] */
@Test(expected = IllegalArgumentException.class)
public void setPageSizeThrowsOnNegativePageSize() {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String querySpecificationJson = "validJson";
    final int pageSize = 10;
    new NonStrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
        }
    };
    Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
    // act
    query.setPageSize(-10);
// assert
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 29 with ContractApiHttp

use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.

the class QueryTest method constructorThrowsOnContractApiHttpNull.

/* SRS_QUERY_21_001: [The constructor shall throw IllegalArgumentException if the provided contractApiHttp is null.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnContractApiHttpNull() {
    // arrange
    final ContractApiHttp contractApiHttp = null;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final int pageSize = 10;
    // act
    Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, pageSize);
// assert
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 30 with ContractApiHttp

use of com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp in project azure-iot-sdk-java by Azure.

the class QueryTest method nextReturnsQueryResultWithContinuationToken.

/* SRS_QUERY_21_016: [The next shall create and return a new instance of the QueryResult using the `x-ms-item-type` as type, `x-ms-continuation` as the next continuationToken, and the message body.] */
/* SRS_QUERY_21_017: [The next shall set hasNext as true if the continuationToken is not null, or false if it is null.] */
@Test
public void nextReturnsQueryResultWithContinuationToken() throws ProvisioningServiceClientException {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final String queryPath = targetPath + "/query";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String querySpecificationJson = "validJson";
    final String continuationToken = "validToken";
    final String type = "validToken";
    final String bodyResult = "result";
    final Map<String, String> headersSend = new HashMap<>();
    final Map<String, String> headersResult = new HashMap<String, String>() {

        {
            put("x-ms-item-type", type);
            put("x-ms-continuation", continuationToken);
        }
    };
    new StrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
            mockedContractApiHttp.request(HttpMethod.POST, queryPath, headersSend, querySpecificationJson);
            result = mockedHttpResponse;
            mockedHttpResponse.getBody();
            result = bodyResult.getBytes(StandardCharsets.UTF_8);
            mockedHttpResponse.getHeaderFields();
            result = headersResult;
            Deencapsulation.newInstance(QueryResult.class, type, bodyResult, continuationToken);
        }
    };
    Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, 0);
    // act
    QueryResult queryResult = query.next();
    // assert
    assertNotNull(queryResult);
    assertTrue(query.hasNext());
}
Also used : HashMap(java.util.HashMap) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Aggregations

ContractApiHttp (com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp)38 Test (org.junit.Test)38 HashMap (java.util.HashMap)10 ProvisioningSasToken (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken)9 URL (java.net.URL)7 HttpRequest (com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest)5 ProvisioningConnectionString (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString)3 ProvisioningServiceClientException (com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1