From f9a57a53ba19458522c84c49682786a8fee821a1 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Wed, 10 Dec 2014 18:43:40 +0530 Subject: [PATCH 1/5] Test case 1 for Office creation. --- .../integrationtests/OfficeIntegrationsTest | 31 ++++++++++++++++++- .../common/office/OfficeHelper | 6 +++- .../common/office/OfficeResourceHandler | 4 +-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest index 118e6d854..85216d61e 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest @@ -13,6 +13,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.office.OfficeHelper; +import org.mifosplatform.integrationtests.common.office.OfficeResourceHandler; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.ResponseSpecBuilder; @@ -33,5 +35,32 @@ public class OfficeIntegrationsTest { this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.statusOkResponseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); } -} + @Test + public void testCreateOffice() + { + int random_array = {1997, 26, 12}; + OfficeHelper oh = OfficeHelper // oh ---> Office Helper + .create(Utils.randomNameGenerator("", 5)) + .externalId(Utils.randomNameGenerator("offices-", 7)) + .nameDecorated(Utils.randomNameGenerator("", 8)) + .openingDate(random_array) + .hierarchy(".") + .build(); + String JsonData = oh.toJSON(); + final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); + Assert.assertNotNull(officeID); + + } + private Long createOffice(final String officeJSON, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + String officeId = String.valueOf(OfficeResourceHandler.createOffice(officeJSON, requestSpec, responseSpec)); + if (officeId.equals("null")) { + // Invalid JSON data parameters + return null; + } + + return new Long(officeId); +} +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper index 02368d7ea..6ca1074b1 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper @@ -36,7 +36,7 @@ public class OfficeHelper { this.hierarchy = hierarchy; } public OfficeHelper build() { - return new OfficeHelper(this.name, this.externalId, this.id, this.nameDecorated, this.openingDate, this.hierarchy); + return new OfficeHelper(this.name, this.externalId, this.nameDecorated, this.openingDate, this.hierarchy); } } @@ -96,6 +96,10 @@ public class OfficeHelper { return this.openingDate; } + public static Builder create(final String name) { + return new Builder(name); + } + } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler index bc79caf88..6fa6d354d 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler @@ -14,10 +14,10 @@ public class OfficeResourceHandler { private static final String OFFICES_URL = "/mifosng-provider/api/v1/offices"; private static final String CREATE_OFFICES_URL = OFFICES_URL + "?" + Utils.TENANT_IDENTIFIER; - public static Integer createFund(final String fundJSON, + public static Integer createOffice(final String officeJSON, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - return Utils.performServerPost(requestSpec, responseSpec, CREATE_FUNDS_URL, fundJSON, "resourceId"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_OFFICES_URL, officeJSON, "resourceId"); } public Integer createOffice(final String openingDate) { From fa20a9ccb316465f9ae5f92bac51b0ee725406a7 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Thu, 11 Dec 2014 13:38:36 +0530 Subject: [PATCH 2/5] 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(); + + } + } } From 632fac4d5bdf7b4ce82fb204169dc47bac9cc4b4 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Thu, 11 Dec 2014 13:49:29 +0530 Subject: [PATCH 3/5] Test Cases for Office API. (Reformatted Code) --- .../integrationtests/OfficeIntegrationsTest | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest index bb004202c..f59d92ff0 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest @@ -23,6 +23,7 @@ import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; import java.util.*; + public class OfficeIntegrationsTest { private ResponseSpecification statusOkResponseSpec; @@ -37,24 +38,24 @@ public class OfficeIntegrationsTest { } @Test - public void testCreateOffice() - { + public void testCreateOffice() { int random_array = {1997, 26, 12}; OfficeHelper oh = OfficeHelper // oh ---> Office Helper - .create(Utils.randomNameGenerator("", 5)) - .externalId(Utils.randomNameGenerator("offices-", 7)) - .nameDecorated(Utils.randomNameGenerator("", 8)) - .openingDate(random_array) - .hierarchy(".") - .build(); + .create(Utils.randomNameGenerator("", 5)) + .externalId(Utils.randomNameGenerator("offices-", 7)) + .nameDecorated(Utils.randomNameGenerator("", 8)) + .openingDate(random_array) + .hierarchy(".") + .build(); String JsonData = oh.toJSON(); final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); Assert.assertNotNull(officeID); } + private Long createOffice(final String officeJSON, - final RequestSpecification requestSpec, - final ResponseSpecification responseSpec) { + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { String officeId = String.valueOf(OfficeResourceHandler.createOffice(officeJSON, requestSpec, responseSpec)); if (officeId.equals("null")) { // Invalid JSON data parameters @@ -64,48 +65,48 @@ public class OfficeIntegrationsTest { return new Long(officeId); @Test - public void testCreateOfficeWithEmptyName() + 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(); + .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() + 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(); + .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() + 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(); + .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); @@ -114,7 +115,7 @@ public class OfficeIntegrationsTest { OfficeHelper oh2 = new OfficeHelper .create(Utils.randomNameGenerator("", 7)) .externalId(Utils.randomNameGenerator(oh.getName())) - .nameDecorated(Utils.randomNameGenerator("",11)) + .nameDecorated(Utils.randomNameGenerator("", 11)) .openingDate(random_array2) .hierarchy(".") .build(); @@ -126,13 +127,13 @@ public class OfficeIntegrationsTest { } @Test - public void testCreateOfficeWithDuplicateExternalId() + public void testCreateOfficeWithDuplicateExternalId () { int random_array1 = {2003, 2, 2}; OfficeHelper oh1 = new OfficeHelper .create(Utils.randomNameGenerator("", 8)) .externalId(oh1.getExternalId()) - .nameDecorated(Utils.randomNameGenerator("",10)) + .nameDecorated(Utils.randomNameGenerator("", 10)) .openingDate(random_array1) .hierarchy(".") .build(); @@ -145,7 +146,7 @@ public class OfficeIntegrationsTest { OfficeHelper oh2 = new OfficeHelper .create(Utils.randomNameGenerator("", 9)) .externalId(Utils.randomNameGenerator("Offices-", 5)) - .nameDecorated(Utils.randomNameGenerator("",11)) + .nameDecorated(Utils.randomNameGenerator("", 11)) .openingDate(random_array2) .hierarchy(".") .build(); @@ -159,12 +160,12 @@ public class OfficeIntegrationsTest { } @Test - public void testCreateOfficeWithEmptyOpeningDate() + public void testCreateOfficeWithEmptyOpeningDate () { OfficeHelper oh = new OfficeHelper - .create(Utils.randomNameGenerator("",9)) - .externalId(Utils.randomNameGenerator("Offices-",4)) - .nameDecorated(Utils.randomNameGenerator("",3)) + .create(Utils.randomNameGenerator("", 9)) + .externalId(Utils.randomNameGenerator("Offices-", 4)) + .nameDecorated(Utils.randomNameGenerator("", 3)) .openingDate(null) .hierarchy(".") .build(); @@ -175,7 +176,7 @@ public class OfficeIntegrationsTest { } @Test - public void testNameUnknowForNow() + public void testNameUnknowForNow () { OfficeHelper oh = new OfficeHelper .create() @@ -187,5 +188,5 @@ public class OfficeIntegrationsTest { } -} + } } From 7a2dec9987da150b2c2cc7030277531029d1f710 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Thu, 11 Dec 2014 13:55:41 +0530 Subject: [PATCH 4/5] Renaming to .java --- .../{OfficeIntegrationsTest => OfficeIntegrationsTest.java} | 0 .../common/office/{OfficeHelper => OfficeHelper.java} | 0 .../office/{OfficeResourceHandler => OfficeResourceHandler.java} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/{OfficeIntegrationsTest => OfficeIntegrationsTest.java} (100%) rename mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/{OfficeHelper => OfficeHelper.java} (100%) rename mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/{OfficeResourceHandler => OfficeResourceHandler.java} (100%) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest.java similarity index 100% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java similarity index 100% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java similarity index 100% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java From f16ae302d293d44cafc0c39ae8fe4544f927ab65 Mon Sep 17 00:00:00 2001 From: varunVNnayar Date: Thu, 11 Dec 2014 14:55:03 +0530 Subject: [PATCH 5/5] License Header Added. --- .../integrationtests/common/office/OfficeHelper.java | 5 +++++ .../common/office/OfficeResourceHandler.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java index 6ca1074b1..c546790cf 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper.java @@ -1,3 +1,8 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ package org.mifosplatform.integrationtests.common.office; import com.google.gson.Gson; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java index 6fa6d354d..8dd2ca405 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler.java @@ -1,3 +1,8 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ package org.mifosplatform.integrationtests.common.office; import com.google.common.reflect.TypeToken;