Skip to content

Commit

Permalink
[rewrite] #1281 focused commit to show changes to [karate-demo] for a…
Browse files Browse the repository at this point in the history
…pi testing
  • Loading branch information
ptrthomas committed Nov 9, 2020
1 parent 08b4b0c commit 9808bd8
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions karate-demo/src/test/java/demo/binary/binary.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Background:

Scenario: json with byte-array
Given path 'echo', 'binary'
And def encoded = Base64.encoder.encodeToString('hello'.bytes);
And def encoded = Base64.encoder.encodeToString('hello'.getBytes())
And request { message: 'hello', data: '#(encoded)' }
When method post
Then status 200
And def expected = Base64.encoder.encodeToString('world'.bytes);
And def expected = Base64.encoder.encodeToString('world'.getBytes())
And match response == { message: 'world', data: '#(expected)' }
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Given path 'cats'
And request { name: '<name>' }
When method post
Then status 200
And kittens.add(response)
And kittens.push(response)

Examples:
| name |
Expand Down
5 changes: 3 additions & 2 deletions karate-demo/src/test/java/demo/calltable/call-table.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Then status 200
And match response == { id: '#number', name: 'Billie', kittens: '#(^^created)' }

# get kittens for billie using the id from the previous response
Given path 'cats', $.id, 'kittens'
Given path 'cats', response.id, 'kittens'
When method get
Then status 200

# some demo match examples
* match each response == { id: '#number', name: '#string' }
* match response == "#[6] { id: '#number', name: '#string' }"
* def schema = { id: '#number', name: '#string' }
* match response == "#[6] schema"

# pure data-driven assertion, compare with the original data
* match response[*].name contains only $kittens[*].name
Expand Down
4 changes: 2 additions & 2 deletions karate-demo/src/test/java/demo/encoding/encoding.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Scenario: french json ISO-8859-1
And header Content-Type = 'application/json; charset=ISO-8859-1'
When method post
Then status 200
And match response == { givenName: 'oliàèôç' }
And match response == { givenName: '#string' }
* def contentType = karate.prevRequest.headers['Content-Type'][0]
* match contentType contains 'application/json'
* match contentType contains 'charset=ISO-8859-1'
Expand Down Expand Up @@ -91,4 +91,4 @@ Scenario: multipart but forcing the charset to NOT be sent
And configure charset = null
When method post
Then status 200
And match response == { id: '#uuid', filename: 'karate-logo.jpg', message: 'oli???? M?ller', contentType: 'image/jpg' }
And match response == { id: '#uuid', filename: 'karate-logo.jpg', message: 'oliàèôç Müller', contentType: 'image/jpg' }
3 changes: 1 addition & 2 deletions karate-demo/src/test/java/demo/params/params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Scenario: comma delimited param value (normal)

@mock-servlet-todo
Scenario: comma delimited param value (in url)
Given url demoBaseUrl + '?fieldList=name,id,date_created,date_modified,created_id,modified_id'
And path 'echo'
Given url demoBaseUrl + '/echo?fieldList=name,id,date_created,date_modified,created_id,modified_id'
When method get
Then status 200
And match response.fieldList[0] == 'name,id,date_created,date_modified,created_id,modified_id'
Expand Down
2 changes: 1 addition & 1 deletion karate-demo/src/test/java/demo/request/request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Scenario: create cat
* def contentType = temp.headers['Content-Type'][0]
* match contentType contains 'application/json'
* match contentType contains 'charset=UTF-8'
* def requestUri = temp.uri
* def requestUri = temp.url
* match requestUri == demoBaseUrl + '/cats?foo=bar'
# this will be of java type byte[]
* def requestBody = temp.body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Scenario: params json with embedded expressions
Scenario: test that multi-params work as expected

Given path 'search'
And param foo = 'bar', 'baz'
And param foo = ['bar', 'baz']
When method get
Then status 200
And match response == { foo: ['bar', 'baz'] }
Expand Down
2 changes: 1 addition & 1 deletion karate-demo/src/test/java/demo/soap/soap.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Scenario: soap 1.1
"""
When soap action 'http://tempuri.org/Add'
Then status 200
And match /Envelope/Body/AddResponse/AddResult == 5
And match /Envelope/Body/AddResponse/AddResult == '5'
And print 'response: ', response

Scenario: soap 1.2
Expand Down
2 changes: 1 addition & 1 deletion karate-demo/src/test/java/demo/unit/cat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: demo calling java methods with complex types
* def billie = toCat({ id: 1, name: 'Billie' })
* def fun = function(n, i){ return { id: i + 2, name: n } }
* def kittens = karate.map(names, fun)
* billie.kittens = kittens
* billie.kittens = karate.toJava(kittens)
* match toJson(billie) contains expected
* match toJson(billie).kittens == expected.kittens

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Background:

Scenario: upload multiple fields
Given path 'files', 'fields'
And multipart fields { message: 'hello world', json: { foo: 'bar' } }
And multipart fields { message: 'hello world', json: { value: { foo: 'bar' } } }
When method post
Then status 200
And match response == { message: 'hello world', json: { foo: 'bar' } }
12 changes: 6 additions & 6 deletions karate-demo/src/test/java/demo/upload/upload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ Background:
Scenario: upload file
Given path 'files'
# refer to the second scenario in this file for how to set the upload filename using the 'multipart file' syntax
And multipart field myFile = read('test.pdf')
And multipart file myFile = { read: 'test.pdf' }
And multipart field message = 'hello world'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'myFile', message: 'hello world', contentType: 'application/octet-stream' }
And match response == { id: '#uuid', filename: 'test.pdf', message: 'hello world', contentType: 'application/pdf' }
And def id = response.id

Given path 'files', id
When method get
Then status 200
And match response == read('test.pdf')
And match header Content-Disposition contains 'attachment'
And match header Content-Disposition contains 'myFile'
And match header Content-Type == 'application/octet-stream'
And match header Content-Disposition contains 'test.pdf'
And match header Content-Type == 'application/pdf'

# example of calling custom java code from karate
* def FileChecker = Java.type('com.intuit.karate.demo.util.FileChecker')
# example of parsing a string into json by karate
* json fileInfo = FileChecker.getMetadata(id)
* match fileInfo == { id: '#(id)', filename: 'myFile', message: 'hello world', contentType: 'application/octet-stream' }
* match fileInfo == { id: '#(id)', filename: 'test.pdf', message: 'hello world', contentType: 'application/pdf' }

@mock-servlet-todo
Scenario: upload with filename and content-type specified
Expand Down Expand Up @@ -65,7 +65,7 @@ Scenario: upload with content created dynamically

Scenario: upload multipart/mixed
Given path 'files', 'mixed'
And multipart field myJson = { text: 'hello world' }
And multipart field myJson = { value: { text: 'hello world' } }
And multipart file myFile = { read: 'test.pdf', filename: 'upload-name.pdf', contentType: 'application/pdf' }
And header Content-Type = 'multipart/mixed'
When method post
Expand Down
2 changes: 1 addition & 1 deletion karate-demo/src/test/java/demo/websocket/websocket.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Scenario: only listening to websocket messages
And def id = response.id

# this line will wait until the handler returns true
* def result = socket.listen(5000)
* json result = socket.listen(5000)
* match result == { id: '#(id)', content: 'hello Rudy !' }

Scenario: using the websocket instance to send as well as receive messages
Expand Down

0 comments on commit 9808bd8

Please sign in to comment.