diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java index bc78b77a2..80a6e8887 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java @@ -5,8 +5,10 @@ */ package org.mifosplatform.integrationtests; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertEquals; +import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import org.junit.Assert; import org.junit.Before; @@ -21,9 +23,7 @@ import com.jayway.restassured.http.ContentType; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; -import java.math.BigInteger; -import java.util.HashMap; -import java.util.List; +import java.util.*; /** * Funds Integration Test for checking Funds Application. @@ -43,10 +43,13 @@ public class FundsIntegrationTest { @Test public void testRetrieveFund() { - FundsHelper fh = FundsHelper.create(Utils.randomNameGenerator("", 10)).build(); + FundsHelper fh = FundsHelper + .create(Utils.randomNameGenerator("", 10)) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); String jsonData = fh.toJSON(); - final Integer fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); Assert.assertNotNull(fundID); jsonData = FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.responseSpec); @@ -57,28 +60,36 @@ public class FundsIntegrationTest { @Test public void testRetrieveAllFunds() { - FundsHelper fh = FundsHelper.create(Utils.randomNameGenerator("", 10)).build(); + FundsHelper fh = FundsHelper + .create(Utils.randomNameGenerator("", 10)) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); String jsonData = fh.toJSON(); - final Integer fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); Assert.assertNotNull(fundID); - List list = FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.responseSpec); + List> list = FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.responseSpec); + Assert.assertNotNull(list); + Assert.assertThat(list.size(), greaterThanOrEqualTo(1)); + + jsonData = new Gson().toJson(list); + List fhList = new Gson().fromJson(jsonData, new TypeToken>(){}.getType()); + Assert.assertThat(fhList, hasItem(fh)); } @Test public void testFundUnknown() { - String jsonData = FundsResourceHandler.retrieveFund(Integer.MAX_VALUE, this.requestSpec, this.responseSpec); + String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, this.responseSpec); HashMap map = new Gson().fromJson(jsonData, HashMap.class); assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found"); } - private Integer createFund(final String fundJSON, - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec) { - System.out.println("------------------ CREATING NEW FUND ------------------"); - return FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec); + private Long createFund(final String fundJSON, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + return new Long(String.valueOf(FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec))); } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsHelper.java index f4fd4d968..2f8c79614 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsHelper.java @@ -12,34 +12,47 @@ public class FundsHelper { public static class Builder { private String name; + private String externalId; private Builder(final String name) { this.name = name; } + public Builder externalId(final String externalId) { + this.externalId = externalId; + return this; + } + public FundsHelper build() { - return new FundsHelper(this.name); + return new FundsHelper(this.name, this.externalId); } } private String name; - private Integer resourceId; + private String externalId; + private Long resourceId; - public FundsHelper() { + FundsHelper() { super(); } - private FundsHelper(final String name) { + private FundsHelper(final String name, + final String externalId) { super(); this.name = name; + this.externalId = externalId; } public String getName() { return this.name; } - public Integer getResourceID() { + public String getExternalId() { + return this.externalId; + } + + public Long getResourceId() { return this.resourceId; } @@ -55,4 +68,28 @@ public class FundsHelper { return new Builder(name); } + @Override + public int hashCode() { + return this.name.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (!(o instanceof FundsHelper)) { + return false; + } + + FundsHelper fh = (FundsHelper)o; + + if (this.name.equals(fh.name)) { + return true; + } + + return false; + } + } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsResourceHandler.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsResourceHandler.java index c12cd569a..70fdd4795 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsResourceHandler.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/funds/FundsResourceHandler.java @@ -24,13 +24,13 @@ public class FundsResourceHandler { return Utils.performServerPost(requestSpec, responseSpec, CREATE_FUNDS_URL, fundJSON, "resourceId"); } - public static List retrieveAllFunds(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec) { + public static List> retrieveAllFunds(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER; return Utils.performServerGet(requestSpec, responseSpec, URL, ""); } - public static String retrieveFund(final Integer fundID, + public static String retrieveFund(final Long fundID, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;