Package feign

Examples of feign.MethodMetadata


  public static final class JAXRSContract extends Contract.BaseContract {

    @Override
    public MethodMetadata parseAndValidatateMetadata(Method method) {
      MethodMetadata md = super.parseAndValidatateMetadata(method);
      Path path = method.getDeclaringClass().getAnnotation(Path.class);
      if (path != null) {
        String pathValue = emptyToNull(path.value());
        checkState(pathValue != null, "Path.value() was empty on type %s", method.getDeclaringClass().getName());
        if (!pathValue.startsWith("/")) {
            pathValue = "/" + pathValue;
        }
        md.template().insert(0, pathValue);
      }
      return md;
    }
View Full Code Here


    @PATCH Response patch(URI nextLink);
  }

  @Test public void requestLineOnlyRequiresMethod() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(CustomMethodAndURIParam.class.getDeclaredMethod("patch",
        URI.class));
    assertEquals(md.template().method(), "PATCH");
    assertEquals(md.template().url(), "");
    assertTrue(md.template().queries().isEmpty());
    assertTrue(md.template().headers().isEmpty());
    assertNull(md.template().body());
    assertNull(md.template().bodyTemplate());
    assertEquals(md.urlIndex(), Integer.valueOf(0));
  }
View Full Code Here

    @GET @Path("/?flag&Action=GetUser&Version=2010-05-08") Response empty();
  }

  @Test public void queryParamsInPathExtract() throws Exception {
    {
      MethodMetadata md = contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("none"));
      assertEquals(md.template().url(), "/");
      assertTrue(md.template().queries().isEmpty());
      assertEquals(md.template().toString(), "GET / HTTP/1.1\n");
    }
    {
      MethodMetadata md = contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("one"));
      assertEquals(md.template().url(), "/");
      assertEquals(md.template().queries().get("Action"), ImmutableSet.of("GetUser"));
      assertEquals(md.template().toString(), "GET /?Action=GetUser HTTP/1.1\n");
    }
    {
      MethodMetadata md = contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("two"));
      assertEquals(md.template().url(), "/");
      assertEquals(md.template().queries().get("Action"), ImmutableSet.of("GetUser"));
      assertEquals(md.template().queries().get("Version"), ImmutableSet.of("2010-05-08"));
      assertEquals(md.template().toString(), "GET /?Action=GetUser&Version=2010-05-08 HTTP/1.1\n");
    }
    {
      MethodMetadata md = contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("three"));
      assertEquals(md.template().url(), "/");
      assertEquals(md.template().queries().get("Action"), ImmutableSet.of("GetUser"));
      assertEquals(md.template().queries().get("Version"), ImmutableSet.of("2010-05-08"));
      assertEquals(md.template().queries().get("limit"), ImmutableSet.of("1"));
      assertEquals(md.template().toString(), "GET /?Action=GetUser&Version=2010-05-08&limit=1 HTTP/1.1\n");
    }
    {
      MethodMetadata md = contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("empty"));
      assertEquals(md.template().url(), "/");
      assertTrue(md.template().queries().containsKey("flag"));
      assertEquals(md.template().queries().get("Action"), ImmutableSet.of("GetUser"));
      assertEquals(md.template().queries().get("Version"), ImmutableSet.of("2010-05-08"));
      assertEquals(md.template().toString(), "GET /?flag&Action=GetUser&Version=2010-05-08 HTTP/1.1\n");
    }
  }
View Full Code Here

    @POST @Consumes({""}) Response consumesEmpty();
  }

  @Test public void producesAddsAcceptHeader() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(ProducesAndConsumes.class.getDeclaredMethod("produces"));
    assertEquals(md.template().headers().get(ACCEPT), ImmutableSet.of(APPLICATION_XML));
  }
View Full Code Here

  public void producesEmpty() throws Exception {
    contract.parseAndValidatateMetadata(ProducesAndConsumes.class.getDeclaredMethod("producesEmpty"));
  }

  @Test public void consumesAddsContentTypeHeader() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(ProducesAndConsumes.class.getDeclaredMethod("consumes"));
    assertEquals(md.template().headers().get(CONTENT_TYPE), ImmutableSet.of(APPLICATION_JSON));
  }
View Full Code Here

    @POST Response tooMany(List<String> body, List<String> body2);
  }

  @Test public void bodyParamIsGeneric() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(BodyParams.class.getDeclaredMethod("post",
        List.class));
    assertNull(md.template().body());
    assertNull(md.template().bodyTemplate());
    assertNull(md.urlIndex());
    assertEquals(md.bodyIndex(), Integer.valueOf(0));
    assertEquals(md.bodyType(), new TypeToken<List<String>>() {
    }.getType());
  }
View Full Code Here

    @GET @Path("/{param}") Response emptyPathParam(@PathParam("") String empty);
  }

  @Test public void pathOnType() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(PathOnType.class.getDeclaredMethod("base"));
    assertEquals(md.template().url(), "/base");
    md = contract.parseAndValidatateMetadata(PathOnType.class.getDeclaredMethod("get"));
    assertEquals(md.template().url(), "/base/specific");
  }
View Full Code Here

  interface WithURIParam {
    @GET @Path("/{1}/{2}") Response uriParam(@PathParam("1") String one, URI endpoint, @PathParam("2") String two);
  }

  @Test public void methodCanHaveUriParam() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(WithURIParam.class.getDeclaredMethod("uriParam", String.class,
        URI.class, String.class));
    assertEquals(md.urlIndex(), Integer.valueOf(1));
  }
View Full Code Here

        URI.class, String.class));
    assertEquals(md.urlIndex(), Integer.valueOf(1));
  }

  @Test public void pathParamsParseIntoIndexToName() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(WithURIParam.class.getDeclaredMethod("uriParam", String.class,
        URI.class, String.class));
    assertEquals(md.template().url(), "/{1}/{2}");
    assertEquals(md.indexToName().get(0), ImmutableSet.of("1"));
    assertEquals(md.indexToName().get(2), ImmutableSet.of("2"));
  }
View Full Code Here

    @GET Response emptyQueryParam(@QueryParam("") String empty);
  }

  @Test public void mixedRequestLineParams() throws Exception {
    MethodMetadata md = contract.parseAndValidatateMetadata(WithPathAndQueryParams.class.getDeclaredMethod
        ("recordsByNameAndType", int.class, String.class, String.class));
    assertNull(md.template().body());
    assertNull(md.template().bodyTemplate());
    assertTrue(md.template().headers().isEmpty());
    assertEquals(md.template().url(), "/domains/{domainId}/records");
    assertEquals(md.template().queries().get("name"), ImmutableSet.of("{name}"));
    assertEquals(md.template().queries().get("type"), ImmutableSet.of("{type}"));
    assertEquals(md.indexToName().get(0), ImmutableSet.of("domainId"));
    assertEquals(md.indexToName().get(1), ImmutableSet.of("name"));
    assertEquals(md.indexToName().get(2), ImmutableSet.of("type"));
    assertEquals(md.template().toString(), "GET /domains/{domainId}/records?name={name}&type={type} HTTP/1.1\n");
  }
View Full Code Here

TOP

Related Classes of feign.MethodMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.