Git Product home page Git Product logo

feign-mock's Introduction

The contents of this project was donated to Feign project and it’s now available as part of Feig.

feign-mock

Build Status Coverage Status Maven Central Issues Forks Stars

An easy way to test https://github.com/Netflix/feign. Since feign stores most of the logic in annotations, this helps to check if the annotations are correct.

The original article is available here

If mocking feign clients is easy, testing the logic written in annotations is not!

To check if you are parsing the request/response properly, the only way is firing a real request. Well, that doesn’t seem to be a good path to unit (or even integration) test remote services. Any IO change will affect test stability.

That is why I created feign-mock.

With feign-mock you can use pre-loaded JSON strings or streams as content for your responses. It also allows you to verify mocked invocations and feign-mock will hit your annotations to make sure everything works.

Example
  private GitHub github;
  private MockClient mockClient;

  @Before
  public void setup() throws IOException {
    mockClient = new MockClient()
        .noContent(HttpMethod.PATCH, "/repos/velo/feign-mock/contributors");

    github = Feign.builder()
        .decoder(new GsonDecoder())
        .client(mockClient)
        .target(new MockTarget<>(GitHub.class));
  }

  @After
  public void tearDown() {
    mockClient.verifyStatus();
  }

  @Test
  public void missHttpMethod() {
    List<Contributor> result = github.patchContributors("velo", "feign-mock");
    assertThat(result, nullValue());
    mockClient.verifyOne(HttpMethod.PATCH, "/repos/velo/feign-mock/contributors");
  }

This simple test returns no content and verifies that the URL was truly invoked.

On the mocked client, you can include all URLs and methods you want to mock.

For more comprehensive examples take a look at MockClientTest.

feign-mock's People

Contributors

sergiandreplace avatar velo avatar vermgit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

feign-mock's Issues

Support fallback

Would be nice if this could also include for fallback classes.
As far as I could see, this is not supported, yet, right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.