MIFOSX-117: integrate andreas work on UGD.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package org.mifosplatform.common;
|
||||
|
||||
|
||||
import static com.jayway.restassured.RestAssured.given;
|
||||
import static com.jayway.restassured.path.json.JsonPath.from;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
|
||||
import com.jayway.restassured.RestAssured;
|
||||
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.port = 8443;
|
||||
RestAssured.keystore("../keystore.jks", "openmf");
|
||||
}
|
||||
|
||||
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
|
||||
try {
|
||||
System.out.println("-----------------------------------LOGIN-----------------------------------------");
|
||||
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) {
|
||||
if (e instanceof HttpHostConnectException) {
|
||||
HttpHostConnectException hh = (HttpHostConnectException) e;
|
||||
fail("Failed to connect to mifosx platform:"+hh.getMessage());
|
||||
}
|
||||
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
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)
|
||||
.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();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
sb.append((sourceSetString).charAt(rnd.nextInt(lengthOfSource)));
|
||||
return (prefix + (sb.toString()));
|
||||
}
|
||||
|
||||
public static String randomStringGenerator(final String prefix, final int len) {
|
||||
return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package org.mifosplatform.template;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.mifosplatform.portfolio.loanaccount.LoanScheduleTestDataHelper;
|
||||
import org.mifosplatform.portfolio.loanaccount.MonetaryCurrencyBuilder;
|
||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||
import org.mifosplatform.template.domain.Template;
|
||||
import org.mifosplatform.template.service.TemplateMergeService;
|
||||
|
||||
public class TemplateMergeServiceTest {
|
||||
|
||||
private Template template;
|
||||
private final static String TEST_FILE = "src/test/resources/template.mustache";
|
||||
private static TemplateMergeService tms;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
tms = new TemplateMergeService(new FromJsonHelper());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileHelloTemplate() throws Exception {
|
||||
String name = "TemplateName";
|
||||
String text = "Hello Test for Template {{template.name}}!";
|
||||
|
||||
template = new Template(name, text, null, null, null);
|
||||
|
||||
HashMap<String, Object> scopes = new HashMap<String, Object>();
|
||||
scopes.put("template", template);
|
||||
|
||||
String output ="";
|
||||
output = tms.compile(template, scopes);
|
||||
assertEquals("Hello Test for Template TemplateName!", output);
|
||||
}
|
||||
|
||||
|
||||
//TODO:ASSERT!!
|
||||
@Test
|
||||
public void compileLoanSummary() throws IOException{
|
||||
|
||||
LocalDate july2nd = new LocalDate(2012, 7, 2);
|
||||
MonetaryCurrency usDollars = new MonetaryCurrencyBuilder().withCode("USD").withDigitsAfterDecimal(2).build();
|
||||
List<LoanRepaymentScheduleInstallment> installments
|
||||
= LoanScheduleTestDataHelper.createSimpleLoanSchedule(july2nd, usDollars);
|
||||
|
||||
File file = new File(TEST_FILE);
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(file));
|
||||
byte[] bytes = new byte[(int) file.length()];
|
||||
dis.readFully(bytes);
|
||||
String content = new String(bytes, "UTF-8");
|
||||
|
||||
template = new Template("TemplateName", content, null, null, null);
|
||||
|
||||
HashMap<String, Object> scopes = new HashMap<String, Object>();
|
||||
scopes.put("installments", installments);
|
||||
|
||||
String output = tms.compile(template, scopes);
|
||||
|
||||
dis.close();
|
||||
|
||||
System.out.println(output);
|
||||
dis.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
|
||||
|
||||
<tx:annotation-driven />
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
|
||||
p:driverClassName="com.mysql.jdbc.Driver"
|
||||
p:url="jdbc:mysql://localhost:3306/mifosplatform-tenants"
|
||||
p:username="root"
|
||||
p:password="mysql" />
|
||||
|
||||
<bean id="hibernateExceptionTranslator" class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />
|
||||
|
||||
|
||||
<bean id="entityManagerFactory"
|
||||
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
|
||||
<property name="dataSource" ref="tenantDataSourceJndi"/>
|
||||
<property name="packagesToScan">
|
||||
<list>
|
||||
<value>org.mifosplatform.template</value>
|
||||
<value>org.mifosplatform.commands.domain</value>
|
||||
<value>org.mifosplatform.useradministration.domain</value>
|
||||
<value>org.mifosplatform.organisation.office.domain</value>
|
||||
<value>org.mifosplatform.organisation.staff.domain</value>
|
||||
<value>org.mifosplatform.infrastructure.core.serialization</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
|
||||
</property>
|
||||
<property name="jpaProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
|
||||
<prop key="hibernate.hbm2ddl.auto">create</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
|
||||
<context:component-scan base-package="org.mifosplatform.accounting.*,
|
||||
org.mifosplatform.commands.handler.*,
|
||||
org.mifosplatform.commands.service.*,
|
||||
org.mifosplatform.commands.*,
|
||||
org.mifosplatform.audit.*,
|
||||
org.mifosplatform.infrastructure.*,
|
||||
org.mifosplatform.scheduledjobs.*,
|
||||
org.mifosplatform.organisation.*,
|
||||
org.mifosplatform.portfolio.loanaccount.*,
|
||||
org.mifosplatform.portfolio.savingsaccount.*,
|
||||
org.mifosplatform.portfolio.*,
|
||||
org.mifosplatform.template.*,
|
||||
org.mifosplatform.template.service.*,
|
||||
org.mifosplatform.useradministration.*" >
|
||||
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />
|
||||
</context:component-scan>
|
||||
|
||||
<jpa:repositories base-package="org.mifosplatform.commands.domain" />
|
||||
<jpa:repositories base-package="org.mifosplatform.infrastructure.*.domain" />
|
||||
<jpa:repositories base-package="org.mifosplatform.accounting.*.domain" />
|
||||
<jpa:repositories base-package="org.mifosplatform.useradministration.domain" />
|
||||
<jpa:repositories base-package="org.mifosplatform.organisation.*.domain" />
|
||||
<jpa:repositories base-package="org.mifosplatform.portfolio.*" />
|
||||
<jpa:repositories base-package="org.mifosplatform.template.domain" />
|
||||
|
||||
<jee:jndi-lookup jndi-name="java:comp/env/jdbc/mifosplatform-tenants" id="tenantDataSourceJndi" />
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,132 @@
|
||||
<h1><span style="font-size:20px"><strong><span style="color:#0000CD">Sample Loan Summary & Repayment Schedule </span></strong></span></h1>
|
||||
|
||||
<h2><span style="font-size:16px"><span style="color:#0000CD">TABLE 1. LOAN SUMMARY</span> </span></h2>
|
||||
|
||||
<table align="left" border="1" cellpadding="3" cellspacing="0" style="width:650px">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Loan size and currency</td>
|
||||
<td> </td>
|
||||
<td>Total no. of installments </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Interest rate </td>
|
||||
<td> </td>
|
||||
<td>Installment frequency</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Commission fee</td>
|
||||
<td> </td>
|
||||
<td>Disbursement date </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Other fees</td>
|
||||
<td> </td>
|
||||
<td>Mandatory savings</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Purpose of loan</td>
|
||||
<td> </td>
|
||||
<td>Maturity date </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Grace period (if applies)</td>
|
||||
<td> </td>
|
||||
<td>Type of guarantee</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Penalty for late payment</td>
|
||||
<td> </td>
|
||||
<td>Maturity of the loan (in months) </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Penalty for pre-payment</td>
|
||||
<td> </td>
|
||||
<td>Total cost of loan (principle + int.+ fees) </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h2><span style="font-size:16px"><span style="color:#0000CD">TABLE 2. REPAYMENT SCHEDULE </span></span></h2>
|
||||
|
||||
<table border="1" cellpadding="3" cellspacing="0" style="width:600px">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Date</td>
|
||||
<td>Disbursement Amount</td>
|
||||
<td>
|
||||
<p>Principle Repayment</p>
|
||||
</td>
|
||||
<td> Interest Repayment</td>
|
||||
<td>Commission Payment</td>
|
||||
<td>Fees</td>
|
||||
<td>Tax Payment</td>
|
||||
<td>Total Repayment</td>
|
||||
<td>Total Balance Outstanding</td>
|
||||
</tr>
|
||||
{{#installments}}
|
||||
<tr>
|
||||
<td>{{dueDate}}</td>
|
||||
<td>{{installmentNumber}}</td>
|
||||
<td>{{fromDate}}</td>
|
||||
<td>{{principal}}</td>
|
||||
<td> </td>
|
||||
<td>{{feeChargesCharged}}</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
{{/installments}}
|
||||
<tr>
|
||||
<td>Total</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Client Signature ___________________________________________________________________ </p>
|
||||
|
||||
<p>Credit Officer Signature _____________________________________________________________ </p>
|
||||
|
||||
<p>Branch Director Signature ___________________________________________________________ </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><span style="font-size:12px"><strong>Please contact the<span style="color:#FF0000"> Macro</span><span style="color:#0000CD">Dreams</span> Customer Service Line if you have questions or complaints about our products, </strong></span></p>
|
||||
|
||||
<p><span style="font-size:12px"><strong>services, or staff: 555-555-5555. Open Monday to Saturday 7:00-20:00. All calls are free. </strong></span></p>
|
||||
Reference in New Issue
Block a user