-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.feature
89 lines (78 loc) · 3.63 KB
/
upload.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Feature: file upload end-point
Background:
* url demoBaseUrl
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 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 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'
# 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' }
@mock-servlet-todo
Scenario: upload with filename and content-type specified
Given path 'files'
And multipart file myFile = { read: 'test.pdf', filename: 'upload-name.pdf', contentType: 'application/pdf' }
And multipart field message = 'hello world'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'upload-name.pdf', message: 'hello world', contentType: 'application/pdf' }
And def id = response.id
Given path 'files', id
When method get
Then status 200
And match responseBytes == read('test.pdf')
And match header Content-Disposition contains 'attachment'
And match header Content-Disposition contains 'upload-name.pdf'
And match header Content-Type == 'application/pdf'
Scenario: upload with content created dynamically
Given path 'files'
And def value = 'lorem ipsum'
And multipart file myFile = { value: '#(value)', filename: 'hello.txt', contentType: 'text/plain' }
And multipart field message = 'hello world'
When method post
Then status 200
And match response contains { id: '#uuid', filename: 'hello.txt', message: 'hello world' }
And def id = response.id
Given path 'files', id
When method get
Then status 200
And match response == 'lorem ipsum'
And match header Content-Disposition contains 'attachment'
And match header Content-Disposition contains 'hello.txt'
And match header Content-Type contains 'text/plain'
Scenario: upload multipart/mixed
Given path 'files', 'mixed'
And multipart field myJson = { 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
Then status 200
And match response == { id: '#uuid', filename: 'upload-name.pdf', message: 'hello world', contentType: 'application/pdf' }
@mock-servlet-todo
Scenario: multipart upload has content-length header set
Given path 'search', 'headers'
And multipart field myFile = read('test.pdf')
And multipart field message = 'hello world'
When method post
Then status 200
And match response['content-length'][0] == '#notnull'
Given path 'search', 'headers'
And multipart file myFile = { read: 'test.pdf', filename: 'upload-name.pdf', contentType: 'application/pdf' }
And multipart field message = 'hello world'
When method post
Then status 200
And match response['content-length'][0] == '#notnull'