use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpsRequestTest method constructorWritesBodyToConnection.
// Tests_SRS_HTTPSREQUEST_25_002: [The function shall write the body to the connection.]
@Test
public void constructorWritesBodyToConnection(@Mocked final HttpConnection mockConn, @Mocked final URL mockUrl) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
final byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
}
};
// Act
new HttpRequest(mockUrl, httpsMethod, body);
// Assert
new Verifications() {
{
new HttpConnection(mockUrl, (HttpMethod) any).writeOutput(body);
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method connectStreamsRequestBody.
// Tests_SRS_HTTPSCONNECTION_25_006: [The function shall stream the request body, if present, through the connection.]
@Test
public void connectStreamsRequestBody() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
byte[] body = { 1, 2, 3 };
final byte[] expectedBody = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
body[0] = 5;
conn.connect();
// Assert
new Verifications() {
{
mockUrl.openConnection().getOutputStream().write(expectedBody);
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method constructorRejectsNonHttpsUrl.
// Tests_SRS_HTTPSCONNECTION_25_004: [If the URI given does not use the HTTPS protocol, the constructor shall throw an IllegalArgumentException.]
// Assert
@Test(expected = IllegalArgumentException.class)
public void constructorRejectsNonHttpsUrl() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "http";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
new HttpConnection(mockUrl, httpsMethod);
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method constructorThrowsIoExceptionIfCannotOpenConnection.
// Tests_SRS_HTTPSCONNECTION_25_002: [The constructor shall throw an IOException if the connection was unable to be opened.]
// Assert
@Test(expected = IOException.class)
public void constructorThrowsIoExceptionIfCannotOpenConnection() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = new IOException();
}
};
// Act
new HttpConnection(mockUrl, httpsMethod);
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method readErrorFailsIfCannotAccessErrorStream.
// Tests_SRS_HTTPSCONNECTION_25_018: [The function shall throw an IOException if the error stream could not be accessed.]
// Assert
@Test(expected = IOException.class)
public void readErrorFailsIfCannotAccessErrorStream() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getErrorStream();
result = new IOException();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.readError();
}
Aggregations