Search in sources :

Example 31 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 getRegistrationStatusThrowsOnEmptyOperationId.

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

        {
            mockedRequestData.getOperationId();
            result = "";
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
            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 32 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 prepareRequestThrowsOnInvalidTimeout.

@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnInvalidTimeout() 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, HttpMethod.PUT, expectedPayload, -2, 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 33 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 prepareRequestThrowsOnNullUrl.

@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnNullUrl() 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 }, null, 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 34 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 requestNonceWithDPSTPMThrowsOnNullResponseCallback.

@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullResponseCallback() 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 = mockedSslContext;
        }
    };
    // act
    contractAPIHttp.requestNonceForTPM(mockedRequestData, null, null);
}
Also used : ContractAPIHttp(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp) Test(org.junit.Test)

Example 35 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 requestNonceWithDPSTPMThrowsHubExceptionWithStatusLessThan300Throws.

// SRS_ContractAPIHttp_25_009: [If service return any other status other than 404 then this method shall throw ProvisioningDeviceTransportException in case of < 300 or ProvisioningDeviceHubException on any other status.]
@Test(expected = ProvisioningDeviceTransportException.class)
public void requestNonceWithDPSTPMThrowsHubExceptionWithStatusLessThan300Throws() throws IOException, ProvisioningDeviceClientException {
    final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
    ContractAPIHttp contractAPIHttp = createContractClass();
    prepareRequestExpectations();
    new NonStrictExpectations() {

        {
            mockedRequestData.getRegistrationId();
            result = TEST_REGISTRATION_ID;
            mockedRequestData.getEndorsementKey();
            result = TEST_EK;
            mockedRequestData.getStorageRootKey();
            result = TEST_SRK;
            mockedRequestData.getSslContext();
            result = mockedSslContext;
            mockedHttpRequest.send();
            result = mockedHttpResponse;
            ProvisioningDeviceClientExceptionManager.verifyHttpResponse(mockedHttpResponse);
            mockedHttpResponse.getStatus();
            result = 200;
            new DeviceRegistrationParser(anyString, anyString, anyString, anyString);
            result = mockedDeviceRegistrationParser;
            mockedDeviceRegistrationParser.toJson();
            result = "some json";
        }
    };
    // act
    try {
        contractAPIHttp.requestNonceForTPM(mockedRequestData, mockedResponseCallback, null);
    } finally {
        // assert
        new Verifications() {

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