Search in sources :

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

@Test(expected = ProvisioningDeviceClientException.class)
public void constructorThrowsOnEmptyHostName() throws ProvisioningDeviceClientException {
    // arrange
    new NonStrictExpectations() {

        {
            mockedProvisioningDeviceClientConfig.getIdScope();
            result = TEST_SCOPE_ID;
            mockedProvisioningDeviceClientConfig.getProvisioningServiceGlobalEndpoint();
            result = "";
        }
    };
    // act
    ContractAPIHttp contractAPIHttp = new ContractAPIHttp(mockedProvisioningDeviceClientConfig);
// assert
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 12 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 constructorThrowsOnNullScopeID.

// SRS_ContractAPIHttp_25_002: [The constructor shall throw ProvisioningDeviceClientException if either idScope and hostName are null or empty.]
@Test(expected = ProvisioningDeviceClientException.class)
public void constructorThrowsOnNullScopeID() throws ProvisioningDeviceClientException {
    // arrange
    new NonStrictExpectations() {

        {
            mockedProvisioningDeviceClientConfig.getIdScope();
            result = null;
        }
    };
    // act
    ContractAPIHttp contractAPIHttp = new ContractAPIHttp(mockedProvisioningDeviceClientConfig);
// assert
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

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

// SRS_ContractAPIHttp_25_011: [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 authenticateWithDPSThrowsOnNullRegistrationId() throws ProvisioningDeviceClientException {
    // arrange
    final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
    ContractAPIHttp contractAPIHttp = createContractClass();
    new NonStrictExpectations() {

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

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

@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnNullPayload() throws Exception {
    // arrange
    final byte[] expectedPayload = null;
    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, HttpMethod.PUT, 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 15 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 requestNonceWithDPSTPMThrowsTransportExceptionIfAnyOfTheTransportCallsFails.

@Test(expected = ProvisioningDeviceTransportException.class)
public void requestNonceWithDPSTPMThrowsTransportExceptionIfAnyOfTheTransportCallsFails() throws IOException, ProvisioningDeviceClientException {
    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 = mockedSslContext;
            new UrlPathBuilder(TEST_HOST_NAME, TEST_SCOPE_ID, ProvisioningDeviceClientTransportProtocol.HTTPS);
            result = new IOException("test IOException");
        }
    };
    // act
    try {
        contractAPIHttp.requestNonceForTPM(mockedRequestData, mockedResponseCallback, null);
    } finally {
        // assert
        new Verifications() {

            {
                mockedResponseCallback.run((ResponseData) any, any);
                times = 0;
            }
        };
    }
}
Also used : UrlPathBuilder(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder) IOException(java.io.IOException) 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