@@ -71,6 +71,33 @@ public void multipartRequestPartsAreAvailableViaTemplating() {
71
71
+ "file:binary=true:application/octet-stream:QUJDRA==" ));
72
72
}
73
73
74
+ @ Test
75
+ public void multipartRequestPartsHeadersAreCaseInsensitive () {
76
+ wm .stubFor (
77
+ post ("/templated" )
78
+ .willReturn (
79
+ ok (
80
+ "multipart:{{request.multipart}}\n "
81
+ + "text:content-type={{request.parts.text.headers.CoNtEnT-TyPe}}\n "
82
+ + "file:content-type={{request.parts.file.headers.cOnTeNt-tYpE}}" )));
83
+
84
+ WireMockResponse response =
85
+ client .post (
86
+ "/templated" ,
87
+ MultipartEntityBuilder .create ()
88
+ .addTextBody ("text" , "hello" , ContentType .TEXT_PLAIN )
89
+ .addBinaryBody (
90
+ "file" , "ABCD" .getBytes (), ContentType .APPLICATION_OCTET_STREAM , "abcd.bin" )
91
+ .build ());
92
+
93
+ assertThat (
94
+ response .content (),
95
+ is (
96
+ "multipart:true\n "
97
+ + "text:content-type=text/plain; charset=ISO-8859-1\n "
98
+ + "file:content-type=application/octet-stream" ));
99
+ }
100
+
74
101
@ Test
75
102
public void returnsEmptyPartsInTemplateWhenRequestIsNotMultipart () {
76
103
wm .stubFor (
@@ -85,8 +112,46 @@ public void returnsEmptyPartsInTemplateWhenRequestIsNotMultipart() {
85
112
assertThat (response .content (), is ("multipart:false\n " + "text::" ));
86
113
}
87
114
88
- // TODO list parts and/or get the count
115
+ @ Test
116
+ public void ableToReturnTheNumberOfParts () {
117
+ wm .stubFor (
118
+ post ("/templated" )
119
+ .willReturn (
120
+ ok ("multipart:{{request.multipart}}\n " + "part count = {{size request.parts}}" )));
121
+ WireMockResponse response =
122
+ client .post (
123
+ "/templated" ,
124
+ MultipartEntityBuilder .create ()
125
+ .addTextBody ("text" , "hello" , ContentType .TEXT_PLAIN )
126
+ .addBinaryBody (
127
+ "file" , "ABCD" .getBytes (), ContentType .APPLICATION_OCTET_STREAM , "abcd.bin" )
128
+ .build ());
89
129
90
- // TODO case-insensitive map for headers or normalisation of key case?
130
+ assertThat (response .content (), is ("multipart:true\n " + "part count = 2" ));
131
+ }
91
132
133
+ @ Test
134
+ public void ableToIterateOverParts () {
135
+ wm .stubFor (
136
+ post ("/templated" )
137
+ .willReturn (
138
+ ok (
139
+ "multipart:{{request.multipart}}\n "
140
+ + "{{#each request.parts as |part|}}{{part.name}}:{{part.headers.content-type}}:{{part.body}}/\n {{/each}}" )));
141
+ WireMockResponse response =
142
+ client .post (
143
+ "/templated" ,
144
+ MultipartEntityBuilder .create ()
145
+ .addTextBody ("text" , "hello" , ContentType .TEXT_PLAIN )
146
+ .addBinaryBody (
147
+ "file" , "ABCD" .getBytes (), ContentType .APPLICATION_OCTET_STREAM , "abcd.bin" )
148
+ .build ());
149
+
150
+ assertThat (
151
+ response .content (),
152
+ is (
153
+ "multipart:true\n "
154
+ + "file:application/octet-stream:ABCD/\n "
155
+ + "text:text/plain; charset=ISO-8859-1:hello/\n " ));
156
+ }
92
157
}
0 commit comments