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