possible fix for hooks related integration test failure

This commit is contained in:
Vishwas Babu A J
2014-10-18 16:19:45 -07:00
parent 733656685d
commit 21c4cdf002
@@ -8,6 +8,8 @@ package org.mifosplatform.integrationtests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.HttpHostConnectException;
import org.junit.Before;
import org.junit.Test;
@@ -24,13 +26,13 @@ import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
public class HookIntegrationTest {
private RequestSpecification requestSpec;
private RequestSpecification requestSpec;
private ResponseSpecification responseSpec;
private HookHelper hookHelper;
private OfficeHelper officeHelper;
@Before
public void setUp() throws Exception {
Utils.initializeRESTAssured();
@@ -40,27 +42,30 @@ public class HookIntegrationTest {
this.hookHelper = new HookHelper(this.requestSpec, this.responseSpec);
this.officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
}
@Test
public void shouldSendOfficeCreationNotification() {
//Subject to https://echo-webhook.herokuapp.com being up
//See http://www.jamesward.com/2014/06/11/testing-webhooks-was-a-pain-so-i-fixed-the-glitch
final String payloadURL = "http://echo-webhook.herokuapp.com:80/Z7RXoCBdLSFMDrpn?";
this.hookHelper.createHook(payloadURL);
final Integer createdOfficeID = this.officeHelper.createOffice("01 January 2012");
try {
final String json = RestAssured.get(payloadURL.replace("?", "")).asString();
final Integer notificationOfficeId = JsonPath.with(json).get("officeId");
assertEquals("Equality check for created officeId and hook received payload officeId",
createdOfficeID, notificationOfficeId);
System.out.println("Notification Office Id - " + notificationOfficeId);
} catch (final Exception e) {
// Subject to https://echo-webhook.herokuapp.com being up
// See
// http://www.jamesward.com/2014/06/11/testing-webhooks-was-a-pain-so-i-fixed-the-glitch
final String payloadURL = "http://echo-webhook.herokuapp.com:80/Z7RXoCBdLSFMDrpn?";
this.hookHelper.createHook(payloadURL);
final Integer createdOfficeID = this.officeHelper.createOffice("01 January 2012");
try {
// sleep for a three seconds to increase the likelihood of the
// previous request for creating office completing
TimeUnit.SECONDS.sleep(3);
final String json = RestAssured.get(payloadURL.replace("?", "")).asString();
final Integer notificationOfficeId = JsonPath.with(json).get("officeId");
assertEquals("Equality check for created officeId and hook received payload officeId", createdOfficeID, notificationOfficeId);
System.out.println("Notification Office Id - " + notificationOfficeId);
} catch (final Exception e) {
if (e instanceof HttpHostConnectException) {
fail("Failed to connect to https://echo-webhook.herokuapp.com platform");
}
throw new RuntimeException(e);
}
}
}