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 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;
}
};
}
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 getRegistrationStatusThrowsOnNullRegistrationId.
@Test(expected = ProvisioningDeviceClientException.class)
public void getRegistrationStatusThrowsOnNullRegistrationId() throws ProvisioningDeviceClientException {
// arrange
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getOperationId();
result = TEST_OPERATION_ID;
mockedRequestData.getRegistrationId();
result = null;
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
}
};
// act
contractAPIHttp.getRegistrationStatus(mockedRequestData, mockedResponseCallback, null);
}
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 sendRequestThrowsOnSendFailure.
@Test(expected = IOException.class)
public void sendRequestThrowsOnSendFailure() throws Exception {
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedHttpRequest.send();
result = new IOException("Send failure");
}
};
// act
Deencapsulation.invoke(contractAPIHttp, "sendRequest", mockedHttpRequest);
// 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 getRegistrationStatusThrowsOnEmptyRegistrationId.
@Test(expected = ProvisioningDeviceClientException.class)
public void getRegistrationStatusThrowsOnEmptyRegistrationId() throws ProvisioningDeviceClientException {
// arrange
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getOperationId();
result = TEST_OPERATION_ID;
mockedRequestData.getRegistrationId();
result = "";
mockedRequestData.getSslContext();
result = mockedSslContext;
mockedRequestData.getSasToken();
result = null;
}
};
// act
contractAPIHttp.getRegistrationStatus(mockedRequestData, mockedResponseCallback, null);
}
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 constructorSucceeds.
// SRS_ContractAPIHttp_25_001: [The constructor shall save the scope id and hostname.]
@Test
public void constructorSucceeds() throws ProvisioningDeviceClientException {
// arrange
new NonStrictExpectations() {
{
mockedProvisioningDeviceClientConfig.getIdScope();
result = TEST_SCOPE_ID;
mockedProvisioningDeviceClientConfig.getProvisioningServiceGlobalEndpoint();
result = TEST_HOST_NAME;
}
};
// act
ContractAPIHttp contractAPIHttp = new ContractAPIHttp(mockedProvisioningDeviceClientConfig);
// assert
assertEquals(TEST_SCOPE_ID, Deencapsulation.getField(contractAPIHttp, "idScope"));
assertEquals(TEST_HOST_NAME, Deencapsulation.getField(contractAPIHttp, "hostName"));
}
Aggregations