Search in sources :

Example 1 with JAXRSContract

use of feign.jaxrs.JAXRSContract in project atlasdb by palantir.

the class TimestampRemotingTest method testNotLeader.

@Test
public void testNotLeader() {
    ObjectMapper mapper = new ObjectMapper();
    String uri = notLeader.baseUri().toString();
    TimestampService ts = Feign.builder().decoder(new JacksonDecoder(mapper)).encoder(new JacksonEncoder(mapper)).contract(new JAXRSContract()).retryer(new Retryer.Default(1, 1, 40)).target(TimestampService.class, notLeader.baseUri().toString());
    ts.getFreshTimestamp();
}
Also used : JacksonEncoder(feign.jackson.JacksonEncoder) JAXRSContract(feign.jaxrs.JAXRSContract) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Example 2 with JAXRSContract

use of feign.jaxrs.JAXRSContract in project atlasdb by palantir.

the class TimestampRemotingTest method testSerializing.

@Test
public void testSerializing() {
    ObjectMapper mapper = new ObjectMapper();
    String uri = dropwizard.baseUri().toString();
    TimestampService ts = Feign.builder().decoder(new JacksonDecoder(mapper)).encoder(new JacksonEncoder(mapper)).contract(new JAXRSContract()).target(TimestampService.class, uri);
    long freshTimestamp = ts.getFreshTimestamp();
    TimestampRange freshTimestamps = ts.getFreshTimestamps(100);
}
Also used : JacksonEncoder(feign.jackson.JacksonEncoder) JAXRSContract(feign.jaxrs.JAXRSContract) TimestampRange(com.palantir.timestamp.TimestampRange) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InMemoryTimestampService(com.palantir.timestamp.InMemoryTimestampService) TimestampService(com.palantir.timestamp.TimestampService) JacksonDecoder(feign.jackson.JacksonDecoder) Test(org.junit.Test)

Example 3 with JAXRSContract

use of feign.jaxrs.JAXRSContract in project feign by OpenFeign.

the class JAXRSClientTest method testConsumesMultipleWithContentTypeHeaderAndBody.

@Test
public void testConsumesMultipleWithContentTypeHeaderAndBody() throws Exception {
    server.enqueue(new MockResponse().setBody("AAAAAAAA"));
    final JaxRSClientTestInterfaceWithJaxRsContract api = newBuilder().contract(// use JAXRSContract
    new JAXRSContract()).target(JaxRSClientTestInterfaceWithJaxRsContract.class, "http://localhost:" + server.getPort());
    final Response response = api.consumesMultipleWithContentTypeHeaderAndBody("application/json;charset=utf-8", "body");
    assertEquals("AAAAAAAA", Util.toString(response.body().asReader(UTF_8)));
    MockWebServerAssertions.assertThat(server.takeRequest()).hasHeaders(MapEntry.entry("Content-Type", Collections.singletonList("application/json;charset=utf-8"))).hasMethod("POST");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) JAXRSContract(feign.jaxrs.JAXRSContract) AbstractClientTest(feign.client.AbstractClientTest) Test(org.junit.Test)

Example 4 with JAXRSContract

use of feign.jaxrs.JAXRSContract in project feign by OpenFeign.

the class ApacheHttp5ClientTest method queryParamsAreRespectedWhenBodyIsEmpty.

@Test
public void queryParamsAreRespectedWhenBodyIsEmpty() throws InterruptedException {
    final HttpClient httpClient = HttpClientBuilder.create().build();
    final JaxRsTestInterface testInterface = Feign.builder().contract(new JAXRSContract()).client(new ApacheHttp5Client(httpClient)).target(JaxRsTestInterface.class, "http://localhost:" + server.getPort());
    server.enqueue(new MockResponse().setBody("foo"));
    server.enqueue(new MockResponse().setBody("foo"));
    assertEquals("foo", testInterface.withBody("foo", "bar"));
    final RecordedRequest request1 = server.takeRequest();
    assertEquals("/withBody?foo=foo", request1.getPath());
    assertEquals("bar", request1.getBody().readString(StandardCharsets.UTF_8));
    assertEquals("foo", testInterface.withoutBody("foo"));
    final RecordedRequest request2 = server.takeRequest();
    assertEquals("/withoutBody?foo=foo", request2.getPath());
    assertEquals("", request2.getBody().readString(StandardCharsets.UTF_8));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HttpClient(org.apache.hc.client5.http.classic.HttpClient) JAXRSContract(feign.jaxrs.JAXRSContract) AbstractClientTest(feign.client.AbstractClientTest) Test(org.junit.Test)

Example 5 with JAXRSContract

use of feign.jaxrs.JAXRSContract in project feign by OpenFeign.

the class ApacheHttpClientTest method queryParamsAreRespectedWhenBodyIsEmpty.

@Test
public void queryParamsAreRespectedWhenBodyIsEmpty() throws InterruptedException {
    final HttpClient httpClient = HttpClientBuilder.create().build();
    final JaxRsTestInterface testInterface = Feign.builder().contract(new JAXRSContract()).client(new ApacheHttpClient(httpClient)).target(JaxRsTestInterface.class, "http://localhost:" + server.getPort());
    server.enqueue(new MockResponse().setBody("foo"));
    server.enqueue(new MockResponse().setBody("foo"));
    assertEquals("foo", testInterface.withBody("foo", "bar"));
    final RecordedRequest request1 = server.takeRequest();
    assertEquals("/withBody?foo=foo", request1.getPath());
    assertEquals("bar", request1.getBody().readString(StandardCharsets.UTF_8));
    assertEquals("foo", testInterface.withoutBody("foo"));
    final RecordedRequest request2 = server.takeRequest();
    assertEquals("/withoutBody?foo=foo", request2.getPath());
    assertEquals("", request2.getBody().readString(StandardCharsets.UTF_8));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HttpClient(org.apache.http.client.HttpClient) JAXRSContract(feign.jaxrs.JAXRSContract) AbstractClientTest(feign.client.AbstractClientTest) Test(org.junit.Test)

Aggregations

JAXRSContract (feign.jaxrs.JAXRSContract)6 Test (org.junit.Test)5 AbstractClientTest (feign.client.AbstractClientTest)3 JacksonDecoder (feign.jackson.JacksonDecoder)3 JacksonEncoder (feign.jackson.JacksonEncoder)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InMemoryTimestampService (com.palantir.timestamp.InMemoryTimestampService)2 TimestampService (com.palantir.timestamp.TimestampService)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 AtlasDbService (com.palantir.atlasdb.api.AtlasDbService)1 TimestampRange (com.palantir.timestamp.TimestampRange)1 HttpClient (org.apache.hc.client5.http.classic.HttpClient)1 HttpClient (org.apache.http.client.HttpClient)1 Before (org.junit.Before)1