Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mock Server Using WireMock

243 views

Published on

¿Los servicios no están listos? ¿Los microservicios externos que consume mi app son lentos en ambiente de pruebas? Qué hacer.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Mock Server Using WireMock

  1. 1. Rest APIs mocking with Wiremock GLOBANT TAE WEEK </>
  2. 2. ● What the Mock? ● Why mocking API? ● When mocking API? ● Wiremock ○ Installing ○ Stubs ● Demo stand alone ● Demo code AGENDA
  3. 3. What The Mock? mockable.io
  4. 4. WHY TO MOCK ● Simulate not available services/rest API ● Stable service ● Simulate errors
  5. 5. WHEN TO MOCK External APIs ● Authentication ● Rights ● Send requests, alerts, emails
  6. 6. WireMock Mock your APIs for fast, robust and comprehensive testing WireMock is a simulator for HTTP(S)-based APIs. Some might consider it a service virtualization tool or a mock server.
  7. 7. INSTALLING Maven Standard WireMock JAR <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock</artifactId> <version>2.19.0</version> <scope>test</scope> </dependency> Or standalone JAR <dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-standalone</artifactId> <version>2.19.0</version> </dependency> Gradle Standard WireMock JAR testCompile "com.github.tomakehurst:wiremock:2.19.0" Or standalone JAR testCompile "com.github.tomakehurst:wiremock-standalone:2.19.0"
  8. 8. JUnit 4.x import static com.github.tomakehurst.wiremock.client.WireMock.*; @Rule public WireMockRule wireMockRule = new WireMockRule(8089); // No-args constructor defaults to port 8080
  9. 9. Non-JUnit and general Java usage WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089)); //No-args constructor will start on port 8080, no HTTPS wireMockServer.start(); //WireMock.configureFor("wiremock.host", 8089); //Change the port //WireMock.configureFor("tomcat.host", 8080, "/wiremock"); //General path // Do some stuff WireMock.reset(); // Finish doing stuff wireMockServer.stop();
  10. 10. Demo with stand alone To run: java -jar wiremock-standalone-2.19.0.jar To see the history: http://localhost:8080/__admin/requests To see the mappings: http://localhost:8080/__admin/mappings Wiremock client
  11. 11. Demo with code Webhooks Event generator A Event generator B Send alerts Method: POST Server: alert_server Path: /alert Method: POST Server: webhook Path: /events
  12. 12. Thank you!

×