Giter VIP home page Giter VIP logo

integration-tests-demo's Introduction

integration-tests-demo

A Java REST API to demonstrate how integration tests can be made with Rest Assured and Wiremock.

Application content

The application is a REST API of person domain composed by:

  • HTTP GET endpoint exposed at /persons that returns all the persons;
  • HTTP GET endpoint exposed at /persons/{id} that returns the given person id;
  • HTTP POST endpoint exposed at /persons that registers the given person and return a Location header with only the created person id;
  • HTTP GET endpoint exposed at /check-cpfthat returns HTTP OK - 200 when the called API responds successfully and HTTP BAD REQUEST - 400 when the called API responds anything different (this endpoint is only used for testing by stubbing the called API with an invalid response).

Running the application

Just run the main class application src/main/java/com/ariielm/integrationtestsdemo/IntegrationTestsDemoApplication.java Postman on the IDE or with Maven spring-boot:run.

To test the application, just use the Postman collection located at

Tests with only Rest Assured

Run the src/test/java/com/ariielm/integrationtestsdemo/controller/PersonControllerTestIT.java on your IDE. The Spring boot context will be created, then the Rest Assured will invoke the /persons endpoints (e.g. line 27) and make the asserts to check if the application is working perfectly (e.g. line 31).

Tests with Rest Assured and Wiremock

Run the src/test/java/com/ariielm/integrationtestsdemo/controller/CheckCPFControllerTest.java on your IDE. The Spring boot context will be created on a dynamic port, the Wiremock API will be created on a different dynamic port, then Wiremock will stub the called endpoint (line 22), the Rest Assured will invoke the /check-cpf endpoint (line 30) and make the asserts to check if the application is working perfectly (line 32).

integration-tests-demo's People

Contributors

ariielm avatar

Watchers

 avatar

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.