diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java index ab7bfa199..e42436bbd 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java @@ -15,7 +15,7 @@ import org.junit.Before; import org.junit.Test; import org.mifosplatform.integrationtests.common.ClientHelper; import org.mifosplatform.integrationtests.common.GroupHelper; -import org.mifosplatform.integrationtests.common.StaffHelper; +import org.mifosplatform.integrationtests.common.organisation.StaffHelper; import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/StaffTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/StaffTest.java new file mode 100644 index 000000000..0f56dc1b4 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/StaffTest.java @@ -0,0 +1,89 @@ +/** + * 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; + +import java.util.HashMap; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.organisation.StaffHelper; +import org.mifosplatform.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class StaffTest { + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + private ResponseSpecification responseSpecForValidationError; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build(); + } + + @Test + public void testStaffCreate() { + final HashMap response = StaffHelper.createStaffMap(requestSpec, responseSpec); + + Assert.assertNotNull(response); + Assert.assertEquals(response.get("officeId"), 1); + Assert.assertNotNull(response.get("resourceId")); + } + + @Test + public void testStaffCreateValidationError() { + + final String noOfficeJson = StaffHelper.createStaffWithJSONFields("firstname", "lastname"); + final String noFirstnameJson = StaffHelper.createStaffWithJSONFields("officeId", "lastname"); + final String noLastnameJson = StaffHelper.createStaffWithJSONFields("officeId", "firstname"); + + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noOfficeJson); + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noFirstnameJson); + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noLastnameJson); + + final HashMap map = new HashMap<>(); + + map.put("officeId", 1); + map.put("firstname", Utils.randomNameGenerator("michael_", 5)); + map.put("lastname", Utils.randomNameGenerator("Doe_", 4)); + + /** Long firstname test */ + map.put("firstname", Utils.randomNameGenerator("michael_", 43)); + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map)); + map.put("firstname", Utils.randomNameGenerator("michael_", 5)); + + /** Long lastname test */ + map.put("lastname", Utils.randomNameGenerator("Doe_", 47)); + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map)); + map.put("lastname", Utils.randomNameGenerator("Doe_",4)); + + /** Long mobileNo test */ + map.put("mobileNo", Utils.randomNameGenerator("num_", 47)); + StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map)); + } + + public void testStaffCreateMaxNameLength() { + + final HashMap map = new HashMap<>(); + + map.put("officeId", 1); + map.put("firstname", Utils.randomNameGenerator("michael_",42)); + map.put("lastname", Utils.randomNameGenerator("Doe_", 47)); + + StaffHelper.createStaffWithJson(requestSpec, responseSpec, new Gson().toJson(map)); + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StaffHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/StaffHelper.java similarity index 57% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StaffHelper.java rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/StaffHelper.java index 0ca102866..752385bcd 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/StaffHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/StaffHelper.java @@ -1,60 +1,92 @@ -/** - * 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; - -import com.google.gson.Gson; -import com.jayway.restassured.specification.RequestSpecification; -import com.jayway.restassured.specification.ResponseSpecification; - -import java.util.HashMap; - -public class StaffHelper { - - private static final String TRANSFER_STAFF_URL = "/mifosng-provider/api/v1/groups"; - - private static final String CREATE_STAFF_URL = "/mifosng-provider/api/v1/staff"; - - private static final String RESOURCE_ID = "resourceId"; - - public static final String GROUP_ID = "groupId"; - - - - public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, - final Integer groupId,final Integer staffToTransfer ,final String note){ - final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+Utils.TENANT_IDENTIFIER; - return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID); - } - - - public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) { - final HashMap map = new HashMap<>(); - map.put("staffId", staffToTransferId); - map.put("note", note); - System.out.println("map : " + map); - return new Gson().toJson(map); - } - - - - public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - final String url = CREATE_STAFF_URL +"?"+ Utils.TENANT_IDENTIFIER ; - return Utils.performServerPost(requestSpec, responseSpec, url, createStaffAsJSON(), RESOURCE_ID); - } - - - public static String createStaffAsJSON(){ - final HashMap map = new HashMap<>(); - map.put("officeId",1); - map.put("firstname", Utils.randomNameGenerator("michael_",5)); - map.put("lastname", Utils.randomNameGenerator("Doe_",4)); - map.put("isLoanOfficer", true); - System.out.println("map : " + map); - return new Gson().toJson(map); - } - - -} +/** + * 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.organisation; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.mifosplatform.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class StaffHelper { + + private static final String TRANSFER_STAFF_URL = "/mifosng-provider/api/v1/groups"; + + private static final String CREATE_STAFF_URL = "/mifosng-provider/api/v1/staff"; + + private static final String RESOURCE_ID = "resourceId"; + + public static final String GROUP_ID = "groupId"; + + + + public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer groupId,final Integer staffToTransfer ,final String note){ + final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+ Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID); + } + + + public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) { + final HashMap map = new HashMap<>(); + map.put("staffId", staffToTransferId); + map.put("note", note); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + + + public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId"); + } + + public static HashMap createStaffMap(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()); + } + + public static HashMap createStaffWithJson(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String json) { + final String url = CREATE_STAFF_URL +"?"+ Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(requestSpec, responseSpec, url, json, ""); + } + + public static String createStaffAsJSON(){ + final HashMap map = new HashMap<>(); + map.put("officeId", 1); + map.put("firstname", Utils.randomNameGenerator("michael_",5)); + map.put("lastname", Utils.randomNameGenerator("Doe_",4)); + map.put("isLoanOfficer", true); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String createStaffWithJSONFields(String... fields) { + final HashMap map = new HashMap<>(); + final List fieldList = Arrays.asList(fields); + if(fieldList.contains("officeId")) { + map.put("officeId", 1); + } + if(fieldList.contains("firstname")) { + map.put("firstname", Utils.randomNameGenerator("michael_",5)); + } + if(fieldList.contains("lastname")) { + map.put("lastname", Utils.randomNameGenerator("Doe_",4)); + } + if(fieldList.contains("isLoanOfficer")) { + map.put("isLoanOfficer", true); + } + if(fieldList.contains("mobileNo")) { + map.put("mobileNo", "+123515198"); + } + System.out.println("map : " + map); + return new Gson().toJson(map); + } +}