Search in sources :

Example 1 with ContractApiHttp

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

the class ContractApiHttpTest method createFromConnectionStringSucceeded.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_004: [The createFromConnectionString shall create a new ContractApiHttp instance and return it.] */
@Test
public void createFromConnectionStringSucceeded() throws ProvisioningServiceClientException {
    // arrange
    final ProvisioningConnectionString provisioningConnectionString = mockedProvisioningConnectionString;
    // act
    ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(provisioningConnectionString);
    // assert
    assertNotNull(contractApiHttp);
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) Test(org.junit.Test)

Example 2 with ContractApiHttp

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

the class ContractApiHttpTest method requestThrowsOnSendHttpRequestFailed.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_015: [If the HttpRequest failed send the message, the request shall throw ProvisioningServiceClientTransportException, threw by the callee.*/
@Test(expected = ProvisioningServiceClientException.class)
public void requestThrowsOnSendHttpRequestFailed() throws ProvisioningServiceClientException, IOException {
    // arrange
    new NonStrictExpectations() {

        {
            new ProvisioningSasToken(mockedProvisioningConnectionString);
            result = mockedProvisioningSasToken;
            mockedProvisioningSasToken.toString();
            result = VALID_SASTOKEN;
            mockedProvisioningConnectionString.getHostName();
            result = VALID_HOST_NAME;
            new URL((String) any);
            result = mockedURL;
            new HttpRequest(mockedURL, HttpMethod.PUT, VALID_PAYLOAD.getBytes(StandardCharsets.UTF_8));
            result = mockedHttpRequest;
            mockedHttpRequest.send();
            result = new ProvisioningServiceClientException();
        }
    };
    ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
    // act
    contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
// assert
}
Also used : HttpRequest(com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest) ProvisioningSasToken(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) URL(java.net.URL) ProvisioningServiceClientException(com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientException) Test(org.junit.Test)

Example 3 with ContractApiHttp

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

the class ContractApiHttpTest method requestThrowsOnWrongPath.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_009: [If the provided path contains not valid characters, the request shall throw IllegalArgumentException.*/
@Test(expected = IllegalArgumentException.class)
public void requestThrowsOnWrongPath() throws ProvisioningServiceClientException, IOException {
    // arrange
    new NonStrictExpectations() {

        {
            new ProvisioningSasToken(mockedProvisioningConnectionString);
            result = mockedProvisioningSasToken;
            mockedProvisioningSasToken.toString();
            result = VALID_SASTOKEN;
            mockedProvisioningConnectionString.getHostName();
            result = VALID_HOST_NAME;
            new URL((String) any);
            result = new MalformedURLException();
        }
    };
    ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
    // act
    contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
// assert
}
Also used : MalformedURLException(java.net.MalformedURLException) ProvisioningSasToken(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) URL(java.net.URL) Test(org.junit.Test)

Example 4 with ContractApiHttp

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

the class ContractApiHttpTest method requestCreatesSasToken.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_005: [The request shall create a SAS token based on the connection string.*/
@Test
public void requestCreatesSasToken() throws ProvisioningServiceClientException, IOException {
    // arrange
    new Expectations() {

        {
            new ProvisioningSasToken(mockedProvisioningConnectionString);
            result = mockedProvisioningSasToken;
            mockedProvisioningSasToken.toString();
            result = VALID_SASTOKEN;
            mockedProvisioningConnectionString.getHostName();
            result = VALID_HOST_NAME;
            new URL((String) any);
            result = mockedURL;
            new HttpRequest(mockedURL, HttpMethod.PUT, VALID_PAYLOAD.getBytes(StandardCharsets.UTF_8));
            result = mockedHttpRequest;
            mockedHttpRequest.send();
            result = mockedHttpResponse;
            mockedHttpResponse.getStatus();
            result = VALID_SUCCESS_STATUS;
            mockedHttpResponse.getErrorReason();
            result = VALID_SUCCESS_MESSAGE.getBytes(StandardCharsets.UTF_8);
            mockedHttpResponse.getBody();
            result = VALID_BODY;
            mockedHttpResponse.getHeaderFields();
            result = VALID_HEADER;
            ProvisioningServiceClientExceptionManager.httpResponseVerification(VALID_SUCCESS_STATUS, VALID_SUCCESS_MESSAGE);
        }
    };
    ContractApiHttp contractApiHttp = ContractApiHttp.createFromConnectionString(mockedProvisioningConnectionString);
    requestNonStrictExpectations();
    // act
    contractApiHttp.request(HttpMethod.PUT, VALID_PATH, VALID_HEADER, VALID_PAYLOAD);
}
Also used : HttpRequest(com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest) ProvisioningSasToken(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken) ContractApiHttp(com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp) URL(java.net.URL) Test(org.junit.Test)

Example 5 with ContractApiHttp

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

the class ContractApiHttpTest method privateConstructorSucceeded.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_001: [The constructor shall store the provided connection string.] */
@Test
public void privateConstructorSucceeded() {
    // arrange
    // act
    ContractApiHttp httpDeviceRegistrationClient = Deencapsulation.newInstance(ContractApiHttp.class, new Class[] { ProvisioningConnectionString.class }, mockedProvisioningConnectionString);
    // assert
    assertNotNull(httpDeviceRegistrationClient);
    assertEquals(mockedProvisioningConnectionString, Deencapsulation.getField(httpDeviceRegistrationClient, "provisioningConnectionString"));
}
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