Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ public void process(final HttpResponse response,
Stream.of(response.getAllHeaders())
.forEach(header -> builder.setHeader(header.getName(), header.getValue()));

final LoggableEntity loggableEntity = new LoggableEntity(response.getEntity());
response.setEntity(loggableEntity);
if (response.getEntity() != null) {
final LoggableEntity loggableEntity = new LoggableEntity(response.getEntity());
response.setEntity(loggableEntity);

builder.setBody(loggableEntity.getBody());
builder.setBody(loggableEntity.getBody());
} else {
builder.setBody("No body present");
}

final HttpResponseAttachment responseAttachment = builder.build();
processor.addAttachment(responseAttachment, renderer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ void setUp() {
stubFor(get(urlEqualTo("/hello"))
.willReturn(aResponse()
.withBody(BODY_STRING)));

stubFor(get(urlEqualTo("/empty"))
.willReturn(aResponse()
.withStatus(304)));
}

@AfterEach
Expand Down Expand Up @@ -110,4 +114,30 @@ void shouldCreateResponseAttachment() throws Exception {
.extracting("responseCode")
.containsExactly(200);
}

@Test
void shouldCreateResponseAttachmentWithEmptyBody() throws Exception {
final AttachmentRenderer<AttachmentData> renderer = mock(AttachmentRenderer.class);
final AttachmentProcessor<AttachmentData> processor = mock(AttachmentProcessor.class);

final HttpClientBuilder builder = HttpClientBuilder.create()
.addInterceptorLast(new AllureHttpClientResponse(renderer, processor));

try (CloseableHttpClient httpClient = builder.build()) {
final HttpGet httpGet = new HttpGet(String.format("http://localhost:%d/empty", server.port()));
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
assertThat(response.getEntity())
.isEqualTo(null);
}
}

final ArgumentCaptor<AttachmentData> captor = ArgumentCaptor.forClass(AttachmentData.class);
verify(processor, times(1))
.addAttachment(captor.capture(), eq(renderer));

assertThat(captor.getAllValues())
.hasSize(1)
.extracting("body")
.containsExactly("No body present");
}
}