Skip to content

Commit

Permalink
Give more time to events tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-peirse committed Sep 27, 2020
1 parent deb16b6 commit c652e69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/main/java/com/checkout/ApacheHttpClientTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ public CompletableFuture<Response> invoke(String httpMethod, String path, ApiCre
.map(Header::getValue).orElse("NO_REQUEST_ID_SUPPLIED");

if (statusCode != 404) {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("\n");
if (response.getEntity() != null && response.getEntity().getContent() != null) {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
String jsonBody = stringBuilder.toString();
return new Response(statusCode, jsonBody, requestId);
}
String jsonBody = stringBuilder.toString();
return new Response(statusCode, jsonBody, requestId);
} else {
return new Response(statusCode, null, requestId);
}
} else {
return new Response(statusCode, null, requestId);
Expand Down
16 changes: 11 additions & 5 deletions src/test/java/com/checkout/events/EventsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.checkout.webhooks.WebhookRequest;
import com.checkout.webhooks.WebhookResponse;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.time.Instant;
Expand All @@ -14,6 +15,11 @@

public class EventsTests extends ApiTestFixture {

@Before
public void before() throws Exception {
Thread.sleep(5000);
}

@Test
public void retrieve_all_event_types() throws Exception {
List<EventTypesResponse> allEventTypesResponses = getApi().eventsClient().retrieveAllEventTypes(null).get();
Expand Down Expand Up @@ -101,7 +107,7 @@ public void retrieve_event_notification() throws Exception {
final String paymentId = payment.getPayment().getId();

// Sometimes the events aren't available immediately
Thread.sleep(5000);
Thread.sleep(10000);
final String eventId = getApi().eventsClient().retrieveEvents(null, null, null, null, paymentId).get().getData().get(0).getId();
EventResponse event = getApi().eventsClient().retrieveEvent(eventId).get();
Assert.assertNotNull(event.getNotifications());
Expand Down Expand Up @@ -138,7 +144,7 @@ public void test_retry_specific_webhook() throws Exception {
final String paymentId = payment.getPayment().getId();

// Sometimes the events aren't available immediately
Thread.sleep(5000);
Thread.sleep(10000);
final String eventId = getApi().eventsClient().retrieveEvents(null, null, null, null, paymentId).get().getData().get(0).getId();
EventResponse originalEvent = getApi().eventsClient().retrieveEvent(eventId).get();
long initialAttempts = originalEvent.getNotifications().stream()
Expand All @@ -147,7 +153,7 @@ public void test_retry_specific_webhook() throws Exception {

getApi().eventsClient().retryWebhook(eventId, webhook.getId()).get();

Thread.sleep(5000);
Thread.sleep(10000);
EventResponse retriedEvent = getApi().eventsClient().retrieveEvent(eventId).get();
long retriedAttempts = retriedEvent.getNotifications().stream()
.filter(it -> webhookUrl.equals(it.getUrl()))
Expand All @@ -170,7 +176,7 @@ public void test_retry_all_webhooks() throws Exception {
final String paymentId = payment.getPayment().getId();

// Sometimes the events aren't available immediately
Thread.sleep(5000);
Thread.sleep(10000);
final String eventId = getApi().eventsClient().retrieveEvents(null, null, null, null, paymentId).get().getData().get(0).getId();
EventResponse originalEvent = getApi().eventsClient().retrieveEvent(eventId).get();
long initialAttempts = originalEvent.getNotifications().stream()
Expand All @@ -179,7 +185,7 @@ public void test_retry_all_webhooks() throws Exception {

getApi().eventsClient().retryAllWebhooks(eventId).get();

Thread.sleep(5000);
Thread.sleep(10000);
EventResponse retriedEvent = getApi().eventsClient().retrieveEvent(eventId).get();
long retriedAttempts = retriedEvent.getNotifications().stream()
.filter(it -> webhookUrl.equals(it.getUrl()))
Expand Down

0 comments on commit c652e69

Please sign in to comment.