Search in sources :

Example 6 with RecordedRequest

use of okhttp3.mockwebserver.RecordedRequest in project sonarqube by SonarSource.

the class HttpConnectorTest method use_basic_authentication.

@Test
public void use_basic_authentication() throws Exception {
    answerHelloWorld();
    underTest = HttpConnector.newBuilder().url(serverUrl).credentials("theLogin", "thePassword").build();
    GetRequest request = new GetRequest("api/issues/search");
    underTest.call(request);
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(basic("theLogin", "thePassword"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 7 with RecordedRequest

use of okhttp3.mockwebserver.RecordedRequest in project zipkin by openzipkin.

the class HttpBulkSpanIndexerTest method doesntWriteSpanId.

@Test
public void doesntWriteSpanId() throws Exception {
    es.enqueue(new MockResponse());
    indexer.add("test_zipkin_http-2016-10-01", TestObjects.LOTS_OF_SPANS[0], (Long) null);
    indexer.execute(callback);
    callback.get();
    RecordedRequest request = es.takeRequest();
    assertThat(request.getBody().readByteString().utf8()).doesNotContain("\"_id\"");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 8 with RecordedRequest

use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.

the class AbstractMockWebServerTestCase method getRequest.

private MockResponse getRequest(RecordedRequest request, byte[] body, String contentType) {
    if (request.getMethod().equals("OPTIONS")) {
        return new MockResponse().setResponseCode(200).setHeader("Allow", "GET, OPTIONS, HEAD, TRACE");
    }
    Buffer buf = new Buffer();
    buf.write(body);
    MockResponse response = new MockResponse().setHeader("Content-Length", body.length).setBody(buf).setResponseCode(200);
    if (contentType != null) {
        response = response.setHeader("Content-Type", contentType);
    }
    return response;
}
Also used : Buffer(okio.Buffer) MockResponse(okhttp3.mockwebserver.MockResponse)

Example 9 with RecordedRequest

use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.

the class AbstractMockWebServerTestCase method putRequest.

private MockResponse putRequest(RecordedRequest request, String expectedRequestContent) {
    assertTrue("Invalid request content-length", Integer.parseInt(request.getHeader("Content-Length")) > 0);
    String requestContentType = request.getHeader("Content-Type");
    assertNotNull("No content-type", requestContentType);
    Charset charset = StandardCharsets.ISO_8859_1;
    if (requestContentType.contains("charset=")) {
        String charsetName = requestContentType.split("charset=")[1];
        charset = Charset.forName(charsetName);
    }
    assertEquals("Invalid request body", expectedRequestContent, request.getBody().readString(charset));
    return new MockResponse().setResponseCode(202);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Charset(java.nio.charset.Charset)

Example 10 with RecordedRequest

use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.

the class AbstractMockWebServerTestCase method postRequest.

private MockResponse postRequest(RecordedRequest request, String expectedRequestContent, String location, String contentType, byte[] responseBody) {
    assertEquals(1, request.getHeaders().values("Content-Length").size());
    assertTrue("Invalid request content-length", Integer.parseInt(request.getHeader("Content-Length")) > 0);
    String requestContentType = request.getHeader("Content-Type");
    assertNotNull("No content-type", requestContentType);
    Charset charset = StandardCharsets.ISO_8859_1;
    if (requestContentType.contains("charset=")) {
        String charsetName = requestContentType.split("charset=")[1];
        charset = Charset.forName(charsetName);
    }
    assertEquals("Invalid request body", expectedRequestContent, request.getBody().readString(charset));
    Buffer buf = new Buffer();
    buf.write(responseBody);
    return new MockResponse().setHeader("Location", baseUrl + location).setHeader("Content-Type", contentType).setHeader("Content-Length", responseBody.length).setBody(buf).setResponseCode(201);
}
Also used : Buffer(okio.Buffer) MockResponse(okhttp3.mockwebserver.MockResponse) Charset(java.nio.charset.Charset)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)206 MockResponse (okhttp3.mockwebserver.MockResponse)188 Test (org.junit.Test)168 HttpURLConnection (java.net.HttpURLConnection)18 MockWebServer (okhttp3.mockwebserver.MockWebServer)14 IOException (java.io.IOException)13 URL (java.net.URL)13 OutputStream (java.io.OutputStream)12 Response (okhttp3.Response)12 OkHttpURLConnection (okhttp3.internal.huc.OkHttpURLConnection)12 AbstractTest (org.openstack4j.api.AbstractTest)12 Test (org.testng.annotations.Test)12 Call (okhttp3.Call)11 Buffer (okio.Buffer)11 Request (okhttp3.Request)8 RecordingOkAuthenticator (okhttp3.internal.RecordingOkAuthenticator)7 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 ByteString (okio.ByteString)6 CookieManager (java.net.CookieManager)5 URLConnection (java.net.URLConnection)5