Added Group Tests for Creation, Activation, Client Association, Updating & Deletion.
This commit is contained in:
committed by
Vishwas Babu A J
parent
5669ccfc4b
commit
fff9cba28f
+67
@@ -0,0 +1,67 @@
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
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.Utils;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Group Test for checking Group:
|
||||
* Creation, Activation, Client Association, Updating & Deletion
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class GroupTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkGroupLoanCreateAndDisburseFlow() {
|
||||
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Integer groupID = GroupHelper.createGroup(requestSpec, responseSpec);
|
||||
GroupHelper.verifyGroupCreatedOnServer(requestSpec, responseSpec, groupID);
|
||||
|
||||
groupID = GroupHelper.activateGroup(requestSpec, responseSpec, groupID.toString());
|
||||
GroupHelper.verifyGroupActivatedOnServer(requestSpec, responseSpec, groupID, true);
|
||||
|
||||
groupID = GroupHelper.associateClient(requestSpec, responseSpec, groupID.toString(),clientID.toString());
|
||||
GroupHelper.verifyGroupMembers(requestSpec,responseSpec,groupID, clientID);
|
||||
|
||||
groupID = GroupHelper.disAssociateClient(requestSpec, responseSpec, groupID.toString(),clientID.toString());
|
||||
GroupHelper.verifyEmptyGroupMembers(requestSpec,responseSpec,groupID);
|
||||
|
||||
String updatedGroupName=GroupHelper.randomNameGenerator("Group-",5);
|
||||
groupID = GroupHelper.updateGroup(requestSpec, responseSpec, updatedGroupName, groupID.toString());
|
||||
GroupHelper.verifyGroupDetails(requestSpec, responseSpec, groupID,"name",updatedGroupName);
|
||||
|
||||
groupID = GroupHelper.createGroup(requestSpec, responseSpec);
|
||||
groupID = GroupHelper.deleteGroup(requestSpec, responseSpec, groupID.toString());
|
||||
GroupHelper.verifyGroupCreatedOnServer(requestSpec, responseSpec, groupID);
|
||||
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class GroupHelper {
|
||||
|
||||
private static final String CREATE_GROUP_URL = "/mifosng-provider/api/v1/groups?tenantIdentifier=default";
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final boolean active) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return createGroup(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(true,activationDate), "groupId");
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(false,""), "groupId");
|
||||
}
|
||||
|
||||
public static Integer associateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final String clientMember) {
|
||||
String GROUP_ASSOCIATE_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?command=associateClients&tenantIdentifier=default";
|
||||
System.out.println("---------------------------------Associate Client To A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId");
|
||||
}
|
||||
|
||||
public static Integer disAssociateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final String clientMember) {
|
||||
String GROUP_ASSOCIATE_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?command=disassociateClients&tenantIdentifier=default";
|
||||
System.out.println("---------------------------------Disassociate Client To A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId");
|
||||
}
|
||||
|
||||
public static Integer activateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId) {
|
||||
String GROUP_ASSOCIATE_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?command=activate&tenantIdentifier=default";
|
||||
System.out.println("---------------------------------Activate A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, activateGroupAsJSON(""), "groupId");
|
||||
}
|
||||
|
||||
public static Integer updateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
String name, final String groupId) {
|
||||
String GROUP_ASSOCIATE_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?tenantIdentifier=default";
|
||||
System.out.println("---------------------------------UPDATE GROUP---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, updateGroupAsJSON(name), "groupId");
|
||||
}
|
||||
|
||||
public static Integer deleteGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId) {
|
||||
String GROUP_ASSOCIATE_URL = "/mifosng-provider/api/v1/groups/" + groupId + "?tenantIdentifier=default";
|
||||
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, "groupId");
|
||||
}
|
||||
|
||||
|
||||
public static String getTestGroupAsJSON(final boolean active, final String activationDate) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("officeId", "1");
|
||||
map.put("name", randomNameGenerator("Group_Name_", 5));
|
||||
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||
if (active==true){
|
||||
map.put("active", "true");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("activationDate", activationDate);
|
||||
}
|
||||
else
|
||||
map.put("active", "false");
|
||||
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
|
||||
public static String associateClientAsJSON(final String clientMember) {
|
||||
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(clientMember);
|
||||
map.put("clientMembers", list);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String activateGroupAsJSON(final String activationDate) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
if (activationDate != "")
|
||||
map.put("activationDate", activationDate);
|
||||
else
|
||||
map.put("activationDate", "04 March 2011");
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updateGroupAsJSON(final String name) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("name", name);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n");
|
||||
String GROUP_URL = "/mifosng-provider/api/v1/groups/" + generatedGroupID + "?tenantIdentifier=default";
|
||||
Integer responseGroupID = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE GROUP",generatedGroupID, responseGroupID);
|
||||
}
|
||||
|
||||
public static void verifyGroupDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final String field, final String expectedValue) {
|
||||
System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n");
|
||||
String GROUP_URL = "/mifosng-provider/api/v1/groups/" + generatedGroupID + "?tenantIdentifier=default";
|
||||
String responseValue = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, field);
|
||||
assertEquals("ERROR IN CREATING THE GROUP",expectedValue, responseValue);
|
||||
}
|
||||
|
||||
public static void verifyGroupActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final boolean generatedGroupStatus) {
|
||||
System.out.println("------------------------------CHECK GROUP STATUS------------------------------------\n");
|
||||
String GROUP_URL = "/mifosng-provider/api/v1/groups/" + generatedGroupID + "?tenantIdentifier=default";
|
||||
boolean responseGroupStatus = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "active");
|
||||
assertEquals("ERROR IN ACTIVATING THE GROUP",generatedGroupStatus, responseGroupStatus);
|
||||
}
|
||||
|
||||
public static void verifyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final Integer groupMember) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
System.out.println("------------------------------CHECK GROUP MEMBERS------------------------------------\n");
|
||||
String GROUP_URL = "/mifosng-provider/api/v1/groups/" + generatedGroupID + "?associations=clientMembers&tenantIdentifier=default";
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers");
|
||||
assertTrue("ERROR IN GROUP MEMBER",list.toString().contains("id=" + groupMember.toString()));
|
||||
}
|
||||
|
||||
public static void verifyEmptyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
System.out.println("------------------------------CHECK EMPTY GROUP MEMBER LIST------------------------------------\n");
|
||||
String GROUP_URL = "/mifosng-provider/api/v1/groups/" + generatedGroupID + "?associations=clientMembers&tenantIdentifier=default";
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers");
|
||||
System.out.println(list);
|
||||
assertEquals("GROUP MEMBER LIST NOT EMPTY",list, null);
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
}
|
||||
+48
-9
@@ -6,8 +6,6 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
|
||||
@@ -16,13 +14,19 @@ import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import java.lang.System;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Utils {
|
||||
|
||||
private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default";
|
||||
|
||||
|
||||
public static void initializeRESTAssured() {
|
||||
RestAssured.baseURI = "https://localhost";
|
||||
RestAssured.baseURI ="https://localhost";
|
||||
RestAssured.port = 8443;
|
||||
RestAssured.keystore("../keystore.jks", "openmf");
|
||||
}
|
||||
@@ -33,10 +37,11 @@ public class Utils {
|
||||
String json = RestAssured.post(LOGIN_URL).asString();
|
||||
assertThat("Failed to login into mifosx platform", StringUtils.isBlank(json), is(false));
|
||||
return JsonPath.with(json).get("base64EncodedAuthenticationKey");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof HttpHostConnectException) {
|
||||
HttpHostConnectException hh = (HttpHostConnectException) e;
|
||||
fail("Failed to connect to mifosx platform:" + hh.getMessage());
|
||||
fail("Failed to connect to mifosx platform:"+hh.getMessage());
|
||||
}
|
||||
|
||||
throw new RuntimeException(e);
|
||||
@@ -44,18 +49,52 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static <T> T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String getURL, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
|
||||
final String getURL, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().get(getURL).andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
|
||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).body(jsonBodyToSend)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().post(postURL)
|
||||
.andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerPut(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String putURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).body(jsonBodyToSend)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().put(putURL)
|
||||
.andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerDelete(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String deleteURL, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().delete(deleteURL)
|
||||
.andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static String convertDateToURLFormat(String dateToBeConvert){
|
||||
SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy");
|
||||
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String reformattedStr="";
|
||||
try {
|
||||
reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reformattedStr;
|
||||
}
|
||||
|
||||
public static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) {
|
||||
int lengthOfSource = sourceSetString.length();
|
||||
Random rnd = new Random();
|
||||
|
||||
Reference in New Issue
Block a user