use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method setReadTimeoutSetsRequestTimeout.
// Tests_SRS_HTTPSCONNECTION_25_011: [The function shall set the read timeout to the given value.]
@Test
public void setReadTimeoutSetsRequestTimeout() throws IOException {
// Arrange
final HttpMethod httpsMethod = HttpMethod.POST;
final String field = "test-field";
final String value = "test-value";
final int timeout = 1;
new NonStrictExpectations() {
{
mockUrl.getProtocol();
result = "https";
mockUrl.openConnection();
result = mockUrlConn;
mockUrlConn.getRequestMethod();
result = httpsMethod.name();
}
};
HttpConnection conn = new HttpConnection(mockUrl, httpsMethod);
// Act
conn.setReadTimeoutMillis(timeout);
// Assert
new Verifications() {
{
mockUrl.openConnection().setReadTimeout(timeout);
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod in project azure-iot-sdk-java by Azure.
the class HttpConnectionTest method connectThrowsIoExceptionIfCannotConnect.
// Tests_SRS_HTTPSCONNECTION_25_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();
}
use of com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod 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.HttpMethod 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.HttpMethod 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);
}
};
}
Aggregations