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 07cf09c50..139fce056 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/FundsIntegrationTest.java @@ -41,32 +41,107 @@ public class FundsIntegrationTest { } @Test - public void testCreateFaultyFund() { + public void testCreateFund() { FundsHelper fh = FundsHelper - .create(Utils.randomNameGenerator("", 120)) - .externalId(Utils.randomNameGenerator("fund-", 120)) + .create(Utils.randomNameGenerator("", 10)) + .externalId(Utils.randomNameGenerator("fund-", 5)) .build(); String jsonData = fh.toJSON(); - final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec.statusCode(400)); + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + Assert.assertNotNull(fundID); + } + + @Test + public void testCreateFundWithEmptyName() { + FundsHelper fh = FundsHelper + .create(null) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); + String jsonData = fh.toJSON(); + + final Long fundID = createFund(jsonData, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(400).build()); Assert.assertNull(fundID); } @Test - public void testDuplicates() { + public void testCreateFundWithEmptyExternalId() { FundsHelper fh = FundsHelper - .create(Utils.randomNameGenerator("", 10)) - .externalId(Utils.randomNameGenerator("fund-", 5)) - .build(); + .create(Utils.randomNameGenerator("", 10)) + .externalId(null) + .build(); + String jsonData = fh.toJSON(); + + final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); + Assert.assertNotNull(fundID); + } + + @Test + public void testCreateFundWithDuplicateName() { + 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)); + FundsHelper fh2 = FundsHelper + .create(fh.getName()) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); + jsonData = fh2.toJSON(); + + final Long fundID2 = createFund(jsonData, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(403).build()); Assert.assertNull(fundID2); } + @Test + public void testCreateFundWithDuplicateExternalId() { + 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); + + FundsHelper fh2 = FundsHelper + .create(Utils.randomNameGenerator("", 10)) + .externalId(fh.getExternalId()) + .build(); + jsonData = fh2.toJSON(); + + final Long fundID2 = createFund(jsonData, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(403).build()); + Assert.assertNull(fundID2); + } + + @Test + public void testCreateFundWithInvalidName() { + FundsHelper fh = FundsHelper + .create(Utils.randomNameGenerator("", 120)) + .externalId(Utils.randomNameGenerator("fund-", 5)) + .build(); + String jsonData = fh.toJSON(); + + final Long fundID = createFund(jsonData, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(400).build()); + Assert.assertNull(fundID); + } + + @Test + public void testCreateFundWithInvalidExternalId() { + FundsHelper fh = FundsHelper + .create(Utils.randomNameGenerator("", 10)) + .externalId(Utils.randomNameGenerator("fund-", 120)) + .build(); + String jsonData = fh.toJSON(); + + final Long fundID = createFund(jsonData, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(400).build()); + Assert.assertNull(fundID); + } + @Test public void testRetrieveFund() { FundsHelper fh = FundsHelper @@ -103,7 +178,7 @@ public class FundsIntegrationTest { } @Test - public void testFundUnknown() { + public void testRetrieveUnknownFund() { 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"); @@ -132,10 +207,98 @@ public class FundsIntegrationTest { 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.statusCode(404)); + FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, new ResponseSpecBuilder().expectStatusCode(404).build()); Assert.assertNull(fh); } + @Test + public void testUpdateFundWithInvalidNewName() { + 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); + + String newName = Utils.randomNameGenerator("", 120); + String newExternalId = Utils.randomNameGenerator("fund-", 5); + FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, + new ResponseSpecBuilder().expectStatusCode(400).build()); + + Assert.assertNull(fh2); + } + + @Test + public void testUpdateFundWithEmptyNewName() { + 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); + + String newExternalId = Utils.randomNameGenerator("fund-", 5); + FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, newExternalId, this.requestSpec, this.responseSpec); + + Assert.assertNotNull(fh2); + } + + @Test + public void testUpdateFundWithInvalidNewExternalId() { + 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); + + String newName = Utils.randomNameGenerator("", 10); + String newExternalId = Utils.randomNameGenerator("fund-", 120); + FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, + new ResponseSpecBuilder().expectStatusCode(400).build()); + + Assert.assertNull(fh2); + } + + @Test + public void testUpdateFundWithEmptyNewExternalId() { + 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); + + String newName = Utils.randomNameGenerator("", 10); + FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, null, this.requestSpec, this.responseSpec); + + Assert.assertNotNull(fh2); + } + + @Test + public void testUpdateFundWithEmptyParams() { + 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); + + FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, null, this.requestSpec, this.responseSpec); + + Assert.assertNotNull(fh2); + } + private Long createFund(final String fundJSON, final RequestSpecification requestSpec, final ResponseSpecification 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 2f8c79614..cc05dd869 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 @@ -70,7 +70,10 @@ public class FundsHelper { @Override public int hashCode() { - return this.name.hashCode(); + if (this.name != null) { + return this.name.hashCode(); + } + return super.hashCode(); } @Override