From aaf7025d795e119298616548cc8b9234ea5f5727 Mon Sep 17 00:00:00 2001 From: Mohammed Nafees Date: Wed, 3 Dec 2014 14:47:47 +0530 Subject: [PATCH] Add test for duplicate creation --- .../FundsIntegrationTest.java | 25 +++++++++++++++---- .../common/funds/FundsResourceHandler.java | 11 ++------ 2 files changed, 22 insertions(+), 14 deletions(-) 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 6bec406c6..07cf09c50 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java @@ -37,7 +37,7 @@ public class FundsIntegrationTest { Utils.initializeRESTAssured(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); - this.responseSpec = new ResponseSpecBuilder().build(); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); } @Test @@ -48,10 +48,25 @@ public class FundsIntegrationTest { .build(); String jsonData = fh.toJSON(); - final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec.statusCode(400)); Assert.assertNull(fundID); } + @Test + public void testDuplicates() { + FundsHelper fh = FundsHelper + .create(Utils.randomNameGenerator("", 10)) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); + String jsonData = fh.toJSON(); + + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + Assert.assertNotNull(fundID); + + final Long fundID2 = createFund(jsonData, this.requestSpec, this.responseSpec.statusCode(403)); + Assert.assertNull(fundID2); + } + @Test public void testRetrieveFund() { FundsHelper fh = FundsHelper @@ -89,7 +104,7 @@ public class FundsIntegrationTest { @Test public void testFundUnknown() { - String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, this.responseSpec); + String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, this.responseSpec.statusCode(404)); HashMap map = new Gson().fromJson(jsonData, HashMap.class); assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found"); } @@ -110,14 +125,14 @@ public class FundsIntegrationTest { FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.responseSpec); Assert.assertEquals(newName, fh2.getName()); - Assert.assertNull(fh2.getExternalId()); + Assert.assertEquals(newExternalId, fh2.getExternalId()); } @Test public void testUpdateUnknownFund() { String newName = Utils.randomNameGenerator("", 10); String newExternalId = Utils.randomNameGenerator("fund-", 5); - FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec); + FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec.statusCode(404)); Assert.assertNull(fh); } 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 9c8f5dd99..e27e1377c 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 @@ -46,15 +46,8 @@ public class FundsResourceHandler { final String newExternalId, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - final HashMap map = new HashMap<>(); - if (!newName.isEmpty()) { - map.put("name", newName); - } else if (!newExternalId.isEmpty()) { - // to test that the externalId cannot be updated - map.put("externalId", newExternalId); - } - - String updateJSON = new Gson().toJson(map); + FundsHelper fh = FundsHelper.create(newName).externalId(newExternalId).build(); + String updateJSON = new Gson().toJson(fh); final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER; final HashMap response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes");