Skip to content

Instantly share code, notes, and snippets.

@ptrthomas
Last active February 5, 2018 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptrthomas/35ef9d40623cbeade7388b2cbb29a3b1 to your computer and use it in GitHub Desktop.
Save ptrthomas/35ef9d40623cbeade7388b2cbb29a3b1 to your computer and use it in GitHub Desktop.
Feature: person mock server
Background:
* def persons =
"""
{
'1': { id: 1, firstName: 'FN1', lastName: 'LN1', email: 'email1@email.com' },
'2': { id: 2, firstName: 'FN2', lastName: 'LN2', email: 'email2@email.com' },
'3': { id: 3, firstName: 'FN3', lastName: 'LN3', email: 'email3@email.com' },
'4': { id: 4, firstName: 'FN4', lastName: 'LN4', email: 'email4@email.com' }
}
"""
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
@ptrthomas
Copy link
Author

ptrthomas commented Feb 5, 2018

Instructions:

  1. save the above gist as person-mock.feature
  2. download the Karate binary (only requires a JRE 8 to run) : https://dl.bintray.com/ptrthomas/karate/ (take the latest version available)
  3. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment