Search in sources :

Example 16 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 nextSendPageSizeAndContinuationTokeanIntoHttpHeader.

/* SRS_QUERY_21_012: [If the pageSize is not 0, the next shall send the Http request with `x-ms-max-item-count=[pageSize]` in the header.] */
/* SRS_QUERY_21_013: [If the continuationToken is not null or empty, the next shall send the Http request with `x-ms-continuation=[continuationToken]` in the header.] */
/* SRS_QUERY_21_014: [The next shall send a Http request with a Http verb `POST`.] */
@Test
public void nextSendPageSizeAndContinuationTokeanIntoHttpHeader() 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 int pageSize = 10;
    final Map<String, String> headersSend = new HashMap<String, String>() {

        {
            put("x-ms-max-item-count", "10");
            put("x-ms-continuation", continuationToken);
        }
    };
    final Map<String, String> headersResult = new HashMap<String, String>() {

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

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

Example 17 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 getPageSizeReturnsPageSize.

/* SRS_QUERY_21_021: [The getPageSize shall return the stored pageSize.] */
@Test
public void getPageSizeReturnsPageSize() {
    // 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
    assertEquals(pageSize, query.getPageSize());
}
Also used : ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 18 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 constructorThrowsOnTargetPathEmpty.

/* SRS_QUERY_21_002: [The constructor shall throw IllegalArgumentException if the provided targetPath is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnTargetPathEmpty() {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "";
    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 19 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 nextThrowsOnNullBody.

/* SRS_QUERY_21_024: [The next shall throw IllegalArgumentException if the heepResponse contains a null body.] */
@Test(expected = IllegalArgumentException.class)
public void nextThrowsOnNullBody() 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 Map<String, String> headersSend = new HashMap<>();
    new StrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
            mockedContractApiHttp.request(HttpMethod.POST, queryPath, headersSend, querySpecificationJson);
            result = mockedHttpResponse;
            mockedHttpResponse.getBody();
            result = null;
            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 : HashMap(java.util.HashMap) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 20 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 nextThrowsOnEmptyContinuationToken.

/* SRS_QUERY_21_018: [The next shall throw NoSuchElementException if the provided continuationToken is null or empty.] */
@Test(expected = NoSuchElementException.class)
public void nextThrowsOnEmptyContinuationToken() throws ProvisioningServiceClientException {
    // arrange
    final ContractApiHttp contractApiHttp = mockedContractApiHttp;
    final String targetPath = "enrollments";
    final QuerySpecification querySpecification = mockedQuerySpecification;
    final String querySpecificationJson = "validJson";
    new StrictExpectations() {

        {
            mockedQuerySpecification.toJson();
            result = querySpecificationJson;
        }
    };
    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)

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