Coder Social home page Coder Social logo

teads-wiremock-extensions's Introduction

WireMock Extensions Build Status

wiremock-extensions is a set of extensions for WireMock.

Installation

For now, wiremock-extensions is not published on Maven Central Repository.
The only way is through the WireMock standalone process.

  1. Download WireMock Jar
  2. Download Extension Jar
  3. Run
  java -cp "wiremock-standalone-2.8.0.jar:wiremock-extensions_2.11-0.15.jar" \
       com.github.tomakehurst.wiremock.standalone.WireMockServerRunner \
       --extensions tv.teads.wiremock.extension.JsonExtractor,tv.teads.wiremock.extension.Calculator,tv.teads.wiremock.extension.FreeMarkerRenderer,tv.teads.wiremock.extension.Randomizer

WireMock JSON Extractor

wiremock-json-extractor is a WireMock extension that can generate a response from a JSON request.
It recognizes all JSONPaths from the response's template and try to replace them by the correct value from the request. You can also specify a fallback value that will be use if nothing was found when searching for the JSONPath.

{
  "request": {
    "method": "POST",
    "url": "/some/url"
  },
  "response": {
    "status": 200,
    "body": "I found ${$.value} for $.value. Sadly, I found nothing for ${$.undefined},
       so I will have to use the fallback value: ${$.undefined§3}",
    "transformers": ["json-extractor"]
  }
}
POST /some/url HTTP/1.1
Content-Type: application/json
{ "value": 12 }
HTTP/1.1 200 OK
I found 12 for $.value. Sadly, I found nothing for ${$.undefined},
 so I will have to use the fallback value: 3

You can check every supported operators on the Gatling JSONPath Syntax documentation.

WireMock Calculator

{
  "request": {
    "method": "GET",
    "url": "/some/url"
  },
  "response": {
    "status": 200,
    "body": "What is the value of 1+2*3? Simple, it is: ${1+2*3}",
    "transformers": ["calculator"]
  }
}
GET /some/url HTTP/1.1
HTTP/1.1 200 OK
What is the value of 1+2*3? Simple, it is: 7

WireMock Randomizer

Random generators supported:

  • RandomInteger: integer values from 0 to Integer.MAX_VALUE
  • RandomDouble: double values from 0.0 to 1.0
  • RandomBoolean: true or false values
  • RandomFloat: float values from 0.0 to 1.0
  • RandomLong: absolute long values
  • RandomString: string of 10 characters
  • RandomUUID: random UUID
{
  "request": {
    "method": "GET",
    "url": "/some/url"
  },
  "response": {
    "status": 200,
    "body": "Random integer generated: @{RandomInteger}",
    "transformers": ["randomizer"]
  }
}
GET /some/url HTTP/1.1
HTTP/1.1 200 OK
Random integer generated: 784129741

WireMock FreeMarkerRenderer

wiremock-freemarker-renderer is a WireMock extension that can generate a response from a FreeMarker template.
It maps an incoming JSON request to a FreeMarker data model. $ can be used to call the root object. It allows a syntax close to JSONPath.

{
  "request": {
    "method": "POST",
    "url": "/some/url"
  },
  "response": {
    "status": 200,
    "body": "I found ${$.value} for $.value. Sadly, I found nothing for ${$.undefined!"$.undefined"}, 
       so I will have to use the fallback value: ${$.undefined!3}",
    "transformers": ["freemarker-renderer"]
  }
}
POST /some/url HTTP/1.1
Content-Type: application/json
{ "value": 12 }
HTTP/1.1 200 OK
I found 12 for $.value. Sadly, I found nothing for $.undefined, 
 so I will have to use the fallback value: 3

You can check all the possibilities on the FreeMarker documentation.

teads-wiremock-extensions's People

Contributors

alixba avatar elyrixia avatar nailyk avatar viewtiful avatar pdalpra avatar bjaglin 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.