use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method invoke_throwOnsetReadTimeoutMillis_failed.
/* Tests_SRS_DEVICE_OPERATIONS_21_009: [The request shall add to the HTTP header the sum of timeout and default timeout in milliseconds.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnsetReadTimeoutMillis_failed(@Mocked IotHubServiceSasToken iotHubServiceSasToken, @Mocked HttpRequest httpRequest) throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubServiceSasToken.toString();
result = STANDARD_SASTOKEN_STRING;
httpRequest.setReadTimeoutMillis(DEFAULT_HTTP_TIMEOUT_MS);
result = new IllegalArgumentException();
}
};
//act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method invoke_throwOnRequestID_failed.
/* Tests_SRS_DEVICE_OPERATIONS_21_011: [The request shall add to the HTTP header a `Request-Id` key with a new unique string value for every request.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnRequestID_failed(@Mocked IotHubServiceSasToken iotHubServiceSasToken, @Mocked HttpRequest httpRequest) throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubServiceSasToken.toString();
result = STANDARD_SASTOKEN_STRING;
httpRequest.setReadTimeoutMillis(DEFAULT_HTTP_TIMEOUT_MS);
result = httpRequest;
httpRequest.setHeaderField(AUTHORIZATION, STANDARD_SASTOKEN_STRING);
result = httpRequest;
httpRequest.setHeaderField(REQUEST_ID, STANDARD_REQUEST_ID);
result = new IllegalArgumentException();
}
};
//act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method invoke_throwOnHttpRequest_failed.
/* Tests_SRS_DEVICE_OPERATIONS_21_008: [The request shall create a new HttpRequest with the provided `url`, http `method`, and `payload`.] */
@Test(expected = IOException.class)
public void invoke_throwOnHttpRequest_failed(@Mocked IotHubServiceSasToken iotHubServiceSasToken) throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubServiceSasToken.toString();
result = STANDARD_SASTOKEN_STRING;
}
};
new MockUp<HttpRequest>() {
@Mock
void $init(URL url, HttpMethod method, byte[] body) throws IOException {
throw new IOException();
}
};
//act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, DEFAULT_HTTP_TIMEOUT_MS);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method invoke_throwOnSasTokenEmpty_failed.
/* Tests_SRS_DEVICE_OPERATIONS_21_007: [If the SASToken is null or empty, the request shall throw IOException.] */
@Test(expected = IOException.class)
public void invoke_throwOnSasTokenEmpty_failed(@Mocked IotHubServiceSasToken iotHubServiceSasToken) throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubServiceSasToken.toString();
result = "";
}
};
//act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse in project azure-iot-sdk-java by Azure.
the class DeviceOperationsTest method invoke_throwOnContentType_failed.
/* Tests_SRS_DEVICE_OPERATIONS_21_014: [The request shall add to the HTTP header a `Content-Type` key with `application/json; charset=utf-8`.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnContentType_failed(@Mocked IotHubServiceSasToken iotHubServiceSasToken, @Mocked HttpRequest httpRequest) throws Exception {
//arrange
new NonStrictExpectations() {
{
iotHubServiceSasToken.toString();
result = STANDARD_SASTOKEN_STRING;
httpRequest.setReadTimeoutMillis(DEFAULT_HTTP_TIMEOUT_MS);
result = httpRequest;
httpRequest.setHeaderField(AUTHORIZATION, STANDARD_SASTOKEN_STRING);
result = httpRequest;
httpRequest.setHeaderField(REQUEST_ID, STANDARD_REQUEST_ID);
result = httpRequest;
httpRequest.setHeaderField(USER_AGENT, TransportUtils.getJavaServiceClientIdentifier() + TransportUtils.getServiceVersion());
result = httpRequest;
httpRequest.setHeaderField(ACCEPT, ACCEPT_VALUE);
result = httpRequest;
httpRequest.setHeaderField(CONTENT_TYPE, ACCEPT_VALUE + "; " + ACCEPT_CHARSET);
result = new IllegalArgumentException();
}
};
//act
HttpResponse response = DeviceOperations.request(IOT_HUB_CONNECTION_STRING, new URL(STANDARD_URL), HttpMethod.POST, STANDARD_PAYLOAD, STANDARD_REQUEST_ID, 0);
}
Aggregations