From fa20a9ccb316465f9ae5f92bac51b0ee725406a7 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Thu, 11 Dec 2014 13:38:36 +0530 Subject: [PATCH] Test cases for Office API. --- .../integrationtests/OfficeIntegrationsTest | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest index 85216d61e..bb004202c 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest @@ -62,5 +62,130 @@ public class OfficeIntegrationsTest { } return new Long(officeId); + + @Test + public void testCreateOfficeWithEmptyName() + { + int random_array = {2000, 4, 8}; + OfficeHelper oh = new OfficeHelper + .create(null) + .externalId(Utils.randomNameGenerator("",5)) + .nameDecorated(Utils.randomNameGenerator("offices-", 6)) + .openingDate(random_array) + .hierarchy(".") + .build(); + String JsonData = oh.toJSON(); + final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNull(officeID); + } + + @Test + public void testCreateOfficeWithEmptyExternalId() + { + int random_array = {2005, 1, 1}; + OfficeHelper oh = new OfficeHelper + .create(Utils.randomNameGenerator("", 3)) + .externalId(null) + .nameDecorated(Utils.randomNameGenerator("offices-",5)) + .openingDate(random_array) + .hierarchy(".") + .build(); + String JsonData = oh.toJSON(); + final Long OfficeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNotNull(OfficeID); + } + + @Test + public void testCreateOfficeWithDuplicateName() + { + int random_array1 = {1998, 12, 10}; + OfficeHelper oh1 = new OfficeHelper + .create(Utils.randomNameGenerator("", 7)) + .externalId(Utils.randomNameGenerator("Offices-", 4)) + .nameDecorated(Utils.randomNameGenerator("",10)) + .openingDate(random_array1) + .hierarchy(".") + .build(); + String JsonData = oh1.toJSON(); + final Long OfficeID1 = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNotNull(OfficeID); + + int random_array2 = {2002, 10, 10}; + OfficeHelper oh2 = new OfficeHelper + .create(Utils.randomNameGenerator("", 7)) + .externalId(Utils.randomNameGenerator(oh.getName())) + .nameDecorated(Utils.randomNameGenerator("",11)) + .openingDate(random_array2) + .hierarchy(".") + .build(); + + String JsonData = oh2.toJSON(); + ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build(); // 400 if the test works + final Long OfficeID2 = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNull(OfficeID2); + } + + @Test + public void testCreateOfficeWithDuplicateExternalId() + { + int random_array1 = {2003, 2, 2}; + OfficeHelper oh1 = new OfficeHelper + .create(Utils.randomNameGenerator("", 8)) + .externalId(oh1.getExternalId()) + .nameDecorated(Utils.randomNameGenerator("",10)) + .openingDate(random_array1) + .hierarchy(".") + .build(); + + String JsonData = oh1.toJSON(); + final Long OfficeID1 = createOfficeID(JsonData1, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNotNull(OfficeID); + + int random_array2 = {2005, 5, 5}; + OfficeHelper oh2 = new OfficeHelper + .create(Utils.randomNameGenerator("", 9)) + .externalId(Utils.randomNameGenerator("Offices-", 5)) + .nameDecorated(Utils.randomNameGenerator("",11)) + .openingDate(random_array2) + .hierarchy(".") + .build(); + + String JsonData = oh2.toJSON(); + ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(402).build(); // 402 if the test works + final Long OfficeID2 = createOfficeID(JsonData2, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNull(OfficeID2); + + + } + + @Test + public void testCreateOfficeWithEmptyOpeningDate() + { + OfficeHelper oh = new OfficeHelper + .create(Utils.randomNameGenerator("",9)) + .externalId(Utils.randomNameGenerator("Offices-",4)) + .nameDecorated(Utils.randomNameGenerator("",3)) + .openingDate(null) + .hierarchy(".") + .build(); + + String JsonData = oh.toJSON(); + final Long OfficeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNotNull(OfficeID); + } + + @Test + public void testNameUnknowForNow() + { + OfficeHelper oh = new OfficeHelper + .create() + .externalId() + .nameDecorated() + .openingDate() + .hierarchy(".") + .build(); + + } + } }