Search in sources :

Example 1 with RecordedRequest

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

the class HttpConnectorTest method send_user_agent.

@Test
public void send_user_agent() throws Exception {
    answerHelloWorld();
    underTest = HttpConnector.newBuilder().url(serverUrl).userAgent("Maven Plugin/2.3").build();
    underTest.call(new GetRequest("api/issues/search"));
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getHeader("User-Agent")).isEqualTo("Maven Plugin/2.3");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 2 with RecordedRequest

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

the class HttpConnectorTest method use_access_token.

/**
   * Access token replaces the couple {login,password} and is sent through
   * the login field
   */
@Test
public void use_access_token() throws Exception {
    answerHelloWorld();
    underTest = HttpConnector.newBuilder().url(serverUrl).token("theToken").build();
    GetRequest request = new GetRequest("api/issues/search");
    underTest.call(request);
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(basic("theToken", ""));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 3 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 4 with RecordedRequest

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

the class WebhookCallerImplTest method send_posts_payload_to_http_server.

@Test
public void send_posts_payload_to_http_server() throws Exception {
    Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, "my-webhook", server.url("/ping").toString());
    server.enqueue(new MockResponse().setBody("pong").setResponseCode(201));
    WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
    assertThat(delivery.getHttpStatus().get()).isEqualTo(201);
    assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0);
    assertThat(delivery.getError()).isEmpty();
    assertThat(delivery.getAt()).isEqualTo(NOW);
    assertThat(delivery.getWebhook()).isSameAs(webhook);
    assertThat(delivery.getPayload()).isSameAs(PAYLOAD);
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getMethod()).isEqualTo("POST");
    assertThat(recordedRequest.getPath()).isEqualTo("/ping");
    assertThat(recordedRequest.getBody().readUtf8()).isEqualTo(PAYLOAD.getJson());
    assertThat(recordedRequest.getHeader("User-Agent")).isEqualTo("SonarQube/6.2");
    assertThat(recordedRequest.getHeader("Content-Type")).isEqualTo("application/json; charset=utf-8");
    assertThat(recordedRequest.getHeader("X-SonarQube-Project")).isEqualTo(PAYLOAD.getProjectKey());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 5 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)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)609 Test (org.junit.Test)426 MockResponse (okhttp3.mockwebserver.MockResponse)401 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)134 Test (org.junit.jupiter.api.Test)110 MockWebServer (okhttp3.mockwebserver.MockWebServer)51 ByteString (okio.ByteString)45 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)41 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)32 HttpHeaders (org.springframework.http.HttpHeaders)29 JsonObject (com.google.gson.JsonObject)26 Response (okhttp3.Response)26 EnqueueRequests (okhttp3.mockwebserver.EnqueueRequests)25 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)24 Dispatcher (okhttp3.mockwebserver.Dispatcher)23 Buffer (okio.Buffer)23 IOException (java.io.IOException)22 Instant (java.time.Instant)21 MediaType (org.springframework.http.MediaType)20 Test (org.testng.annotations.Test)20