Search in sources :

Example 41 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 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();
        }
    };
}
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 42 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 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));
}
Also used : HttpConnection(com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection) 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