use of com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorSetsHttpsMethodCorrectly.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSREQUEST_12_003: [The function shall use the given HTTPS method (i.e. GET) as the request method.]
@Test
public void constructorSetsHttpsMethodCorrectly(@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((URL) any, httpsMethod);
}
};
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorWritesBodyToConnection.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSREQUEST_12_002: [The function shall write the body to the connection.]
@Test
public void constructorWritesBodyToConnection(@Mocked final HttpConnection mockConn) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
final byte[] body = { 1, 2, 3 };
final byte[] expectedBody = body;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
}
};
// Act
new HttpRequest(mockUrl, httpsMethod, body);
// Assert
new Verifications() {
{
new HttpConnection(mockUrl, (HttpMethod) any).writeOutput(expectedBody);
}
};
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection 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.HttpConnection 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);
}
};
}
use of com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method connectThrowsIoExceptionIfCannotConnect.
// Tests_SRS_SERVICE_SDK_JAVA_HTTPSCONNECTION_12_007: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
// Assert
@Test(expected = IOException.class)
public void connectThrowsIoExceptionIfCannotConnect() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.connect();
result = new IOException();
}
};
// Act
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
}
Aggregations