Search in sources :

Example 21 with ContractAPIHttp

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method requestNonceWithDPSTPMThrowsOnNullRegistrationId.

// SRS_ContractAPIHttp_25_003: [If either registrationId, sslcontext or restResponseCallback is null or if registrationId is empty then this method shall throw ProvisioningDeviceClientException.]
@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullRegistrationId() throws ProvisioningDeviceClientException {
    // arrange
    final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
    ContractAPIHttp contractAPIHttp = createContractClass();
    new NonStrictExpectations() {

        {
            mockedRequestData.getRegistrationId();
            result = null;
            mockedRequestData.getEndorsementKey();
            result = TEST_EK;
            mockedRequestData.getStorageRootKey();
            result = TEST_SRK;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
        }
    };
    // act
    contractAPIHttp.requestNonceForTPM(mockedRequestData, mockedResponseCallback, null);
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 22 with ContractAPIHttp

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method requestNonceWithDPSTPMThrowsOnNullSSLContext.

@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullSSLContext() throws ProvisioningDeviceClientException {
    // arrange
    final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
    ContractAPIHttp contractAPIHttp = createContractClass();
    new NonStrictExpectations() {

        {
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getEndorsementKey();
            result = TEST_EK;
            mockedRequestData.getStorageRootKey();
            result = TEST_SRK;
            mockedRequestData.getSslContext();
            result = null;
        }
    };
    // act
    contractAPIHttp.requestNonceForTPM(mockedRequestData, mockedResponseCallback, null);
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 23 with ContractAPIHttp

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method getRegistrationStatusThrowsOnNullResponseCallback.

@Test(expected = ProvisioningDeviceClientException.class)
public void getRegistrationStatusThrowsOnNullResponseCallback() throws ProvisioningDeviceClientException {
    // arrange
    ContractAPIHttp contractAPIHttp = createContractClass();
    new NonStrictExpectations() {

        {
            mockedRequestData.getOperationId();
            result = TEST_OPERATION_ID;
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
            mockedRequestData.getSasToken();
            result = null;
        }
    };
    // act
    contractAPIHttp.getRegistrationStatus(mockedRequestData, null, null);
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 24 with ContractAPIHttp

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.

the class ProvisioningDeviceClientContractTest method createContractSucceedsHttp.

@Test
public void createContractSucceedsHttp() throws Exception {
    // arrange
    new NonStrictExpectations() {

        {
            mockedProvisioningDeviceClientConfig.getIdScope();
            result = TEST_SCOPE_ID;
            mockedProvisioningDeviceClientConfig.getProvisioningServiceGlobalEndpoint();
            result = TEST_URI;
            mockedProvisioningDeviceClientConfig.getProtocol();
            result = ProvisioningDeviceClientTransportProtocol.HTTPS;
        }
    };
    // act
    ProvisioningDeviceClientContract clientContract = ProvisioningDeviceClientContract.createProvisioningContract(mockedProvisioningDeviceClientConfig);
    // assert
    assertTrue(clientContract instanceof ContractAPIHttp);
}
Also used : ProvisioningDeviceClientContract(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.ProvisioningDeviceClientContract) NonStrictExpectations(mockit.NonStrictExpectations) ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 25 with ContractAPIHttp

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method getRegistrationStatusWithAuthSucceeds.

// SRS_ContractAPIHttp_25_019: [This method shall retrieve the Url by calling generateRequestUrl on an object for UrlPathBuilder.]
// SRS_ContractAPIHttp_25_020: [This method shall prepare the GET request by setting following headers on a HttpRequest 1. User-Agent : User Agent String for the SDK 2. Accept : "application/json" 3. Content-Type: "application/json; charset=utf-8" 4. Authorization: specified sas token as authorization if a non null value is given.]
// SRS_ContractAPIHttp_25_021: [This method shall set the SSLContext for the Http Request.]
// SRS_ContractAPIHttp_25_022: [This method shall send http request and verify the status by calling 'ProvisioningDeviceClientExceptionManager.verifyHttpResponse'.]
// SRS_ContractAPIHttp_25_023: [If service return a status as < 300 then this method shall trigger the callback to the user with the response message.]
@Test
public void getRegistrationStatusWithAuthSucceeds() throws IOException, ProvisioningDeviceClientException {
    // arrange
    ContractAPIHttp contractAPIHttp = createContractClass();
    prepareRequestExpectations();
    new NonStrictExpectations() {

        {
            mockedRequestData.getOperationId();
            result = TEST_OPERATION_ID;
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
            mockedRequestData.getSasToken();
            result = TEST_SAS_TOKEN;
            mockedHttpRequest.send();
            result = mockedHttpResponse;
        }
    };
    // act
    contractAPIHttp.getRegistrationStatus(mockedRequestData, mockedResponseCallback, null);
    // assert
    prepareRequestVerifications(HttpMethod.GET, 1);
    new Verifications() {

        {
            new UrlPathBuilder(TEST_HOST_NAME, TEST_SCOPE_ID, ProvisioningDeviceClientTransportProtocol.HTTPS);
            times = 1;
            mockedUrlPathBuilder.generateRequestUrl(TEST_REGISTRATION_ID, TEST_OPERATION_ID);
            times = 1;
            mockedHttpRequest.setSSLContext(mockedSslContext);
            times = 1;
            mockedResponseCallback.run((ResponseData) any, null);
            times = 1;
        }
    };
}
Also used : UrlPathBuilder(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder) ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Aggregations

ContractAPIHttp (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp)41 Test (org.junit.Test)41 UrlPathBuilder (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder)12 DeviceRegistrationParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser)7 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)5 IOException (java.io.IOException)4 ProvisioningDeviceClientContract (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.ProvisioningDeviceClientContract)1 NonStrictExpectations (mockit.NonStrictExpectations)1