|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2015 the original author or authors. |
| 2 | + * Copyright 2014-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -75,6 +75,18 @@ public void getRequestWithQueryString() throws IOException {
|
75 | 75 | .request("http://localhost/foo?bar=baz").build());
|
76 | 76 | }
|
77 | 77 |
|
| 78 | + @Test |
| 79 | + public void getRequestWithQueryStringWithNoValue() throws IOException { |
| 80 | + this.snippet.expectHttpRequest("get-request-with-query-string-with-no-value") |
| 81 | + .withContents(httpRequest(RequestMethod.GET, "/foo?bar") |
| 82 | + .header(HttpHeaders.HOST, "localhost")); |
| 83 | + |
| 84 | + new HttpRequestSnippet().document( |
| 85 | + new OperationBuilder("get-request-with-query-string-with-no-value", |
| 86 | + this.snippet.getOutputDirectory()) |
| 87 | + .request("http://localhost/foo?bar").build()); |
| 88 | + } |
| 89 | + |
78 | 90 | @Test
|
79 | 91 | public void postRequestWithContent() throws IOException {
|
80 | 92 | String content = "Hello, world";
|
@@ -123,6 +135,20 @@ public void postRequestWithParameter() throws IOException {
|
123 | 135 | .build());
|
124 | 136 | }
|
125 | 137 |
|
| 138 | + @Test |
| 139 | + public void postRequestWithParameterWithNoValue() throws IOException { |
| 140 | + this.snippet.expectHttpRequest("post-request-with-parameter") |
| 141 | + .withContents(httpRequest(RequestMethod.POST, "/foo") |
| 142 | + .header(HttpHeaders.HOST, "localhost") |
| 143 | + .header("Content-Type", "application/x-www-form-urlencoded") |
| 144 | + .content("bar=")); |
| 145 | + |
| 146 | + new HttpRequestSnippet() |
| 147 | + .document(new OperationBuilder("post-request-with-parameter", |
| 148 | + this.snippet.getOutputDirectory()).request("http://localhost/foo") |
| 149 | + .method("POST").param("bar").build()); |
| 150 | + } |
| 151 | + |
126 | 152 | @Test
|
127 | 153 | public void putRequestWithContent() throws IOException {
|
128 | 154 | String content = "Hello, world";
|
@@ -201,6 +227,30 @@ public void multipartPostWithParameters() throws IOException {
|
201 | 227 | .part("image", "<< data >>".getBytes()).build());
|
202 | 228 | }
|
203 | 229 |
|
| 230 | + @Test |
| 231 | + public void multipartPostWithParameterWithNoValue() throws IOException { |
| 232 | + String paramPart = createPart( |
| 233 | + String.format("Content-Disposition: form-data; " + "name=a%n"), false); |
| 234 | + String filePart = createPart(String |
| 235 | + .format("Content-Disposition: form-data; " + "name=image%n%n<< data >>")); |
| 236 | + String expectedContent = paramPart + filePart; |
| 237 | + this.snippet |
| 238 | + .expectHttpRequest( |
| 239 | + "multipart-post-with-parameter-with-no-value") |
| 240 | + .withContents(httpRequest(RequestMethod.POST, "/upload") |
| 241 | + .header("Content-Type", |
| 242 | + "multipart/form-data; boundary=" + BOUNDARY) |
| 243 | + .header(HttpHeaders.HOST, "localhost").content(expectedContent)); |
| 244 | + new HttpRequestSnippet().document( |
| 245 | + new OperationBuilder("multipart-post-with-parameter-with-no-value", |
| 246 | + this.snippet.getOutputDirectory()) |
| 247 | + .request("http://localhost/upload").method("POST") |
| 248 | + .header(HttpHeaders.CONTENT_TYPE, |
| 249 | + MediaType.MULTIPART_FORM_DATA_VALUE) |
| 250 | + .param("a").part("image", "<< data >>".getBytes()) |
| 251 | + .build()); |
| 252 | + } |
| 253 | + |
204 | 254 | @Test
|
205 | 255 | public void multipartPostWithContentType() throws IOException {
|
206 | 256 | String expectedContent = createPart(
|
|
0 commit comments