use of com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method setHeaderFieldSetsHeaderField.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSREQUEST_12_009: [The function shall set the header field with the given name to the given value.]
@Test
public void setHeaderFieldSetsHeaderField(@Mocked final HttpConnection mockConn) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.POST;
final byte[] body = new byte[0];
final String field = "test-field";
final String value = "test-value";
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
}
};
HttpRequest request = new HttpRequest(mockUrl, httpsMethod, body);
// Act
request.setHeaderField(field, value);
// Assert
new Verifications() {
{
mockConn.setRequestHeader(field, value);
}
};
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorThrowsIoExceptionIfCannotSetupConnection.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSREQUEST_12_004: [If an IOException occurs in setting up the HTTPS connection, the function shall throw an IOException.]
// Assert
@Test(expected = IOException.class)
public void constructorThrowsIoExceptionIfCannotSetupConnection(@Mocked final HttpConnection mockConn) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
new HttpConnection(mockUrl, httpsMethod);
result = new IOException();
}
};
// Act
new HttpRequest(mockUrl, httpsMethod, body);
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorOpensConnection.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSREQUEST_12_001: [The function shall open a connection with the given URL as the endpoint.]
@Test
public void constructorOpensConnection(@Mocked final HttpConnection mockConn) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
final byte[] body = new byte[0];
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
}
};
// Act
new HttpRequest(mockUrl, httpsMethod, body);
// Assert
new Verifications() {
{
new HttpConnection(mockUrl, (HttpMethod) any);
}
};
}
Aggregations