fix generic warnings in StaffTest (re. FINERACT-949)

This commit is contained in:
Michael Vorburger
2020-05-08 20:24:31 +02:00
committed by Michael Vorburger ⛑️
parent 22224709b6
commit 077065c1b5
3 changed files with 34 additions and 34 deletions
@@ -26,6 +26,7 @@ import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification; import io.restassured.specification.ResponseSpecification;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper; import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.junit.Assert; import org.junit.Assert;
@@ -51,7 +52,7 @@ public class StaffTest {
@Test @Test
public void testStaffCreate() { public void testStaffCreate() {
final HashMap response = StaffHelper.createStaffMap(requestSpec, responseSpec); Map<String, Object> response = StaffHelper.createStaffMap(requestSpec, responseSpec);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.get("officeId"), 1); Assert.assertEquals(response.get("officeId"), 1);
@@ -114,7 +115,7 @@ public class StaffTest {
@Test @Test
public void testStaffFetch() { public void testStaffFetch() {
final HashMap response = StaffHelper.getStaff(requestSpec, responseSpec, 1); Map<String, Object> response = StaffHelper.getStaff(requestSpec, responseSpec, 1);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertNotNull(response.get("id")); Assert.assertNotNull(response.get("id"));
Assert.assertEquals(response.get("id"), 1); Assert.assertEquals(response.get("id"), 1);
@@ -132,8 +133,8 @@ public class StaffTest {
@Test @Test
public void testStaffListStatusActive() { public void testStaffListStatusActive() {
final List<HashMap> responseActive = (List<HashMap>)StaffHelper.getStaffListWithState(requestSpec, responseSpec, "active"); List<Map<String, Object>> responseActive = StaffHelper.getStaffListWithState(requestSpec, responseSpec, "active");
for(final HashMap staff : responseActive) { for(final Map<String, Object> staff : responseActive) {
Assert.assertNotNull(staff.get("id")); Assert.assertNotNull(staff.get("id"));
Assert.assertEquals(staff.get("isActive"), true); Assert.assertEquals(staff.get("isActive"), true);
} }
@@ -141,15 +142,14 @@ public class StaffTest {
@Test @Test
public void testStaffListStatusInactive() { public void testStaffListStatusInactive() {
final List<HashMap> responseInactive = (List<HashMap>)StaffHelper.getStaffListWithState(requestSpec, responseSpec, "inactive"); List<Map<String, Object>> responseInactive = StaffHelper.getStaffListWithState(requestSpec, responseSpec, "inactive");
for(final Map<String, Object> staff : responseInactive) {
for(final HashMap staff : responseInactive) {
Assert.assertNotNull(staff.get("id")); Assert.assertNotNull(staff.get("id"));
Assert.assertEquals(staff.get("isActive"), false); Assert.assertEquals(staff.get("isActive"), false);
} }
} }
@Test @Test(expected = ClassCastException.class) // because "xyz" will return an error, not a List
public void testStaffListFetchWrongState() { public void testStaffListFetchWrongState() {
StaffHelper.getStaffListWithState(requestSpec, responseSpecForValidationError, "xyz"); StaffHelper.getStaffListWithState(requestSpec, responseSpecForValidationError, "xyz");
} }
@@ -161,7 +161,7 @@ public class StaffTest {
@Test @Test
public void testStaffUpdate() { public void testStaffUpdate() {
final HashMap<String, Object> map = new HashMap<>(); final Map<String, Object> map = new HashMap<>();
final String firstname = Utils.randomNameGenerator("michael_", 10); final String firstname = Utils.randomNameGenerator("michael_", 10);
final String lastname = Utils.randomNameGenerator("Doe_", 10); final String lastname = Utils.randomNameGenerator("Doe_", 10);
final String externalId = Utils.randomStringGenerator("EXT", 97); final String externalId = Utils.randomStringGenerator("EXT", 97);
@@ -172,8 +172,9 @@ public class StaffTest {
map.put("externalId", externalId); map.put("externalId", externalId);
map.put("mobileNo", mobileNo); map.put("mobileNo", mobileNo);
final HashMap response = (HashMap) StaffHelper.updateStaff(requestSpec, responseSpec, 1, map); Map<String, Object> response = StaffHelper.updateStaff(requestSpec, responseSpec, 1, map);
final HashMap changes = (HashMap) response.get("changes"); @SuppressWarnings("unchecked")
Map<String, Object> changes = (Map<String, Object>) response.get("changes");
Assert.assertEquals(1, response.get("resourceId")); Assert.assertEquals(1, response.get("resourceId"));
Assert.assertEquals(firstname, changes.get("firstname")); Assert.assertEquals(firstname, changes.get("firstname"));
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class Utils { public class Utils {
private final static Logger logger = LoggerFactory.getLogger(Utils.class); private final static Logger logger = LoggerFactory.getLogger(Utils.class);
public static final String TENANT_PARAM_NAME = "tenantIdentifier"; public static final String TENANT_PARAM_NAME = "tenantIdentifier";
public static final String DEFAULT_TENANT = "default"; public static final String DEFAULT_TENANT = "default";
@@ -83,11 +83,11 @@ public class Utils {
logger.info("{} return HTTP 200, application is now ready for integration testing!", HEALTH_URL); logger.info("{} return HTTP 200, application is now ready for integration testing!", HEALTH_URL);
return; return;
} else { } else {
logger.info("{} returned HTTP {}, going to wait and retry (attempt {})", new Object[] { HEALTH_URL, healthHttpStatus, attempt++ }); logger.info("{} returned HTTP {}, going to wait and retry (attempt {})", HEALTH_URL, healthHttpStatus, attempt++);
sleep(3); sleep(3);
} }
} catch (Exception e) { } catch (Exception e) {
logger.info("{} caused {}, going to wait and retry (attempt {})", new Object[] { HEALTH_URL, e.getMessage(), attempt++ }); logger.info("{} caused {}, going to wait and retry (attempt {})", HEALTH_URL, e.getMessage(), attempt++);
lastException = e; lastException = e;
sleep(3); sleep(3);
} }
@@ -117,8 +117,8 @@ public class Utils {
logger.info("Logging in, for integration test..."); logger.info("Logging in, for integration test...");
System.out.println("-----------------------------------LOGIN-----------------------------------------"); System.out.println("-----------------------------------LOGIN-----------------------------------------");
String json = RestAssured.given().contentType(ContentType.JSON) String json = RestAssured.given().contentType(ContentType.JSON)
.body("{\"username\":\"mifos\", \"password\":\"password\"}") .body("{\"username\":\"mifos\", \"password\":\"password\"}")
.expect().log().ifError().when().post(LOGIN_URL).asString(); .expect().log().ifError().when().post(LOGIN_URL).asString();
assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false)); assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false));
String key = JsonPath.with(json).get("base64EncodedAuthenticationKey"); String key = JsonPath.with(json).get("base64EncodedAuthenticationKey");
assertThat("Failed to obtain key: " + json, StringUtils.isBlank(key), is(false)); assertThat("Failed to obtain key: " + json, StringUtils.isBlank(key), is(false));
@@ -141,12 +141,12 @@ public class Utils {
} }
public static String performGetTextResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static String performGetTextResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String getURL){ final String getURL){
return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString(); return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
} }
public static byte[] performGetBinaryResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static byte[] performGetBinaryResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String getURL){ final String getURL){
return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asByteArray(); return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asByteArray();
} }
@@ -209,10 +209,10 @@ public class Utils {
return randomStringGenerator(prefix, lenOfRandomSuffix); return randomStringGenerator(prefix, lenOfRandomSuffix);
} }
public static Long randomNumberGenerator(final int expectedLength){ public static Long randomNumberGenerator(final int expectedLength){
final String source="1234567890"; final String source="1234567890";
final int lengthofSource=source.length(); final int lengthofSource=source.length();
final Random random=new Random(); final Random random=new Random();
StringBuilder stringBuilder=new StringBuilder(expectedLength); StringBuilder stringBuilder=new StringBuilder(expectedLength);
for (int i = 0; i < expectedLength; i++) { for (int i = 0; i < expectedLength; i++) {
stringBuilder.append(source.charAt(random.nextInt(lengthofSource))); stringBuilder.append(source.charAt(random.nextInt(lengthofSource)));
} }
@@ -239,7 +239,7 @@ public class Utils {
} }
public static String performServerTemplatePost(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, public static String performServerTemplatePost(final RequestSpecification requestSpec,final ResponseSpecification responseSpec,
final String postURL,final String legalFormType,final File file,final String locale,final String dateFormat) { final String postURL,final String legalFormType,final File file,final String locale,final String dateFormat) {
final String importDocumentId=given().spec(requestSpec) final String importDocumentId=given().spec(requestSpec)
.queryParam("legalFormType",legalFormType) .queryParam("legalFormType",legalFormType)
@@ -253,7 +253,7 @@ public class Utils {
} }
public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,final ResponseSpecification responseSpec,
final String getURL,final String importDocumentId){ final String getURL,final String importDocumentId){
final String templateLocation=given().spec(requestSpec). final String templateLocation=given().spec(requestSpec).
queryParam("importDocumentId",importDocumentId) queryParam("importDocumentId",importDocumentId)
.expect().spec(responseSpec) .expect().spec(responseSpec)
@@ -24,6 +24,7 @@ import io.restassured.specification.ResponseSpecification;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
public class StaffHelper { public class StaffHelper {
@@ -32,13 +33,11 @@ public class StaffHelper {
private static final String CREATE_STAFF_URL = "/fineract-provider/api/v1/staff"; private static final String CREATE_STAFF_URL = "/fineract-provider/api/v1/staff";
private static final String RESOURCE_ID = "resourceId";
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);
} }
@@ -55,35 +54,35 @@ public class StaffHelper {
return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId"); return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId");
} }
public static HashMap createStaffMap(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { public static Map<String, Object> createStaffMap(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
return createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()); return createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON());
} }
public static HashMap createStaffWithJson(final RequestSpecification requestSpec, public static Map<String, Object> 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, public static Map<String, Object> getStaff(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer staffId) { final ResponseSpecification responseSpec, final Integer staffId) {
final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER; final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, url, ""); return Utils.performServerGet(requestSpec, responseSpec, url, "");
} }
public static List<HashMap> getStaffList(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { public static List<Map<String, Object>> getStaffList(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER; final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, url, ""); return Utils.performServerGet(requestSpec, responseSpec, url, "");
} }
public static Object getStaffListWithState(final RequestSpecification requestSpec, public static List<Map<String, Object>> getStaffListWithState(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String status) { final ResponseSpecification responseSpec, final String status) {
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER + "&status=" + status; final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER + "&status=" + status;
return Utils.performServerGet(requestSpec, responseSpec, url, ""); return Utils.performServerGet(requestSpec, responseSpec, url, "");
} }
public static Object updateStaff(final RequestSpecification requestSpec, public static Map<String, Object> updateStaff(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer staffId, final HashMap<String, Object> changes) { final ResponseSpecification responseSpec, final Integer staffId, final Map<String, Object> changes) {
final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER; final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER;
final String json = new Gson().toJson(changes); final String json = new Gson().toJson(changes);
return Utils.performServerPut(requestSpec, responseSpec, url, json, ""); return Utils.performServerPut(requestSpec, responseSpec, url, json, "");