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 authenticateWithDPSThrowsTransportExceptionIfAnyOfTheTransportCallsFails.
@Test(expected = ProvisioningDeviceTransportException.class)
public void authenticateWithDPSThrowsTransportExceptionIfAnyOfTheTransportCallsFails() throws ProvisioningDeviceClientException {
final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
new UrlPathBuilder(TEST_HOST_NAME, TEST_SCOPE_ID, ProvisioningDeviceClientTransportProtocol.HTTPS);
result = new IOException("test IOException");
}
};
// act
try {
contractAPIHttp.authenticateWithProvisioningService(mockedRequestData, mockedResponseCallback, null);
} finally {
// assert
new Verifications() {
{
mockedResponseCallback.run((ResponseData) any, any);
times = 0;
}
};
}
}
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 getRegistrationStatusWithOutAuthSucceeds.
@Test
public void getRegistrationStatusWithOutAuthSucceeds() throws IOException, ProvisioningDeviceClientException {
// arrange
ContractAPIHttp contractAPIHttp = createContractClass();
prepareRequestExpectations();
new NonStrictExpectations() {
{
mockedRequestData.getOperationId();
result = TEST_OPERATION_ID;
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
mockedHttpRequest.send();
result = mockedHttpResponse;
}
};
// act
contractAPIHttp.getRegistrationStatus(mockedRequestData, mockedResponseCallback, null);
// assert
prepareRequestVerifications(HttpMethod.GET, 0);
new Verifications() {
{
new UrlPathBuilder(TEST_HOST_NAME, TEST_SCOPE_ID, ProvisioningDeviceClientTransportProtocol.HTTPS);
times = 1;
mockedUrlPathBuilder.generateRequestUrl(TEST_REGISTRATION_ID, TEST_OPERATION_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.contract.http.ContractAPIHttp 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.contract.http.ContractAPIHttp in project azure-iot-sdk-java by Azure.
the class ContractAPIHttpTest method constructorThrowsOnEmptyScopeID.
@Test(expected = ProvisioningDeviceClientException.class)
public void constructorThrowsOnEmptyScopeID() throws ProvisioningDeviceClientException {
// arrange
new NonStrictExpectations() {
{
mockedProvisioningDeviceClientConfig.getIdScope();
result = "";
}
};
// act
ContractAPIHttp contractAPIHttp = new ContractAPIHttp(mockedProvisioningDeviceClientConfig);
// assert
}
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 authenticateWithDPSThrowsOnNullResponseCallback.
@Test(expected = ProvisioningDeviceClientException.class)
public void authenticateWithDPSThrowsOnNullResponseCallback() throws ProvisioningDeviceClientException {
// arrange
final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
}
};
// act
contractAPIHttp.authenticateWithProvisioningService(mockedRequestData, null, null);
}
Aggregations