Skip to content

Fixed skipped tests #21

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

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
794cf12
Commit Inicial
luismoroc Jul 5, 2017
9ba9ebb
Merge pull request #1 from luismoro/master
luismoro Jul 5, 2017
b547c8a
Update readme
andreformentoc Jul 5, 2017
16621f4
Deixar acceptedheaders opcionais
andreformentoc Jul 5, 2017
c3fe82a
Merge pull request #2 from concretesolutions/deixar-acceptedheaders-o…
andreformentoc Jul 5, 2017
3d381c9
Update README.md
andreformentoc Jul 5, 2017
a78aae4
Update README.md
andreformentoc Jul 5, 2017
437ce29
Altera para gradle
andreformentoc Jul 10, 2017
3a36b96
Update readme
andreformentoc Jul 10, 2017
9cd75e9
Merge pull request #3 from andreformento/master
andreformentoc Jul 10, 2017
22724b4
Ignora pasta out
andreformentoc Jul 10, 2017
c4eed6c
Permite usar comando do gradle para run e atualiza readme
andreformentoc Jul 10, 2017
792aa9c
Atualiza versão do Spring Boot
andreformentoc Jul 10, 2017
67aaec4
Merge pull request #4 from andreformento/master
andreformentoc Jul 10, 2017
a9d7642
Arrumando RestTemplate
klebertiko Jul 13, 2017
2b2566d
Arrumando dependencias
klebertiko Jul 13, 2017
1f123b7
Merge pull request #5 from klebertiko/master
cs-olavo-castro Jul 14, 2017
c034192
Corrige erro de compilação
andreformento Jul 15, 2017
44aaeba
Corrige quebra de testes integrados
andreformento Jul 15, 2017
05dbcdf
Merge pull request #6 from andreformento/master
andreformentoc Jul 15, 2017
a4a7d0c
Add travis
andreformento Jul 15, 2017
e39a907
Merge pull request #7 from andreformento/master
andreformentoc Jul 15, 2017
41439ed
Fix request/response body (de)serialization to JsonElement
resilva87 Aug 10, 2017
1cb2931
Merge pull request #8 from resilva87/bug/fix-object-serialization
andreformentoc Aug 10, 2017
0e1b17d
Corrige testes unitários e integrados
resilva87 Aug 11, 2017
39a5c4c
Adcionando configs tanto para travis-ci quanto codecov
Aug 11, 2017
d01c4c3
Fixing unit tests
Aug 11, 2017
b89ce09
Adding badges to README
Aug 11, 2017
5db4e3d
Merge pull request #9 from resilva87/chore/fix-tests
andreformentoc Aug 15, 2017
7aed031
Merge pull request #10 from cs-joao-felipe/master
andreformentoc Aug 15, 2017
96035d2
Corrige testes quebrados
andreformento Aug 15, 2017
004ef93
Merge pull request #11 from andreformento/master
andreformentoc Aug 15, 2017
073b6ae
Otimiza propriedades não utilizadas
andreformento Aug 15, 2017
0f3fb17
Merge remote-tracking branch 'upstream/master'
andreformento Aug 15, 2017
5fd8792
Merge pull request #12 from andreformento/master
andreformentoc Aug 15, 2017
5ccb99f
adiciona .DS_Store no git ignore
brunoalvesrocha Aug 15, 2017
3102292
Merge pull request #13 from brunoalvesrocha/master
andreformentoc Aug 15, 2017
b8696a9
Adding Codacy badge
Aug 15, 2017
91350f7
Merge pull request #1 from concretesolutions/master
Aug 15, 2017
1dac758
Codacy appointed fixes
Aug 15, 2017
a7e656a
Merge pull request #15 from cs-joao-felipe/master
Aug 15, 2017
de3af98
updating codify badge
Aug 15, 2017
d5f864b
Using CommandLineRunner interface springBoot instead @PostConstruct
brunoalvesrocha Aug 16, 2017
4ada9e9
fixing_codacy_suggestion
brunoalvesrocha Aug 16, 2017
9b1b7ae
fixing_codacy_suggestion
brunoalvesrocha Aug 16, 2017
5b7ffee
Altera maneira como o projeto realiza requisicoes com o verbo http GET
Aug 16, 2017
f66617b
Fixing FindBugs-IDEA appointed errors.
Aug 17, 2017
65c6fb4
fixing error with filename
Aug 17, 2017
74bd0a5
Reverting File creation changes
Aug 17, 2017
8146c08
fixing some Codacy issues
Aug 17, 2017
c09b877
reverting
Aug 17, 2017
c165cd7
Implement shutdown controller
andreformento Aug 22, 2017
cc4ff9a
Merge pull request #20 from andreformento/master
andreformentoc Aug 22, 2017
3617208
Merge pull request #16 from brunoalvesrocha/master
andreformentoc Aug 22, 2017
e7c0349
Merge pull request #19 from cs-joao-felipe/master
andreformentoc Aug 22, 2017
ad766f2
Adding Coverage history
Aug 22, 2017
9e5e9bb
Create docker image for the app
resilva87 Sep 28, 2017
7b6ee32
Adiciona maintainer do docker
resilva87 Sep 28, 2017
fe742db
Merge pull request #21 from resilva87/feature/docker-image
andreformentoc Sep 28, 2017
d2dc513
Merge pull request #17 from antoniobsn/absn-change-get-request
luismoro Oct 2, 2017
f1a4595
Update README.md
luismoro Oct 2, 2017
405d4cc
Change to elementa-source
andreformento Oct 22, 2017
81372b0
Update codacy Badge
andreformento Oct 22, 2017
fe1cf3e
Add contributing guide
resilva87 Oct 27, 2017
1afdd98
Merge pull request #3 from elemental-source/adiciona-guia-contribuicao
resilva87 Oct 27, 2017
dedce79
Add findbugs plugin
resilva87 Oct 27, 2017
769401c
Add findbugs configuration and fix build
resilva87 Oct 27, 2017
36da314
Remove from TODO
resilva87 Oct 27, 2017
c296746
Merge pull request #5 from elemental-source/feature/add-findbugs-plugin
resilva87 Oct 27, 2017
c0b7c95
Show todo as checklist
resilva87 Oct 27, 2017
b2dcb4c
Merge pull request #11 from elemental-source/chore/todo-list
resilva87 Oct 27, 2017
b1afbca
Add checkstyle plugin and configuration based on Google style
resilva87 Oct 27, 2017
d33d97e
Mark todo as done
resilva87 Oct 27, 2017
60da778
Merge pull request #12 from elemental-source/chore/checkstyle
resilva87 Oct 27, 2017
473d214
Altera o package name para condizer com a finalidade do projeto
Oct 27, 2017
5e4aeb5
Altera o package name para condizer com a finalidade do projeto
Oct 27, 2017
6e024e3
Merge pull request #16 from elemental-source/feature/lm-acerta-nome-p…
luismoro Oct 27, 2017
4f3aa5c
Translated README.md to English
V-V-K Oct 27, 2017
b55293b
Merge pull request #17 from V-V-K/patch-1
resilva87 Oct 29, 2017
26594ff
Improve description and how to use
resilva87 Oct 29, 2017
1677798
Merge pull request #20 from elemental-source/improve-description
resilva87 Oct 29, 2017
58a9b2a
Fixed skipped tests
aleien Oct 31, 2017
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
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`
```
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
[![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:

```
gradle bootRun -Dspring.profiles.active=custom
```

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

```
gradle 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:

```
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`

## 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')``
88 changes: 88 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'docker'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'

findbugs {
sourceSets = [sourceSets.main]
ignoreFailures = true
effort = "default"
reportLevel = "high"
}

checkstyle {
toolVersion = '8.3'
sourceSets= [sourceSets.main]
ignoreFailures = true
}

version = '4.0.0-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile 'org.springframework.boot:spring-boot-starter-undertow'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-hateoas'
compile 'com.google.code.gson:gson'
compile 'javax.ws.rs:javax.ws.rs-api:2.0'
compile 'net.minidev:json-smart:1.0.8'
compile 'com.google.guava:guava:22.0'
compile 'org.modelmapper:modelmapper:0.7.5'
compile 'commons-io:commons-io:2.5'
compile 'org.apache.httpcomponents:httpclient:4.4.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'br.com.six2six:fixture-factory:3.1.0'
}

bootRun {
String activeProfile = System.properties['spring.profiles.active']
systemProperty "spring.profiles.active", activeProfile
}

task codeCoverageReport(type: JacocoReport) {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

sourceSets sourceSets.main
reports {
xml.enabled true
xml.destination "${buildDir}/reports/jacoco/report.xml"
html.enabled false
csv.enabled false
}
}


task buildDocker(type: Docker, dependsOn: build) {
push = false
applicationName = 'elemental-source/' + jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}

Loading