Coder Social home page Coder Social logo

wiremock-acc's Introduction

Central Wiremock Repository

Curl Helper

Allows to make simple GET requests to remote resources. You can store the response in the local variable and extract some parts using jsonPath.

Example:
{
  // You should pass url into the body of the curl tag.
  // You can easily format the url with additional variables.
  "complex": "{{#assign 'relationData'}}{{#curl}}http://host/remote-relations/{{request.query.relationId}}{{/curl}}{{/assign}}{{jsonPath relationData '$.relationships[0].id'}}"
}

In Groovy script you can also have access to request thru variable "context" and to persistence thru variable "persistence".

Groovy Helper

Allows to use groovy to create response. You need to setup GROOVY_ROOT env variable to setup root path for groovy scripts. (default: ./groovy)

Example:
{
  // Use 'inline' property to set inline script
  // You can add any number of args, they will be available with given names.
  "simple": "{{groovy  arg1='request.body' arg2='request.headers' inline='context.get(arg1)'}}",
  // You can use this sintax to pass whichever is in between to variable 'inner' in script 
  "withInput": "{{#groovy arg1='request.body' arg2='request.headers' inline='context.get(arg2)'}}{{request.body}}{{/groovy}}",
   // Use 'scriptFilename' to set groovy script filename
  "file": "{{#groovy arg1='request.body' arg2='request.headers' scriptFilename='example.groovy'}}{{request.body}}{{/groovy}}",
  "vanilla": "{{jsonPath request.body '$.test'}}"
}

In Groovy script you can also have access to request thru variable "context" and to persistence thru variable "persistence".

Groovy Post Serve Action

Example:
{
  ...
  "postServeActions": {
    "groovy": {
      "inline": "script here",
      "scriptFileName": "relative path to GROOVY_ROOT", // mutually exclusive with inline
      "arguments": {
        "arg1": "val1",
        "arg2": "val2"
      }
    }
  },
  ...
}
Or multiple:
{
  ...
  "postServeActions": {
    "groovyArray": {
      "content": [
        {
          "inline": "script here",
          "scriptFileName": "relative path to GROOVY_ROOT",
          // mutually exclusive with inline
          "arguments": {
            "arg1": "val1",
            "arg2": "val2"
          }
        }
      ]
    }
  }
  ...
}

Persistence Helper

Allows to get data from persistent key/value storage. Currently only in-memory db.

Example:
{
  // Use 'key' property to define key to get from storage
  "simple": "{{persist  key='storedKey'}}"
}

If you need "get with default" functionality you may use this piece of code:

Example:
{
  {{eq (persist key='my_key') null yes='my_default_value' no=(persist key='my_key')}}
}

Persistence Post Serve Action

Example:
{
  ...
  "postServeActions": {
    "persist": {
      "action": "action, one of {set, unset, clearAll}",
      "key": "key",
      "value": "value",
      "filename": "relative path to __files", // mutually exclusive with value
      "fixedDelayMilliseconds": 12345
    }
  },
  ...
}
or multiple:
{
  ...
  "postServeActions": {
    "persistArray": {
      "content": [
        {
          "action": "action, one of {set, unset, clearAll}",
          "key": "key",
          "value": "value",
          "filename": "relative path to __files",
          // mutually exclusive with value
          "fixedDelayMilliseconds": 12345
        }
      ]
    }
  },
  ...
}

Persistence Admin Api

If com.tsystems.tm.acc.wiremock.persist.endpoint.PersistenceAdminApi is part of the extensions section of this Dockerfile, then one can use a REST client tool like Postman to read out and manipulate the data that was stored with the Persistence (Array) Post Serve Action. One can GET, PUT, POST or DELETE entries in a wiremock-acc instance.

