use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method readInputFailsIfCannotAccessInputStream.
// Tests_SRS_HTTPSCONNECTION_25_015: [The function shall throw an IOException if the input stream could not be accessed.]
// Assert
@Test(expected = IOException.class)
public void readInputFailsIfCannotAccessInputStream() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getInputStream();
result = new IOException();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.readInput();
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method setRequestMethodRejectsNonPostOrPutIfHasBody.
// Tests_SRS_HTTPSCONNECTION_25_009: [The function shall throw an IllegalArgumentException if the request currently has a non-empty body and the new method is not a POST or a PUT.]
// Assert
@Test(expected = IllegalArgumentException.class)
public void setRequestMethodRejectsNonPostOrPutIfHasBody() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.POST;
final HttpMethod illegalHttpsMethod = HttpMethod.DELETE;
final byte[] body = { 1, 2, 3 };
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
returns(httpsMethod.name(), illegalHttpsMethod.name());
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.writeOutput(body);
// Act
conn.setRequestMethod(illegalHttpsMethod);
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method getResponseHeadersFailsIfDidNotReceiveResponse.
// Tests_SRS_HTTPSCONNECTION_25_023: [The function shall throw an IOException if no response was received.]
// Assert
@Test(expected = IOException.class)
public void getResponseHeadersFailsIfDidNotReceiveResponse() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getHeaderFields();
result = new IOException();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.getResponseHeaders();
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method getResponseStatusFailsIfDidNotReceiveResponse.
// Tests_SRS_HTTPSCONNECTION_25_021: [The function shall throw an IOException if no response was received.]
// Assert
@Test(expected = IOException.class)
public void getResponseStatusFailsIfDidNotReceiveResponse(@Mocked final InputStream mockIs) throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getResponseCode();
result = new IOException();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.getResponseStatus();
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method readErrorClosesErrorStream.
// Tests_SRS_HTTPSCONNECTION_25_019: [The function shall close the error stream after it has been completely read.]
@Test
public void readErrorClosesErrorStream(@Mocked final InputStream mockIs) 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 = mockIs;
mockIs.read();
result = -1;
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
conn.readError();
// Assert
new Verifications() {
{
mockIs.close();
}
};
}
Aggregations