|
26 | 26 | import org.springframework.http.client.ClientHttpRequestFactory; |
27 | 27 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
28 | 28 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
| 29 | +import org.springframework.util.LinkedMultiValueMap; |
| 30 | +import org.springframework.util.MultiValueMap; |
29 | 31 | import org.springframework.web.client.HttpClientErrorException; |
30 | 32 | import org.springframework.web.client.RequestCallback; |
31 | 33 | import org.springframework.web.client.RestTemplate; |
@@ -213,7 +215,23 @@ public void givenFooService_whenCallDelete_thenEntityIsRemoved() { |
213 | 215 | } |
214 | 216 | } |
215 | 217 |
|
216 | | - // |
| 218 | + @Test |
| 219 | + public void givenFooService_whenFormSubmit_thenResourceIsCreated() { |
| 220 | + HttpHeaders headers = new HttpHeaders(); |
| 221 | + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| 222 | + |
| 223 | + MultiValueMap<String, String> map= new LinkedMultiValueMap<>(); |
| 224 | + map.add("id", "1"); |
| 225 | + |
| 226 | + HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers); |
| 227 | + |
| 228 | + ResponseEntity<String> response = restTemplate.postForEntity( fooResourceUrl+"/form", request , String.class); |
| 229 | + |
| 230 | + assertThat(response.getStatusCode(), is(HttpStatus.CREATED)); |
| 231 | + final String fooResponse = response.getBody(); |
| 232 | + assertThat(fooResponse, notNullValue()); |
| 233 | + assertThat(fooResponse, is("1")); |
| 234 | + } |
217 | 235 |
|
218 | 236 | private HttpHeaders prepareBasicAuthHeaders() { |
219 | 237 | final HttpHeaders headers = new HttpHeaders(); |
|
0 commit comments