Search in sources :

Example 11 with DeviceRegistrationParser

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.

the class DeviceRegistrationParserTest method constructorWithTPMOnEmptyEkThrows.

@Test(expected = IllegalArgumentException.class)
public void constructorWithTPMOnEmptyEkThrows() throws Exception {
    final String eKey = "testEndorsementKey";
    final String sRKey = "testStorageRootKey";
    DeviceRegistrationParser deviceRegistrationParser = new DeviceRegistrationParser(TEST_REGISTRATION_ID, "", "", sRKey);
}
Also used : DeviceRegistrationParser(com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser) Test(org.junit.Test)

Example 12 with DeviceRegistrationParser

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.

the class DeviceRegistrationParserTest method constructorWithTPMOnNullEkThrows.

// SRS_DeviceRegistration_25_004: [ The constructor shall throw IllegalArgumentException if EndorsementKey is null or empty. ]
@Test(expected = IllegalArgumentException.class)
public void constructorWithTPMOnNullEkThrows() throws Exception {
    final String eKey = "testEndorsementKey";
    final String sRKey = "testStorageRootKey";
    DeviceRegistrationParser deviceRegistrationParser = new DeviceRegistrationParser(TEST_REGISTRATION_ID, "", null, sRKey);
}
Also used : DeviceRegistrationParser(com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser) Test(org.junit.Test)

Example 13 with DeviceRegistrationParser

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method requestNonceWithDPSTPMThrowsHubExceptionWithStatusOtherThan404Throws.

// SRS_ContractAPIHttp_25_009: [If service return any other status other than 404 then this method shall throw ProvisioningDeviceTransportException in case of 202 or ProvisioningDeviceHubException on any other status.]
@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsHubExceptionWithStatusOtherThan404Throws() 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);
            result = new ProvisioningDeviceHubException("test Exception");
            mockedHttpResponse.getStatus();
            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)

Example 14 with DeviceRegistrationParser

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser 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)

Example 15 with DeviceRegistrationParser

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.

the class ContractAPIHttpTest method authenticateWithDPSWithAuthAndRetryAfterSucceeds.

@Test
public void authenticateWithDPSWithAuthAndRetryAfterSucceeds() throws IOException, ProvisioningDeviceClientException {
    // arrange
    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;
            mockedRequestData.getSasToken();
            result = TEST_SAS_TOKEN;
            mockedHttpRequest.send();
            result = mockedHttpResponse;
            mockedHttpResponse.isFieldAvailable("retry-after");
            result = true;
            mockedHttpResponse.getHeaderField("retry-after");
            result = "3";
            mockedHttpResponse.getStatus();
            result = 400;
            new DeviceRegistrationParser(anyString, anyString, anyString, anyString);
            result = mockedDeviceRegistrationParser;
            mockedDeviceRegistrationParser.toJson();
            result = "some json";
        }
    };
    // act
    contractAPIHttp.authenticateWithProvisioningService(mockedRequestData, mockedResponseCallback, null);
    // assert
    prepareRequestVerifications(HttpMethod.PUT, 1);
    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) 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

DeviceRegistrationParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser)15 Test (org.junit.Test)13 UrlPathBuilder (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.UrlPathBuilder)7 ContractAPIHttp (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.http.ContractAPIHttp)7 HttpRequest (com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest)2 HttpResponse (com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)2 ResponseData (com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ResponseData)2 IOException (java.io.IOException)2 URL (java.net.URL)2 TpmRegistrationResultParser (com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.TpmRegistrationResultParser)1 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)1