Search in sources :

Example 1 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 getRegistrationStatusThrowsOnNullSSLContext.

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

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

Example 2 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 prepareRequestThrowsOnNullMethod.

@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnNullMethod() throws Exception {
    // arrange
    final byte[] expectedPayload = "TestBytes".getBytes(StandardCharsets.UTF_8);
    final String expectedUserAgentValue = "TestUserAgent";
    ContractAPIHttp contractAPIHttp = createContractClass();
    // act
    Deencapsulation.invoke(contractAPIHttp, "prepareRequest", new Class[] { URL.class, HttpMethod.class, byte[].class, Integer.class, Map.class, String.class }, mockedUrl, null, expectedPayload, 0, null, expectedUserAgentValue);
// assert
}
Also used : Base64.encodeBase64String(org.apache.commons.codec.binary.Base64.encodeBase64String) ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 3 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 requestNonceWithDPSTPMThrowsOnNullEk.

@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullEk() 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 = null;
            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 4 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 requestNonceWithDPSTPMThrowsOnNullSRk.

@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullSRk() 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 = null;
            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 5 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 authenticateWithDPSForTPMSucceeds.

// SRS_ContractAPIHttp_25_026: [ This method shall build the required Json input using parser. ]
@Test
public void authenticateWithDPSForTPMSucceeds() throws IOException, ProvisioningDeviceClientException {
    // arrange
    final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
    ContractAPIHttp contractAPIHttp = createContractClass();
    prepareRequestExpectations();
    new NonStrictExpectations() {

        {
            mockedHttpRequest.send();
            result = mockedHttpResponse;
            mockedRequestData.getEndorsementKey();
            result = TEST_EK;
            mockedRequestData.getStorageRootKey();
            result = TEST_SRK;
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
            mockedRequestData.getSasToken();
            result = null;
            Deencapsulation.newInstance(DeviceRegistrationParser.class, new Class[] { String.class, String.class, String.class, String.class }, anyString, anyString, anyString, anyString);
            result = mockedDeviceRegistrationParser;
            mockedDeviceRegistrationParser.toJson();
            result = "some json";
        }
    };
    // act
    contractAPIHttp.authenticateWithProvisioningService(mockedRequestData, mockedResponseCallback, null);
    // assert
    prepareRequestVerifications(HttpMethod.PUT, 0);
    new Verifications() {

        {
            new UrlPathBuilder(TEST_HOST_NAME, TEST_SCOPE_ID, ProvisioningDeviceClientTransportProtocol.HTTPS);
            times = 1;
            mockedUrlPathBuilder.generateRegisterUrl(TEST_REGISTRATION_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