use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method constructorOpensConnection.
// Tests_SRS_HTTPSCONNECTION_25_001: [The constructor shall open a connection to the given URL.]
@Test
public void constructorOpensConnection() throws IOException {
// Arrange
final HttpMethod httpMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
}
};
// Act
new HttpConnection(mockUrl, httpMethod);
// Assert
new Verifications() {
{
mockUrl.openConnection();
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method setRequestMethodSetsRequestMethod.
// Tests_SRS_HTTPSCONNECTION_25_008: [The function shall set the request method.]
@Test
public void setRequestMethodSetsRequestMethod() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.setRequestMethod(httpsMethod);
// Assert
new Verifications() {
{
((HttpsURLConnection) mockUrl.openConnection()).setRequestMethod(httpsMethod.name());
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method setRequestHeaderSetsRequestHeader.
// Tests_SRS_HTTPSCONNECTION_25_010: [The function shall set the given request header field.]
@Test
public void setRequestHeaderSetsRequestHeader() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.POST;
final String field = "test-field";
final String value = "test-value";
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
// Act
conn.setRequestHeader(field, value);
// Assert
new Verifications() {
{
mockUrl.openConnection().setRequestProperty(field, value);
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method connectUsesCorrectUrl.
// Tests_SRS_HTTPSCONNECTION_25_005: [The function shall send a request to the URL given in the constructor.]
@Test
public void connectUsesCorrectUrl() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.PUT;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
// Act
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Assert
new Verifications() {
{
mockUrl.openConnection().connect();
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method readErrorReturnsEmptyErrorReasonIfNoErrorReason.
// Tests_SRS_HTTPSCONNECTION_25_017: [The function shall read from the error stream and return the response.]
@Test
public void readErrorReturnsEmptyErrorReasonIfNoErrorReason() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.GET;
byte[] expectedError = {};
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
mockUrlConn.getErrorStream();
result = null;
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
conn.connect();
// Act
byte[] testError = conn.readError();
// Assert
assertThat(testError, is(expectedError));
}
Aggregations