Search in sources :

Example 1 with MockClient

use of feign.mock.MockClient in project feign by OpenFeign.

the class AbstractMetricsTestBase method decoderExceptionCounterHasUriLabelWithPathExpression.

@Test
public void decoderExceptionCounterHasUriLabelWithPathExpression() {
    final AtomicReference<FeignException.NotFound> notFound = new AtomicReference<>();
    final SourceWithPathExpressions source = Feign.builder().client(new MockClient().ok(HttpMethod.GET, "/get/123", "1234567890abcde")).decoder((response, type) -> {
        notFound.set(new FeignException.NotFound("test", response.request(), null, null));
        throw notFound.get();
    }).addCapability(createMetricCapability()).target(new MockTarget<>(MicrometerCapabilityTest.SourceWithPathExpressions.class));
    FeignException.NotFound thrown = assertThrows(FeignException.NotFound.class, () -> source.get("123", "0x3456789"));
    assertSame(notFound.get(), thrown);
    final Map<METRIC_ID, METRIC> decoderMetrics = getFeignMetrics().entrySet().stream().filter(entry -> isDecoderMetric(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    decoderMetrics.keySet().forEach(metricId -> assertThat("Expect all Decoder metric names to include uri as aggregated path expression:" + metricId, doesMetricIncludeUri(metricId, "/get/{id}")));
}
Also used : MockTarget(feign.mock.MockTarget) HttpMethod(feign.mock.HttpMethod) Map(java.util.Map) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) MockClient(feign.mock.MockClient) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) feign(feign) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) Before(org.junit.Before) AtomicReference(java.util.concurrent.atomic.AtomicReference) Map(java.util.Map) MockClient(feign.mock.MockClient) Test(org.junit.Test)

Example 2 with MockClient

use of feign.mock.MockClient in project feign by OpenFeign.

the class SpringContractTest method setup.

@Before
public void setup() throws IOException {
    mockClient = new MockClient().noContent(HttpMethod.GET, "/health").noContent(HttpMethod.GET, "/health/1").noContent(HttpMethod.GET, "/health/1?deep=true").noContent(HttpMethod.GET, "/health/1?deep=true&dryRun=true").ok(HttpMethod.GET, "/health/generic", "{}");
    resource = Feign.builder().contract(new SpringContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder()).client(mockClient).target(new MockTarget<>(HealthResource.class));
}
Also used : JacksonEncoder(feign.jackson.JacksonEncoder) MockTarget(feign.mock.MockTarget) MockClient(feign.mock.MockClient) JacksonDecoder(feign.jackson.JacksonDecoder) Before(org.junit.Before)

Example 3 with MockClient

use of feign.mock.MockClient in project feign by OpenFeign.

the class AbstractMetricsTestBase method decoderPropagatesUncheckedException.

@Test
public void decoderPropagatesUncheckedException() {
    final AtomicReference<FeignException.NotFound> notFound = new AtomicReference<>();
    final SimpleSource source = Feign.builder().client(new MockClient().ok(HttpMethod.GET, "/get", "1234567890abcde")).decoder((response, type) -> {
        notFound.set(new FeignException.NotFound("test", response.request(), null, null));
        throw notFound.get();
    }).addCapability(createMetricCapability()).target(new MockTarget<>(MicrometerCapabilityTest.SimpleSource.class));
    FeignException.NotFound thrown = assertThrows(FeignException.NotFound.class, () -> source.get("0x3456789"));
    assertSame(notFound.get(), thrown);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) MockClient(feign.mock.MockClient) Test(org.junit.Test)

Example 4 with MockClient

use of feign.mock.MockClient in project feign by OpenFeign.

the class JsonCodecTest method setUp.

@Before
public void setUp() {
    mockClient = new MockClient();
    github = Feign.builder().decoder(new JsonDecoder()).encoder(new JsonEncoder()).client(mockClient).target(new MockTarget<>(GitHub.class));
}
Also used : MockTarget(feign.mock.MockTarget) MockClient(feign.mock.MockClient) Before(org.junit.Before)

Aggregations

MockClient (feign.mock.MockClient)4 MockTarget (feign.mock.MockTarget)3 Before (org.junit.Before)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 feign (feign)1 JacksonDecoder (feign.jackson.JacksonDecoder)1 JacksonEncoder (feign.jackson.JacksonEncoder)1 HttpMethod (feign.mock.HttpMethod)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1 Assert (org.junit.Assert)1