Last active
February 5, 2018 15:49
-
-
Save ptrthomas/35ef9d40623cbeade7388b2cbb29a3b1 to your computer and use it in GitHub Desktop.
Karate mock server port of https://automationrhapsody.com/build-a-rest-stub-server-with-dropwizard/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: person mock server | |
Background: | |
* def persons = | |
""" | |
{ | |
'1': { id: 1, firstName: 'FN1', lastName: 'LN1', email: '[email protected]' }, | |
'2': { id: 2, firstName: 'FN2', lastName: 'LN2', email: '[email protected]' }, | |
'3': { id: 3, firstName: 'FN3', lastName: 'LN3', email: '[email protected]' }, | |
'4': { id: 4, firstName: 'FN4', lastName: 'LN4', email: '[email protected]' } | |
} | |
""" | |
Scenario: pathMatches('/person/get/{id}') | |
* def response = persons[pathParams.id] | |
Scenario: pathMatches('/person/remove') | |
* def list = $persons.* | |
* eval if (list.length) karate.remove('persons', '$.' + list[0].id) | |
Scenario: pathMatches('/person/all') | |
* def response = $persons.* | |
Scenario: methodIs('post') | |
* def person = request | |
* def id = person.id || ~~(persons.length + 1) | |
* set person.id = id | |
* eval persons[id + ''] = person | |
* def response = person |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
person-mock.feature
java -jar karate-netty-0.7.0.RC7-all.jar -m person-mock.feature -p 9000
You can try the following URL-s:
http://localhost:9000/person/get/2
http://localhost:9000/person/all
http://localhost:9000/person/remove (and re-try the above)