https://github.com/wenhao/mushrooms
Mushrooms is an easy setup mock or stub framework. To ensure high levels of efficiency for remote service integration.
https://github.com/wenhao/mushrooms
cache failover mock mock-server moco mushrooms stub
Last synced: 4 months ago
JSON representation
Mushrooms is an easy setup mock or stub framework. To ensure high levels of efficiency for remote service integration.
- Host: GitHub
- URL: https://github.com/wenhao/mushrooms
- Owner: wenhao
- License: apache-2.0
- Created: 2018-07-19T05:44:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-29T06:41:46.000Z (about 7 years ago)
- Last Synced: 2024-04-13T08:55:39.182Z (about 2 years ago)
- Topics: cache, failover, mock, mock-server, moco, mushrooms, stub
- Language: Java
- Homepage:
- Size: 388 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/wenhao/mushrooms)
[](https://coveralls.io/github/wenhao/mushrooms?branch=master)
[](https://www.apache.org/licenses/LICENSE-2.0.txt)
![Mushrooms][logo]
# 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
```groovy
repositories {
jcenter()
}
dependencies {
compile 'com.github.wenhao:mushrooms:3.0.8'
}
```
### Maven
```xml
com.github.wenhao
mushrooms
3.0.8
```
### 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](https://github.com/json-path/JsonPath)
#### Integrate with Spring boot
1. add application.yml configuration, eg.[MushroomsStubConfiguration.java](./src/test/java/com/github/wenhao/mushrooms/integration/config/MushroomsStubConfiguration.java).
2. initialize StubOkHttpClientInterceptor via spring bean config, eg.[BeanConfiguration.java](./src/test/java/com/github/wenhao/mushrooms/integration/config/BeanConfiguration.java).
3. override the OkHttpFeignConfiguration if you're using FeignClient, eg.[OkHttpFeignConfiguration](./src/test/java/com/github/wenhao/mushrooms/integration/config/OkHttpFeignConfiguration.java).
**Full setup**
```yaml
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**
```yaml
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**
```yaml
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](./src/test/java/com/github/wenhao/mushrooms/integration/config/RestTemplateConfiguration.java).
```java
@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.
```yaml
feign:
okhttp:
enabled: true
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: full
```
Logging
```yaml
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]
[logo]: ./docs/images/logo.png
[Apache License]: ./LICENSE