GithubHelp home page GithubHelp logo

rjmock's Introduction

RJMOCK

Summary

It is a tool for creating mock responses. It allows to quick setup of different responses (using url and parameters) for REST services.

Prerequisites

  • JDK 8
  • Maven 3

How to build and run

mvn clean package

It will create build project and prepare zip file in target directory. It can be unzipped in any location. To run project use

java - jar <jar file name>

in unzipped directory

Test mock can be retrieved by calling address:8090/rjmock/test

Structure

config - there is config file for application RJMockData - all mocks files

Configuration

Configuration is in application.properties file

server.port - application port - default: 8090
data.dir - directory with RJMockData - default is in project directory

Mock description

Packages

To call mocks server link should look like that: http://<address>:8090/rjmock/<package_name>/<subpath><query_parameters>

<package_name> tells which <package_name>.json file in descriptors directory should be used.

/<subpath><query_parameters> allows to select response which has been defined in package file

Example of package file:

{
  "responses": [
    {
      "response": "test/test.json",
      "subpath": "test",
      "code": 200,
      "type": "json",
      "conditions":[
        {
          "param": "test",
          "value": "value"
        }
      ]
    },
    {
      "response": "s",
      "subpath":"_any_",
      "code": 404,
      "type": "text"
    }
  ]
}

Each response has:

  • response - string of response or path to file with response
  • subpath - what subpath in link suggest this response. _any_ is special reponse type used when no other subpath is valid (conditions still can be checked)
  • code - what is http return code
  • type - what is response type (example: json or text)
  • conditions - what are requested parameters and their values

Conditions are array and each has

  • param - that is parameter name
  • value - required value

Link that will call first response http://localhost:8090/rjmock/test/test?test=value

Packages and responses are read when called so can be changed without restarting application

Responses

If request has response kept in file then this file should be put in RJMockData/responses directory directory structure inside is not important. The only requirement is that path inside responses has to be given in package description

Package fragment

"responses": [
    {
      "response": "test/test.json",
(...)

Structure

RJMockData
|
|---responses
    |
    |---test
        |
        |---test.json

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.