Merge pull request #453 from vishwasbabu/develop
updating inetgration tests for changes in journal entries api
This commit is contained in:
+7
-28
@@ -6,6 +6,8 @@ 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;
|
||||
|
||||
@@ -14,18 +16,13 @@ import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -36,11 +33,10 @@ 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);
|
||||
@@ -49,34 +45,17 @@ 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();
|
||||
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)
|
||||
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 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();
|
||||
|
||||
+13
-13
@@ -22,30 +22,29 @@ public class JournalEntryHelper {
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public void checkJournalEntryForExpenseAccount(final Account expenseAccount, final String date, final JournalEntry accountEntries) {
|
||||
checkJournalEntry(expenseAccount, Utils.convertDateToURLFormat(date),accountEntries);
|
||||
public void checkJournalEntryForExpenseAccount(final Account expenseAccount, final String date, final JournalEntry accountEntries) {
|
||||
checkJournalEntry(expenseAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
|
||||
public void checkJournalEntryForAssetAccount(final Account assetAccount, final String date, final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(assetAccount,Utils.convertDateToURLFormat(date),accountEntries);
|
||||
public void checkJournalEntryForAssetAccount(final Account assetAccount, final String date, final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(assetAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForIncomeAccount(final Account incomeAccount, final String date, final JournalEntry accountEntries) {
|
||||
checkJournalEntry(incomeAccount, Utils.convertDateToURLFormat(date), accountEntries);
|
||||
checkJournalEntry(incomeAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
private String getEntryValueFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
private String getEntryValueFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
HashMap map = (HashMap) entryResponse.get(entryNumber).get("entryType");
|
||||
return (String) map.get("value");
|
||||
}
|
||||
|
||||
private Float getTransactionAmountFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
private Float getTransactionAmountFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
return (Float) entryResponse.get(entryNumber).get("amount");
|
||||
}
|
||||
|
||||
private void checkJournalEntry(final Account account, final String date, final JournalEntry... accountEntries){
|
||||
String url = createURLForGettingAccountEntries(account,date);
|
||||
private void checkJournalEntry(final Account account, final String date, final JournalEntry... accountEntries) {
|
||||
String url = createURLForGettingAccountEntries(account, date);
|
||||
ArrayList<HashMap> response = Utils.performServerGet(requestSpec, responseSpec, url, "pageItems");
|
||||
for (int i = 0; i < accountEntries.length; i++) {
|
||||
assertThat(getEntryValueFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionType()));
|
||||
@@ -53,9 +52,10 @@ public class JournalEntryHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private String createURLForGettingAccountEntries (final Account account,final String date){
|
||||
return new String ("/mifosng-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type=" +account.getAccountType()
|
||||
+ "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default"+"&orderBy=id&sortOrder=desc");
|
||||
private String createURLForGettingAccountEntries(final Account account, final String date) {
|
||||
return new String("/mifosng-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type="
|
||||
+ account.getAccountType() + "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default"
|
||||
+ "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user