mushrooms

Mushrooms is an easy setup failover and stub framework. To ensure high levels of efficiency for remote service integration.

License

License

GroupId

GroupId

com.github.wenhao
ArtifactId

ArtifactId

mushrooms
Last Version

Last Version

3.0.8
Release Date

Release Date

Type

Type

jar
Description

Description

mushrooms
Mushrooms is an easy setup failover and stub framework. To ensure high levels of efficiency for remote service integration.
Project URL

Project URL

https://github.com/wenhao/mushrooms
Source Code Management

Source Code Management

https://github.com/wenhao/mushrooms

Download mushrooms

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.wenhao/mushrooms/ -->
<dependency>
    <groupId>com.github.wenhao</groupId>
    <artifactId>mushrooms</artifactId>
    <version>3.0.8</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.wenhao/mushrooms/
implementation 'com.github.wenhao:mushrooms:3.0.8'
// https://jarcasting.com/artifacts/com.github.wenhao/mushrooms/
implementation ("com.github.wenhao:mushrooms:3.0.8")
'com.github.wenhao:mushrooms:jar:3.0.8'
<dependency org="com.github.wenhao" name="mushrooms" rev="3.0.8">
  <artifact name="mushrooms" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.wenhao', module='mushrooms', version='3.0.8')
)
libraryDependencies += "com.github.wenhao" % "mushrooms" % "3.0.8"
[com.github.wenhao/mushrooms "3.0.8"]

Dependencies

runtime (5)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.8.1
com.google.code.gson : gson jar 2.8.5
org.json : json jar 20180130
org.skyscreamer : jsonassert jar 1.5.0
com.jayway.jsonpath : json-path jar 2.4.0

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Apache 2.0 License

Mushrooms

Mushrooms

Mushrooms is an easy setup mock or stub framework. To ensure high levels of efficiency for remote service integration.

Why

Remote service integration, especially based on HTTP protocol, e.g. web service, REST etc, highly unstable when developing.

Features

Stub

Stub feature rely on spring boot and okhttp3, make sure FeignClient/RestTemplate are using okhttp3.

  • Stub REST API.
  • Stub Soap API.

Dependencies

  1. io.github.openfeign:feign-okhttp.

Gradle

repositories {
    jcenter()
}

dependencies {
    compile 'com.github.wenhao:mushrooms:3.0.8'
}

Maven

<dependency>
    <groupId>com.github.wenhao</groupId>
    <artifactId>mushrooms</artifactId>
    <version>3.0.8</version>
</dependency>

Build

./gradlew clean build

Get Started

Request Matchers

A request matcher can contain any of the following matchers:

  • method - string value as a plain text, regular expression.
  • path - string value as a plain text, regular expression.
  • query string - key to multiple values as a plain text, regular expression.
  • headers - key to multiple values as a plain text, regular expression.
  • body
    • XPath(example, body: xpath:/Envelope/Body/GetBookRequest[BookName='Java']), without NAMESPACE.
    • XML - full or partial match.
    • JSON - full or partial match.
    • JsonPath(example, body: jsonPath:$.store.book[?(@.price < 10)]), jsonPath syntax

Integrate with Spring boot

  1. add application.yml configuration, eg.MushroomsStubConfiguration.java.
  2. initialize StubOkHttpClientInterceptor via spring bean config, eg.BeanConfiguration.java.
  3. override the OkHttpFeignConfiguration if you're using FeignClient, eg.OkHttpFeignConfiguration.

Full setup

mushrooms:
  stub:
    enabled: true
    failover: true
    stubs:
      - request:
          path: ${REAL_HOST:http://localhost:8080}/stub(.*)
          parameters: 
            - key: [A-z]{0,10}
              value: [A-Z0-9]+
          method: P(.*)
          headers:
            - key: [A-z]{0,10}
              value: [A-Z0-9]+
          body: /stubs/stub_rest_request.json
        response: /stubs/stub_rest_response.json

Stub Configuration

Enabled mushrooms stub and set stub request and response.

Stub REST API

mushrooms:
  stub:
    enabled: true
    stubs:
      - request:
          path: ${REAL_HOST:http://localhost:8080}/stub
          method: POST
          body: /stubs/stub_rest_request.json
        response: /stubs/stub_rest_response.json

Stub Soap API

mushrooms:
  stub:
    enabled: true
    stubs:
      - request:
          path: ${REAL_HOST:http://localhost:8080}/stub/get_book
          method: POST
          body: /stubs/stub_soap_request.xml
        response: /stubs/stub_soap_response.xml

Enabled RestTemplate stub, Customize RestTemplate by using Okhttp3, RestTemplateConfiguration.

@Configuration
public class RestTemplateConfiguration {

  @Bean
  public RestTemplate restTemplate(ClientHttpRequestFactory clientHttpRequestFactory) {
    return new RestTemplate(clientHttpRequestFactory);
  }

  @Bean
  public ClientHttpRequestFactory okHttp3ClientHttpRequestFactory(OkHttpClient okHttpClient) {
    return new OkHttp3ClientHttpRequestFactory(okHttpClient);
  }
}

Generic Configuration

If enabled okhttp stub, enabling feign okhttp client.

feign:
  okhttp:
    enabled: true
  client:
    config:
      default:
        connectTimeout: 5000
        readTimeout: 5000
        loggerLevel: full

Logging

logging:
  level:
    com.github.wenhao.mushrooms: DEBUG

Failover

As Failover is true, will call real endpoint first and return real response if health.

Copyright and license

Copyright © 2018-2019 Wen Hao

Licensed under Apache License

Versions

Version
3.0.8
3.0.7
3.0.6
3.0.5
2.1.3