Search in sources :

Example 36 with HttpMethod

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);
        }
    };
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpMethod(com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod) Test(org.junit.Test)

Example 37 with HttpMethod

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();
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) IOException(java.io.IOException) NonStrictExpectations(mockit.NonStrictExpectations) HttpMethod(com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod) Test(org.junit.Test)

Example 38 with HttpMethod

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();
        }
    };
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpMethod(com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod) Test(org.junit.Test)

Example 39 with HttpMethod

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());
        }
    };
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpMethod(com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Test(org.junit.Test)

Example 40 with HttpMethod

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);
        }
    };
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) HttpMethod(com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod) Test(org.junit.Test)

Aggregations

HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)42 Test (org.junit.Test)42 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)30 NonStrictExpectations (mockit.NonStrictExpectations)26 HttpRequest (com.microsoft.azure.sdk.iot.deps.transport.http.HttpRequest)16 IOException (java.io.IOException)13 Verifications (mockit.Verifications)11 HttpResponse (com.microsoft.azure.sdk.iot.deps.transport.http.HttpResponse)6 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 URL (java.net.URL)3 Map (java.util.Map)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1