URL-Pattern: https://wiremock-acc-app-[ENVIRONMENT-NAME].[HOSTNAME]/__admin/persistence
GET /persistence: gets all the key-value pairs stored
GET /persistence/{name}: gets a specific value for a key
POST /persistence: adds a new key-value pair
PUT /persistence: modifies an existing key-value pair
DELETE /persistence: deletes all stored entries
DELETE /persistence/{name}: deletes a specific entry for a key
Json-Body-Example for a key-value (POST/PUT):
{
	"name": "WO.state.1234",
    "value": "IN_PROGRESS"
}

Webhook Extension

Allows to do callbacks.

Example:
{
  "request" : {
    "method" : "GET",
    "url" : "/async"
  },
  "response" : {
    "body" : "12377869",
    "headers" : {
      "Content-Type" : "application/json"
    },
    "status" : 200
  },
  "postServeActions": {
    "webhook": {
      "url": "{{request.headers.X-Callback-Url}}",
      "body": "IT WORKS",
      "method": "POST",
      "headers" : {
        "Content-Type" : "application/json"
      }
    }
  }
}
Example of for cycle:
[
  {{#each (jsonPath request.body '$.klsIds')}}
  {
    "klsId": {{this}}
  }{{#unless @last}},{{/unless}}
  {{/each}}
]
Example of for Environment variable:
"system": "{{unsafeSystemValue key='TEST_VALUE'}}"
Example oauth helper:
{
  "request": {
    "method": "POST",
    "url": "/test/auth"
  },
  "response": {
    "body": "Ok",
    "headers": {
      "Content-Type": "text/plain"
    },
    "status": 200
  },
  "postServeActions": {
    "webhook": {
      "url": "http://localhost:8080/api/genericCallbackConsumer/v1.0/consume/",
      "headers": {
        "Authorization": "Bearer {{oauth}}",
        "Content-Type": "application/json"
      },
      "method": "POST",
      "body": "OK"
    }
  }
}

Project structure

Stubs are in the folder "stubs"

  • stubs
    • __files - storage for body contents
      • partner - storage for partner systems body contents. Shared between all teams
      • domain1 - storage for body contents for a specific domain env and team env in that domain
        • service1 - storage for body contents of this service, eg. if this service is not deployed what it should respond.
        • service2 - ...
      • domain2 - ...
    • mappings - storage for json definitions of stubs
      • partner - storage for partner systems stubs. Shared between all teams
      • domain1 - storage for stubs for a specific domain env and team env in that domain
        • service1 - storage for stubs of this service, eg. if this service is not deployed what it should respond.
        • service2 - ...
      • domain2 - ...

Ideology

As it is a central storage, it will contain all stubs for all envs and deployed to all envs. It contains only "generic" stubs. That means that stubs in this repository shall not be test case specific. They represent MVP of stubs to enable the environment to be operational.

How to add new stubs:

  • First check if there is already stub created for your endpoint
  • If not create it, use as much templating as possible
  • Use positive cases, negative ones are test case specific
  • Is stub already exists, check if you can reuse it.
  • If not either contact whoever created it to resolve conflict, or add a similar one

Example: Simple webhook receiver

Wiremock can be used as a simple webhook/callback receiver.

Locally

More

You can read more about creating stubs here: https://gard.telekom.de/gardwiki/display/DGHB/Wiremock+Stubs+Handling

wiremock-acc's People

Contributors

cstaege avatar alinamayyy avatar karstenkoehler avatar michalratajczykmagic avatar thspecht avatar ascschubi avatar alina-zakharenko avatar tilmanginzel avatar sebastianstaszalek avatar bdvorako avatar ghahlaoe avatar jokaio avatar sergeinikolaichuk avatar dtbela avatar ompluscator avatar stefanmasz avatar ichcodealsobinich avatar vferenze avatar agnemat avatar cekonieczny avatar metje avatar oksanaromtsyst avatar ilyadanil avatar pmstb avatar mikhailosev avatar jadhub avatar jaroslawwiktorowski avatar artomasz avatar jakubocap avatar oleg-fiksel-acn avatar

Watchers

Irina Khamzova 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.