|
20 | 20 | import io.qameta.allure.attachment.AttachmentProcessor; |
21 | 21 | import io.qameta.allure.attachment.AttachmentRenderer; |
22 | 22 | import org.apache.http.client.methods.CloseableHttpResponse; |
| 23 | +import org.apache.http.client.methods.HttpDelete; |
23 | 24 | import org.apache.http.client.methods.HttpGet; |
24 | 25 | import org.apache.http.impl.client.CloseableHttpClient; |
25 | 26 | import org.apache.http.impl.client.HttpClientBuilder; |
|
33 | 34 |
|
34 | 35 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
35 | 36 | import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; |
| 37 | +import static com.github.tomakehurst.wiremock.client.WireMock.delete; |
36 | 38 | import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 39 | +import static com.github.tomakehurst.wiremock.client.WireMock.noContent; |
37 | 40 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
38 | 41 | import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
39 | 42 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; |
@@ -65,6 +68,9 @@ void setUp() { |
65 | 68 | stubFor(get(urlEqualTo("/empty")) |
66 | 69 | .willReturn(aResponse() |
67 | 70 | .withStatus(304))); |
| 71 | + |
| 72 | + stubFor(delete(urlEqualTo("/hello")) |
| 73 | + .willReturn(noContent())); |
68 | 74 | } |
69 | 75 |
|
70 | 76 | @AfterEach |
@@ -155,4 +161,31 @@ void shouldCreateResponseAttachmentWithEmptyBody() throws Exception { |
155 | 161 | .extracting("body") |
156 | 162 | .containsExactly("No body present"); |
157 | 163 | } |
| 164 | + |
| 165 | + @SuppressWarnings("unchecked") |
| 166 | + @Test |
| 167 | + void shouldCreateRequestAttachmentWithEmptyBodyWhenNoContentIsReturned() throws Exception { |
| 168 | + final AttachmentRenderer<AttachmentData> renderer = mock(AttachmentRenderer.class); |
| 169 | + final AttachmentProcessor<AttachmentData> processor = mock(AttachmentProcessor.class); |
| 170 | + |
| 171 | + final HttpClientBuilder builder = HttpClientBuilder.create() |
| 172 | + .addInterceptorLast(new AllureHttpClientRequest(renderer, processor)); |
| 173 | + |
| 174 | + try (CloseableHttpClient httpClient = builder.build()) { |
| 175 | + final HttpDelete httpDelete = new HttpDelete(String.format("http://localhost:%d/hello", server.port())); |
| 176 | + try (CloseableHttpResponse response = httpClient.execute(httpDelete)) { |
| 177 | + assertThat(response.getEntity()) |
| 178 | + .isEqualTo(null); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + final ArgumentCaptor<AttachmentData> captor = ArgumentCaptor.forClass(AttachmentData.class); |
| 183 | + verify(processor, times(1)) |
| 184 | + .addAttachment(captor.capture(), eq(renderer)); |
| 185 | + |
| 186 | + assertThat(captor.getAllValues()) |
| 187 | + .hasSize(1) |
| 188 | + .extracting("body") |
| 189 | + .containsNull(); |
| 190 | + } |
158 | 191 | } |
0 commit comments