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 getRegistrationStatusThrowsOnEmptyOperationId.
@Test(expected = ProvisioningDeviceClientException.class)
public void getRegistrationStatusThrowsOnEmptyOperationId() throws ProvisioningDeviceClientException {
// arrange
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getOperationId();
result = "";
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
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 prepareRequestThrowsOnInvalidTimeout.
@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnInvalidTimeout() throws Exception {
// arrange
final byte[] expectedPayload = "TestBytes".getBytes(StandardCharsets.UTF_8);
final String expectedUserAgentValue = "TestUserAgent";
ContractAPIHttp contractAPIHttp = createContractClass();
// act
Deencapsulation.invoke(contractAPIHttp, "prepareRequest", new Class[] { URL.class, HttpMethod.class, byte[].class, Integer.class, Map.class, String.class }, mockedUrl, HttpMethod.PUT, expectedPayload, -2, null, expectedUserAgentValue);
// 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 prepareRequestThrowsOnNullUrl.
@Test(expected = IllegalArgumentException.class)
public void prepareRequestThrowsOnNullUrl() throws Exception {
// arrange
final byte[] expectedPayload = "TestBytes".getBytes(StandardCharsets.UTF_8);
final String expectedUserAgentValue = "TestUserAgent";
ContractAPIHttp contractAPIHttp = createContractClass();
// act
Deencapsulation.invoke(contractAPIHttp, "prepareRequest", new Class[] { URL.class, HttpMethod.class, byte[].class, Integer.class, Map.class, String.class }, null, HttpMethod.PUT, expectedPayload, 0, null, expectedUserAgentValue);
// 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 requestNonceWithDPSTPMThrowsOnNullResponseCallback.
@Test(expected = ProvisioningDeviceClientException.class)
public void requestNonceWithDPSTPMThrowsOnNullResponseCallback() throws ProvisioningDeviceClientException {
// arrange
final byte[] expectedPayload = "testByte".getBytes(StandardCharsets.UTF_8);
ContractAPIHttp contractAPIHttp = createContractClass();
new NonStrictExpectations() {
{
mockedRequestData.getRegistrationId();
result = TEST_REGISTRATION_ID;
mockedRequestData.getEndorsementKey();
result = TEST_EK;
mockedRequestData.getStorageRootKey();
result = TEST_SRK;
mockedRequestData.getSslContext();
result = mockedSslContext;
}
};
// act
contractAPIHttp.requestNonceForTPM(mockedRequestData, null, 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 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;
}
};
}
}
Aggregations