use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.
the class ContractAPIHttpTest method authenticateWithDPSWithOutAuthSucceeds.
// SRS_ContractAPIHttp_25_012: [This method shall retrieve the Url by calling 'generateRegisterUrl' on an object for UrlPathBuilder.]
// SRS_ContractAPIHttp_25_013: [This method shall prepare the PUT 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_014: [This method shall set the SSLContext for the Http Request.]
// SRS_ContractAPIHttp_25_015: [This method shall send http request and verify the status by calling 'ProvisioningDeviceClientExceptionManager.verifyHttpResponse'.]
@Test
public void authenticateWithDPSWithOutAuthSucceeds(@Mocked DeviceRegistrationParser mockedDeviceRegistrationParser) throws IOException, ProvisioningDeviceClientException {
// arrange
final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
ContractAPIHttp contractAPIHttp = createContractClass();
prepareRequestExpectations();
new NonStrictExpectations() {
{
mockedHttpRequest.send();
result = mockedHttpResponse;
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getEndorsementKey();
result = null;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
mockedDeviceRegistrationParser.toJson();
result = "TEST JSON";
new DeviceRegistrationParser(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;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.
the class ContractAPIHttpTest method authenticateWithDPSWithAuthSucceeds.
@Test
public void authenticateWithDPSWithAuthSucceeds() 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.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;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.
the class ContractAPIHttpTest method authenticateWithDPSThrowsOnSendFailure.
@Test(expected = ProvisioningDeviceHubException.class)
public void authenticateWithDPSThrowsOnSendFailure() throws IOException, ProvisioningDeviceClientException {
// arrange
final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
ContractAPIHttp contractAPIHttp = createContractClass();
prepareRequestExpectations();
new NonStrictExpectations() {
{
mockedHttpRequest.send();
result = mockedHttpResponse;
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getEndorsementKey();
result = null;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
ProvisioningDeviceClientExceptionManager.verifyHttpResponse(mockedHttpResponse);
result = new ProvisioningDeviceHubException("test Exception");
new DeviceRegistrationParser(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 = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.
the class ContractAPIHttpTest method requestNonceWithDPSTPMSucceeds.
// SRS_ContractAPIHttp_25_004: [This method shall retrieve the Url by calling 'generateRegisterUrl' on an object for UrlPathBuilder.]
// SRS_ContractAPIHttp_25_005: [This method shall prepare the PUT 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".]
// SRS_ContractAPIHttp_25_006: [This method shall set the SSLContext for the Http Request.]
// SRS_ContractAPIHttp_25_008: [If service return a status as 404 then this method shall trigger the callback to the user with the response message.]
@Test
public void requestNonceWithDPSTPMSucceeds() 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;
mockedHttpRequest.send();
result = mockedHttpResponse;
ProvisioningDeviceClientExceptionManager.verifyHttpResponse(mockedHttpResponse);
result = new ProvisioningDeviceHubException("test Exception");
mockedHttpResponse.getStatus();
result = 401;
TpmRegistrationResultParser.createFromJson(new String(mockedHttpResponse.getBody()));
result = mockedTpmRegistrationResultParser;
mockedTpmRegistrationResultParser.getAuthenticationKey();
result = encodeBase64String("some auth key".getBytes(StandardCharsets.UTF_8));
new DeviceRegistrationParser(anyString, anyString, anyString, anyString);
result = mockedDeviceRegistrationParser;
mockedDeviceRegistrationParser.toJson();
result = "some json";
}
};
// act
contractAPIHttp.requestNonceForTPM(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;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.internal.parser.DeviceRegistrationParser in project azure-iot-sdk-java by Azure.
the class DeviceRegistrationParserTest method constructorWithTPMOnNullRegistrationIdThrows.
// SRS_DeviceRegistration_25_003: [ The constructor shall throw IllegalArgumentException if Registration Id is null or empty. ]
@Test(expected = IllegalArgumentException.class)
public void constructorWithTPMOnNullRegistrationIdThrows() throws Exception {
final String eKey = "testEndorsementKey";
final String sRKey = "testStorageRootKey";
DeviceRegistrationParser deviceRegistrationParser = new DeviceRegistrationParser(null, "", eKey, sRKey);
}
Aggregations