Search in sources :

Example 1 with MethodMetadata

use of feign.MethodMetadata in project feign by OpenFeign.

the class JAXRSContractTest method producesAddsAcceptHeader.

@Test
public void producesAddsAcceptHeader() throws Exception {
    MethodMetadata md = parseAndValidateMetadata(ProducesAndConsumes.class, "produces");
    assertThat(md.template()).hasHeaders(entry("Content-Type", asList("application/json")), entry("Accept", asList("application/xml")));
}
Also used : MethodMetadata(feign.MethodMetadata) Test(org.junit.Test)

Example 2 with MethodMetadata

use of feign.MethodMetadata in project feign by OpenFeign.

the class JAXRSContractTest method bodyParamIsGeneric.

@Test
public void bodyParamIsGeneric() throws Exception {
    MethodMetadata md = parseAndValidateMetadata(BodyParams.class, "post", List.class);
    assertThat(md.bodyIndex()).isEqualTo(0);
    assertThat(md.bodyType()).isEqualTo(getClass().getDeclaredField("STRING_LIST").getGenericType());
}
Also used : MethodMetadata(feign.MethodMetadata) Test(org.junit.Test)

Example 3 with MethodMetadata

use of feign.MethodMetadata in project feign by OpenFeign.

the class JAXRSContractTest method headerParamsParseIntoIndexToName.

@Test
public void headerParamsParseIntoIndexToName() throws Exception {
    MethodMetadata md = parseAndValidateMetadata(HeaderParams.class, "logout", String.class);
    assertThat(md.template()).hasHeaders(entry("Auth-Token", asList("{Auth-Token}")));
    assertThat(md.indexToName()).containsExactly(entry(0, asList("Auth-Token")));
}
Also used : MethodMetadata(feign.MethodMetadata) Test(org.junit.Test)

Example 4 with MethodMetadata

use of feign.MethodMetadata in project feign by OpenFeign.

the class JAXRSContractTest method consumesAddsContentTypeHeader.

@Test
public void consumesAddsContentTypeHeader() throws Exception {
    MethodMetadata md = parseAndValidateMetadata(ProducesAndConsumes.class, "consumes");
    assertThat(md.template()).hasHeaders(entry("Accept", asList("text/html")), entry("Content-Type", asList("application/xml")));
}
Also used : MethodMetadata(feign.MethodMetadata) Test(org.junit.Test)

Example 5 with MethodMetadata

use of feign.MethodMetadata in project feign by OpenFeign.

the class HystrixDelegatingContract method parseAndValidatateMetadata.

@Override
public List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) {
    List<MethodMetadata> metadatas = this.delegate.parseAndValidatateMetadata(targetType);
    for (MethodMetadata metadata : metadatas) {
        Type type = metadata.returnType();
        if (type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(HystrixCommand.class)) {
            Type actualType = resolveLastTypeParameter(type, HystrixCommand.class);
            metadata.returnType(actualType);
        } else if (type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(Observable.class)) {
            Type actualType = resolveLastTypeParameter(type, Observable.class);
            metadata.returnType(actualType);
        } else if (type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(Single.class)) {
            Type actualType = resolveLastTypeParameter(type, Single.class);
            metadata.returnType(actualType);
        } else if (type instanceof ParameterizedType && ((ParameterizedType) type).getRawType().equals(Completable.class)) {
            metadata.returnType(void.class);
        }
    }
    return metadatas;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) HystrixCommand(com.netflix.hystrix.HystrixCommand) Single(rx.Single) MethodMetadata(feign.MethodMetadata) Observable(rx.Observable)

Aggregations

MethodMetadata (feign.MethodMetadata)11 Test (org.junit.Test)9 HystrixCommand (com.netflix.hystrix.HystrixCommand)1 Client (feign.Client)1 Contract (feign.Contract)1 Request (feign.Request)1 Response (feign.Response)1 HardCodedTarget (feign.Target.HardCodedTarget)1 IOException (java.io.IOException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Setup (org.openjdk.jmh.annotations.Setup)1 Observable (rx.Observable)1 Single (rx.Single)1