Search in sources :

Example 11 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 constructorThrowsOnQuerySpecificationNull.

/* SRS_QUERY_21_003: [The constructor shall throw IllegalArgumentException if the provided querySpecification is null.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnQuerySpecificationNull() {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = null;
    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 12 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 hasNextReturnsFalse.

/* SRS_QUERY_21_010: [The hasNext shall return the store hasNext.] */
@Test
public void hasNextReturnsFalse() 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 int pageSize = 10;
    final Map<String, String> headersResult = new HashMap<String, String>() {

        {
            put("x-ms-item-type", "enrollment");
        }
    };
    new NonStrictExpectations() {

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

Example 13 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 setPageSizeChangePageSize.

/* SRS_QUERY_21_023: [The setPageSize shall store the new pageSize value.] */
@Test
public void setPageSizeChangePageSize() {
    // 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(20);
    // assert
    assertEquals(20, (int) Deencapsulation.getField(query, "pageSize"));
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 14 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 nextThrowsOnRequestFailed.

/* SRS_QUERY_21_015: [The next shall throw IllegalArgumentException if the Http request throws any ProvisioningServiceClientException.] */
@Test(expected = IllegalArgumentException.class)
public void nextThrowsOnRequestFailed() throws ProvisioningServiceClientException {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final String queryPath = targetPath + "/query";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String querySpecificationJson = "validJson";
    new StrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
            mockedContractApiHttp.request(HttpMethod.POST, queryPath, (Map) any, querySpecificationJson);
            result = new ProvisioningServiceClientBadFormatException();
            times = 1;
        }
    };
    Query query = Deencapsulation.newInstance(Query.class, new Class[] { ContractApiHttp.class, String.class, QuerySpecification.class, Integer.class }, contractApiHttp, targetPath, querySpecification, 0);
    // act
    query.next();
// assert
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 15 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 nextReturnsQueryResultWithoutContinuationToken.

/* SRS_QUERY_21_017: [The next shall set hasNext as true if the continuationToken is not null, or false if it is null.] */
/* 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 nextReturnsQueryResultWithoutContinuationToken() 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 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);
        }
    };
    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, new Class[] { String.class, String.class, String.class }, type, bodyResult, null);
        }
    };
    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);
    assertFalse(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