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);
}
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);
}
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;
}
};
}
}
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;
}
};
}
}
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;
}
};
}
Aggregations