Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concrete #22

Open
wants to merge 89 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
01a9acc
Commit Inicial
luismoroc Jul 5, 2017
57d52db
Merge pull request #1 from luismoro/master
luismoro Jul 5, 2017
790c510
Update readme
andreformentoc Jul 5, 2017
480b9d3
Deixar acceptedheaders opcionais
andreformentoc Jul 5, 2017
31dfdf9
Merge pull request #2 from concretesolutions/deixar-acceptedheaders-o…
andreformentoc Jul 5, 2017
6eaf759
Update README.md
andreformentoc Jul 5, 2017
3c03e06
Altera para gradle
andreformentoc Jul 10, 2017
27fc7e8
Update readme
andreformentoc Jul 10, 2017
28d9c22
Merge pull request #3 from andreformento/master
andreformentoc Jul 10, 2017
d34b70e
Ignora pasta out
andreformentoc Jul 10, 2017
fa5b278
Permite usar comando do gradle para run e atualiza readme
andreformentoc Jul 10, 2017
2a7d863
Atualiza versão do Spring Boot
andreformentoc Jul 10, 2017
898535b
Merge pull request #4 from andreformento/master
andreformentoc Jul 10, 2017
b0b6e19
Arrumando RestTemplate
klebertiko Jul 13, 2017
c78d8f0
Arrumando dependencias
klebertiko Jul 13, 2017
b6a510c
Merge pull request #5 from klebertiko/master
cs-olavo-castro Jul 14, 2017
a0ae752
Corrige erro de compilação
andreformento Jul 15, 2017
a5c4ab0
Corrige quebra de testes integrados
andreformento Jul 15, 2017
49da5e1
Merge pull request #6 from andreformento/master
andreformentoc Jul 15, 2017
178d636
Add travis
andreformento Jul 15, 2017
c1f3ba6
Merge pull request #7 from andreformento/master
andreformentoc Jul 15, 2017
4246de9
Fix request/response body (de)serialization to JsonElement
resilva87 Aug 10, 2017
bcb365c
Merge pull request #8 from resilva87/bug/fix-object-serialization
andreformentoc Aug 10, 2017
72ce461
Corrige testes unitários e integrados
resilva87 Aug 11, 2017
9ef93e3
Adcionando configs tanto para travis-ci quanto codecov
Aug 11, 2017
313e50b
Fixing unit tests
Aug 11, 2017
9102b98
Adding badges to README
Aug 11, 2017
6adc41a
Merge pull request #9 from resilva87/chore/fix-tests
andreformentoc Aug 15, 2017
4c454ac
Merge pull request #10 from cs-joao-felipe/master
andreformentoc Aug 15, 2017
dc756ee
Corrige testes quebrados
andreformento Aug 15, 2017
d71cbd2
Merge pull request #11 from andreformento/master
andreformentoc Aug 15, 2017
c3cba09
Otimiza propriedades não utilizadas
andreformento Aug 15, 2017
57c3dc2
Merge remote-tracking branch 'upstream/master'
andreformento Aug 15, 2017
99a338b
Merge pull request #12 from andreformento/master
andreformentoc Aug 15, 2017
5aa9bd5
adiciona .DS_Store no git ignore
brunoalvesrocha Aug 15, 2017
888bccc
Merge pull request #13 from brunoalvesrocha/master
andreformentoc Aug 15, 2017
ab1254d
Adding Codacy badge
Aug 15, 2017
6313b01
Merge pull request #1 from concretesolutions/master
Aug 15, 2017
08c52dd
Codacy appointed fixes
Aug 15, 2017
1198211
Merge pull request #15 from cs-joao-felipe/master
Aug 15, 2017
693d726
updating codify badge
Aug 15, 2017
f0c33f7
Using CommandLineRunner interface springBoot instead @PostConstruct
brunoalvesrocha Aug 16, 2017
37c4e23
fixing_codacy_suggestion
brunoalvesrocha Aug 16, 2017
8ca4459
fixing_codacy_suggestion
brunoalvesrocha Aug 16, 2017
bf97290
Altera maneira como o projeto realiza requisicoes com o verbo http GET
Aug 16, 2017
cc5f9e9
Fixing FindBugs-IDEA appointed errors.
Aug 17, 2017
bca86ee
fixing error with filename
Aug 17, 2017
ec5d627
Reverting File creation changes
Aug 17, 2017
173f8b3
fixing some Codacy issues
Aug 17, 2017
e39517b
reverting
Aug 17, 2017
3e95de1
Implement shutdown controller
andreformento Aug 22, 2017
aa52921
Merge pull request #20 from andreformento/master
andreformentoc Aug 22, 2017
f153f02
Merge pull request #16 from brunoalvesrocha/master
andreformentoc Aug 22, 2017
dd114f1
Merge pull request #19 from cs-joao-felipe/master
andreformentoc Aug 22, 2017
d283992
Adding Coverage history
Aug 22, 2017
32be134
Create docker image for the app
resilva87 Sep 28, 2017
4dbc191
Adiciona maintainer do docker
resilva87 Sep 28, 2017
3d2edb7
Merge pull request #21 from resilva87/feature/docker-image
andreformentoc Sep 28, 2017
4f93d86
Merge pull request #17 from antoniobsn/absn-change-get-request
luismoro Oct 2, 2017
c50e8ad
Update README.md
luismoro Oct 2, 2017
10a8336
Change to elementa-source
andreformento Oct 22, 2017
f481a7f
Update codacy Badge
andreformento Oct 22, 2017
befae22
Add contributing guide
resilva87 Oct 27, 2017
114336c
Merge pull request #3 from elemental-source/adiciona-guia-contribuicao
resilva87 Oct 27, 2017
bcddb3a
Add findbugs plugin
resilva87 Oct 27, 2017
1a9c082
Add findbugs configuration and fix build
resilva87 Oct 27, 2017
13dbfcb
Remove from TODO
resilva87 Oct 27, 2017
cae0ac4
Merge pull request #5 from elemental-source/feature/add-findbugs-plugin
resilva87 Oct 27, 2017
b466b5a
Show todo as checklist
resilva87 Oct 27, 2017
e19d03d
Merge pull request #11 from elemental-source/chore/todo-list
resilva87 Oct 27, 2017
2864c33
Add checkstyle plugin and configuration based on Google style
resilva87 Oct 27, 2017
2c4b897
Mark todo as done
resilva87 Oct 27, 2017
ec24810
Merge pull request #12 from elemental-source/chore/checkstyle
resilva87 Oct 27, 2017
e91c14a
Altera o package name para condizer com a finalidade do projeto
Oct 27, 2017
510e151
Altera o package name para condizer com a finalidade do projeto
Oct 27, 2017
8acb9c0
Merge pull request #16 from elemental-source/feature/lm-acerta-nome-p…
luismoro Oct 27, 2017
0193126
Translated README.md to English
V-V-K Oct 27, 2017
1597315
Merge pull request #17 from V-V-K/patch-1
resilva87 Oct 29, 2017
e9ffc18
Improve description and how to use
resilva87 Oct 29, 2017
58d3ee3
Merge pull request #20 from elemental-source/improve-description
resilva87 Oct 29, 2017
c9d3a83
teste
Jan 5, 2018
a037d1e
Adiciona application.yml
Jan 5, 2018
49878ba
Update gradle version (#22)
andreformento Jul 14, 2018
aba7748
Update readme (#23)
andreformento Jul 15, 2018
6009719
Easy startup (#24)
andreformento Jul 15, 2018
9a3d78e
Permite variáveis no json a partir de parametros do request (#26)
mariofts Jul 17, 2018
f07c4b2
Usa o rest template do spring (#25)
andreformento Jul 17, 2018
4240ad6
Fix docker-compose
andreformento Jul 18, 2018
3078551
Permite variáveis nos nomes das pastas (#27)
mariofts Aug 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .docker-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Dockerfile
docker-compose.yml
out
.gradle
.idea
build
out
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
48 changes: 31 additions & 17 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
# Compiled class file
*.class
target/
.mvn/

# Log file
*.log
application-*.yml

# BlueJ files
*.ctxt
### STS ###
.classpath
.factorypath
.project
.settings
.springBeans

# Mobile Tools for Java (J2ME)
.mtj.tmp/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
*.DS_Store

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.gradle/

### Application ###
backup-temp/
mocks-prod
fake-api-data
out
bin
.vscode
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: java
jdk:
- oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
script:
- gradle check
#- gradle codeCoverageReport
#after_success:
#- bash <(curl -s https://codecov.io/bash) -t

notifications:
email: false
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing
:clap::tada: Thank you for taking the time to contribute! :tada::clap:

We really value your willingness to contribute to this project. In order to higher the chances of your contribution being accepted, please refer to the following guidelines!

## Steps

1. Fork it!
2. Create your feature branch: `git checkout -b feature/xyz develop`
3. Commit your changes according to our commit message standards: `git commit -am 'feat(xyz) Added new functionality'`
4. Push to your repo: `git push origin feature/xyz`
5. Submit a pull request to `develop`

## Workflow
This repo uses Gitflow as its branch management system. You can learn more about Gitflow [here](https://www.atlassian.com/git/tutorials/comparing-workflows#gitflow-workflow).
A few quick tips:
* All feature branches should be based on `develop` and have the format `feature/branch_name`.
* Minor bug fixes should be based on `master` and have the format `hotfix/branch_name`.

### Commit Conventions
In order to make the changelog generation easier we recommend the use of messages based on [Conventional Commits](https://conventionalcommits.org/).

Examples:
```
feat(orders): added `XYZ` helper function

commit description

footer notes
```

```
refactor(orders): refactored `ABC` helper function

The behaviour of `ABC` was inconsistent and (...)

BREAKING CHANGE: return type of `ABC` is now `String`
```
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM openjdk:8-jdk as build

ENV BUILD_PATH /building
WORKDIR $BUILD_PATH

COPY gradlew $BUILD_PATH/
COPY gradle $BUILD_PATH/gradle
# download gradle
RUN ./gradlew --continue

COPY build.gradle $BUILD_PATH

# download dependencies
RUN ./gradlew build; exit 0

COPY src $BUILD_PATH/src
COPY mocks-test $BUILD_PATH/mocks-test
RUN mkdir $BUILD_PATH/backup-temp

RUN ./gradlew build

#############
# Final image
FROM openjdk:8-jdk
MAINTAINER "elemental-source"

VOLUME /config
VOLUME /mocks-test
VOLUME /backup-temp

WORKDIR /

EXPOSE 5000
EXPOSE 9090

ENV APP_PARAMS "--spring.config.location=file:/config/application.yml"

COPY --from=build /building/build/libs/*.jar app.jar
ENTRYPOINT ["java", \
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5000 -Djava.security.egd=file:/dev/./urandom", \
"-jar", \
"/app.jar", \
"$APP_PARAMS"]
146 changes: 146 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
[![Build Status](https://travis-ci.org/elemental-source/mock-api.svg?branch=master)](https://travis-ci.org/elemental-source/mock-api)
[![codecov.io](https://codecov.io/github/elemental-source/mock-api/coverage.svg?branch=master)](https://codecov.io/github/elemental-source/mock-api?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2be4911c74b14b68a37e78ca4c2c8273)](https://www.codacy.com/app/elemental-source/mock-api?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=elemental-source/mock-api&amp;utm_campaign=Badge_Grade)

## Coverage History
![codecov.io](https://codecov.io/github/elemental-source/mock-api/branch.svg?branch=master)

# Mock API

Allows for reusable http request/response cycles in your tests, similar to WireMock.

## Features

* Capture live responses from external hosts and save the stubs locally
* Define your mocked responses using JSON
* Folder-based data files
* Per-request conditional proxying
* Simple YAML configuration

## Rules

All your requests should be directed to the application. When an HTTP request is made, the following matching rules are applied:

1. Is there a valid mock data file (i.e. request/response pattern) existing in `api.fileBase` folder that matches the request pattern? If so, the mocked response is returned.
2. If not, does the request uri match any pattern described by the `api.uriConfigurations[].pattern` list? If so, the request will be dispatched to the matching `api.uriConfigurations[].host`.
3. If none of above is true, the request is dispatched to the default host `api.host`.

Should (2) or (3) occur, the response from an external host will be cached according to the `captureState` and `api.file.backup.path` properties. Next time the same request is made, it will be returned directly from the saved data file.

## Example of a matched request

Let's say you want to return the following mocked response for the following request:

```
GET http://www.example.com/payments/111/description?code=ABCD
```

Expected response:

```
HTTP 200 (OK)
{
"payment": {
"from": "John",
"to": "Fred",
"value": 33
}
}
```

You should create the following mock data file (its name has no meaning, it can be anything you like):

```
{
// Request field describes what the request should look like in order to return the matched response.
// In this case, query parameter "code" should be equal to "ABCD".
// The request pattern is described by its method, headers, query parameters and body.
request": {
"query": {
"code": "ABCD"
}
},
// Response field describes the mocked response in case the request matches.
// You can define the response body and status code.
"response": {
"body": {
"payment": {
"from": "John",
"to": "Fred",
"value": 33
}
},
"httpStatus": 200
}
}
```

Now, in order to properly use the data file, we should consider where it should be located. `mock-api` will parse the request and use the uri to search for the data file in the `api.fileBase` folder. In our example the request uri is `/payments/111/description?code=ABCD`, this means that the data file should be located in `${api.fileBase}/payments/111/description` folder (i.e. file location is based in uri parts and path parameters, other request fields are described in the data file itself).

## Requirements

* Java JDK 8
* Gradle 4

## Run

### Using Your Property File
Create a valid property file in `src/main/resources/application-custom.yml` then run with `-Dspring.profiles.active=custom` argument. Example:

```shell
./gradlew bootRun -Dspring.profiles.active=custom
```

### Using Docker Image
To generate the Docker image, run:

```shell
./gradlew buildDocker
```

By default, the image name will be `elemental-source/mock-api:VERSION`.

In order to run the application, create two folders: one containing the `application-custom.yml` configuration file and the other containing the mock data files. Then run:

```shell
docker run -d --name mock-api \
-p 9090:9090 \
-p 5000:5000 \
-v /path/to/application-custom.yml:/config/application.yml \
-v /path/to/mock/data/files:/data \
elemental-source/mock-api:VERSION
```

Port `9090` exposes the service while port `5000` can be used to debug the application.

You can check application logs from the container: `docker logs -f mock-api`

You can configure your program arguments in your IDE:
```
--spring.config.location=file/name/example/application.yml
```

#### Using docker-compose

Run `docker-compose up --build`

Get results: `curl -X GET 'http://localhost:9090/guests/132'`

Look `api.host` property at `src/main/resources/application.yml` file.
The value is http://www.mocky.io, the host that will be called if there is no file that dont match with request.
If you create a new mock, you can call directly. Concat `localhost:9090` with the generated link, like this:

```shell
curl -X GET 'http://localhost:9090/v2/5b4bbb0c3100003503a7de45'
```

The response will not found at mock files and then, the external host will be called.

## TODO

- [X] Fix code Style
- [ ] Create an example of a property file
- [ ] Split unit from integrated tests
- [ ] Fix skipping tests
- [ ] Review dependencies (check, for instance, if it's even necessary to have both GSON and modelmapper dependencies)
- [ ] Use objectmapper as component: `compile ('com.fasterxml.jackson.datatype: jackson-datatype-jdk8')``
Loading