Add tests for staff retrieval
This commit is contained in:
+53
-3
@@ -6,12 +6,13 @@
|
|||||||
package org.mifosplatform.integrationtests;
|
package org.mifosplatform.integrationtests;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mifosplatform.integrationtests.common.organisation.StaffHelper;
|
|
||||||
import org.mifosplatform.integrationtests.common.Utils;
|
import org.mifosplatform.integrationtests.common.Utils;
|
||||||
|
import org.mifosplatform.integrationtests.common.organisation.StaffHelper;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||||
@@ -25,6 +26,7 @@ public class StaffTest {
|
|||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private ResponseSpecification responseSpec;
|
private ResponseSpecification responseSpec;
|
||||||
private ResponseSpecification responseSpecForValidationError;
|
private ResponseSpecification responseSpecForValidationError;
|
||||||
|
private ResponseSpecification responseSpecForNotFoundError;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@@ -33,6 +35,7 @@ public class StaffTest {
|
|||||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
this.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
|
this.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||||
|
this.responseSpecForNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -81,9 +84,56 @@ public class StaffTest {
|
|||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
map.put("officeId", 1);
|
map.put("officeId", 1);
|
||||||
map.put("firstname", Utils.randomNameGenerator("michael_",42));
|
map.put("firstname", Utils.randomNameGenerator("michael_", 42));
|
||||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 47));
|
map.put("lastname", Utils.randomNameGenerator("Doe_", 46));
|
||||||
|
|
||||||
StaffHelper.createStaffWithJson(requestSpec, responseSpec, new Gson().toJson(map));
|
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 final String GROUP_ID = "groupId";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
final Integer groupId,final Integer staffToTransfer ,final String note){
|
final Integer groupId,final Integer staffToTransfer ,final String note){
|
||||||
final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+ Utils.TENANT_IDENTIFIER;
|
final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+ Utils.TENANT_IDENTIFIER;
|
||||||
return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID);
|
return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) {
|
public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) {
|
||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("staffId", staffToTransferId);
|
map.put("staffId", staffToTransferId);
|
||||||
@@ -42,8 +40,6 @@ public class StaffHelper {
|
|||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||||
return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId");
|
return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId");
|
||||||
}
|
}
|
||||||
@@ -54,15 +50,32 @@ public class StaffHelper {
|
|||||||
|
|
||||||
public static HashMap createStaffWithJson(final RequestSpecification requestSpec,
|
public static HashMap createStaffWithJson(final RequestSpecification requestSpec,
|
||||||
final ResponseSpecification responseSpec, final String json) {
|
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, "");
|
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(){
|
public static String createStaffAsJSON(){
|
||||||
final HashMap<String, Object> map = new HashMap<>();
|
final HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("officeId", 1);
|
map.put("officeId", 1);
|
||||||
map.put("firstname", Utils.randomNameGenerator("michael_",5));
|
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||||
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
|
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||||
map.put("isLoanOfficer", true);
|
map.put("isLoanOfficer", true);
|
||||||
System.out.println("map : " + map);
|
System.out.println("map : " + map);
|
||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
@@ -75,10 +88,10 @@ public class StaffHelper {
|
|||||||
map.put("officeId", 1);
|
map.put("officeId", 1);
|
||||||
}
|
}
|
||||||
if(fieldList.contains("firstname")) {
|
if(fieldList.contains("firstname")) {
|
||||||
map.put("firstname", Utils.randomNameGenerator("michael_",5));
|
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||||
}
|
}
|
||||||
if(fieldList.contains("lastname")) {
|
if(fieldList.contains("lastname")) {
|
||||||
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
|
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||||
}
|
}
|
||||||
if(fieldList.contains("isLoanOfficer")) {
|
if(fieldList.contains("isLoanOfficer")) {
|
||||||
map.put("isLoanOfficer", true);
|
map.put("isLoanOfficer", true);
|
||||||
|
|||||||
Reference in New Issue
Block a user