+53
-3
@@ -6,12 +6,13 @@
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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 org.mifosplatform.integrationtests.common.organisation.StaffHelper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
@@ -25,6 +26,7 @@ public class StaffTest {
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForValidationError;
|
||||
private ResponseSpecification responseSpecForNotFoundError;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -33,6 +35,7 @@ public class StaffTest {
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
this.responseSpecForNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,9 +84,56 @@ public class StaffTest {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_",42));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 47));
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 42));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 46));
|
||||
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpec, new Gson().toJson(map));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffFetch() {
|
||||
final HashMap response = StaffHelper.getStaff(requestSpec, responseSpec, 1);
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertNotNull(response.get("id"));
|
||||
Assert.assertEquals(response.get("id"), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListFetch() {
|
||||
StaffHelper.getStaffList(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusAll() {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpec, "all");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusActive() {
|
||||
final List<HashMap> responseActive = (List<HashMap>) StaffHelper.getStaffListWithState(requestSpec, responseSpec, "active");
|
||||
for(final HashMap staff : responseActive) {
|
||||
Assert.assertNotNull(staff.get("id"));
|
||||
Assert.assertEquals(staff.get("isActive"), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusInactive() {
|
||||
final List<HashMap> responseInactive = (List<HashMap>) StaffHelper.getStaffListWithState(requestSpec, responseSpec, "inactive");
|
||||
|
||||
for(final HashMap staff : responseInactive) {
|
||||
Assert.assertNotNull(staff.get("id"));
|
||||
Assert.assertEquals(staff.get("isActive"), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListFetchWrongState() {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpecForValidationError, "xyz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffFetchNotFound() {
|
||||
StaffHelper.getStaff(requestSpec, responseSpecForNotFoundError, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-9
@@ -26,14 +26,12 @@ public class StaffHelper {
|
||||
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<String, Object> map = new HashMap<>();
|
||||
map.put("staffId", staffToTransferId);
|
||||
@@ -42,8 +40,6 @@ public class StaffHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId");
|
||||
}
|
||||
@@ -54,15 +50,32 @@ public class StaffHelper {
|
||||
|
||||
public static HashMap createStaffWithJson(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String json) {
|
||||
final String url = CREATE_STAFF_URL +"?"+ Utils.TENANT_IDENTIFIER;
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, url, json, "");
|
||||
}
|
||||
|
||||
public static HashMap getStaff(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer staffId) {
|
||||
final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static List<HashMap> getStaffList(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static Object getStaffListWithState(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String status) {
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER + "&status=" + status;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static String createStaffAsJSON(){
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_",5));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
|
||||
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);
|
||||
@@ -75,10 +88,10 @@ public class StaffHelper {
|
||||
map.put("officeId", 1);
|
||||
}
|
||||
if(fieldList.contains("firstname")) {
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_",5));
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
}
|
||||
if(fieldList.contains("lastname")) {
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||
}
|
||||
if(fieldList.contains("isLoanOfficer")) {
|
||||
map.put("isLoanOfficer", true);
|
||||
|
||||
Reference in New Issue
Block a user