From 21c4cdf0029d52a97f26956c4da7ef97c317f483 Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Sat, 18 Oct 2014 16:19:45 -0700 Subject: [PATCH] possible fix for hooks related integration test failure --- .../integrationtests/HookIntegrationTest.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/HookIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/HookIntegrationTest.java index 23ce8c167..6f8a2c0c0 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/HookIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/HookIntegrationTest.java @@ -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); } - + } }