fix failing test cases

This commit is contained in:
Vishwas Babu A J
2015-03-04 22:41:44 +05:30
parent d9ce1745da
commit a16265eb92
7 changed files with 55 additions and 76 deletions
@@ -105,17 +105,21 @@ public class LoanTransactionHelper {
} }
public HashMap approveLoan(final String approvalDate, final Integer loanID) { public HashMap approveLoan(final String approvalDate, final Integer loanID) {
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate)); String loanApprovalCommand = createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID);
String loanApprovalRequest = getApproveLoanAsJSON(approvalDate);
System.out.println("Loan approval command:" + loanApprovalCommand);
System.out.println("Loan approval request:" + loanApprovalRequest);
return performLoanTransaction(loanApprovalCommand, loanApprovalRequest);
} }
public HashMap approveLoanWithApproveAmount(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount, final Integer loanID, public HashMap approveLoanWithApproveAmount(final String approvalDate, final String expectedDisbursementDate,
List<HashMap> tranches) { final String approvalAmount, final Integer loanID, List<HashMap> tranches) {
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches)); getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches));
} }
public List<HashMap<String, Object>> approveLoanForTranches(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount, final Integer loanID, public List<HashMap<String, Object>> approveLoanForTranches(final String approvalDate, final String expectedDisbursementDate,
List<HashMap> tranches, final String responseAttribute) { final String approvalAmount, final Integer loanID, List<HashMap> tranches, final String responseAttribute) {
return (List<HashMap<String, Object>>) performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), return (List<HashMap<String, Object>>) performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches), responseAttribute); getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches), responseAttribute);
} }
@@ -36,7 +36,6 @@ public class JournalEntryData {
private final BigDecimal amount; private final BigDecimal amount;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final CurrencyData currency; private final CurrencyData currency;
@SuppressWarnings("unused")
private final String transactionId; private final String transactionId;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Boolean manualEntry; private final Boolean manualEntry;
@@ -25,7 +25,6 @@ public class CommandWrapperBuilder {
private String transactionId; private String transactionId;
private Long productId; private Long productId;
private Long templateId; private Long templateId;
private Long tellerId;
public CommandWrapper build() { public CommandWrapper build() {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName,
@@ -62,11 +61,6 @@ public class CommandWrapperBuilder {
return this; return this;
} }
public CommandWrapperBuilder withTellerId(final Long withTellerId) {
this.tellerId = withTellerId;
return this;
}
public CommandWrapperBuilder withJson(final String withJson) { public CommandWrapperBuilder withJson(final String withJson) {
this.json = withJson; this.json = withJson;
return this; return this;
@@ -14,7 +14,6 @@ public class CodeValueData implements Serializable {
private final Long id; private final Long id;
@SuppressWarnings("unused")
private final String name; private final String name;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -74,7 +74,6 @@ import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationDateExce
import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeDeleted; import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeDeleted;
import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeModified; import org.mifosplatform.portfolio.loanaccount.exception.LoanApplicationNotInSubmittedAndPendingApprovalStateCannotBeModified;
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException; import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
import org.mifosplatform.portfolio.loanaccount.exception.MultiDisbursementDataRequiredException;
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator; import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.AprCalculator;
import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.LoanScheduleModel; import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.LoanScheduleModel;
import org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler; import org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler;
@@ -140,7 +139,6 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
private final ConfigurationDomainService configurationDomainService; private final ConfigurationDomainService configurationDomainService;
private final LoanScheduleAssembler loanScheduleAssembler; private final LoanScheduleAssembler loanScheduleAssembler;
@Autowired @Autowired
public LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FromJsonHelper fromJsonHelper, public LoanApplicationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final FromJsonHelper fromJsonHelper,
final LoanApplicationTransitionApiJsonValidator loanApplicationTransitionApiJsonValidator, final LoanApplicationTransitionApiJsonValidator loanApplicationTransitionApiJsonValidator,
@@ -746,15 +744,11 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan"); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
final JsonArray disbursementDataArray = command.arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName);
if(disbursementDataArray == null || disbursementDataArray.size() == 0){
final String errorMessage = "For this loan product, disbursement details must be provided";
throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage);
}
final BigDecimal principal = this.fromJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element); final BigDecimal principal = this.fromJsonHelper.extractBigDecimalWithLocaleNamed("approvedLoanAmount", element);
fromApiJsonDeserializer.validateLoanMultiDisbursementdate(element, baseDataValidator, expectedDisbursementDate, principal); fromApiJsonDeserializer.validateLoanMultiDisbursementdate(element, baseDataValidator, expectedDisbursementDate, principal);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
} }
@Transactional @Transactional
@Override @Override
public CommandProcessingResult approveApplication(final Long loanId, final JsonCommand command) { public CommandProcessingResult approveApplication(final Long loanId, final JsonCommand command) {
@@ -786,8 +780,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
this.loanScheduleAssembler.validateDisbursementDateWithMeetingDates(expectedDisbursementDate, calendar); this.loanScheduleAssembler.validateDisbursementDateWithMeetingDates(expectedDisbursementDate, calendar);
} }
final Map<String, Object> changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray, defaultLoanLifecycleStateMachine()); final Map<String, Object> changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray,
defaultLoanLifecycleStateMachine());
if (!changes.isEmpty()) { if (!changes.isEmpty()) {
@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil;
import org.mifosplatform.template.domain.Template; import org.mifosplatform.template.domain.Template;
import org.mifosplatform.template.domain.TemplateFunctions; import org.mifosplatform.template.domain.TemplateFunctions;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
@@ -49,19 +48,15 @@ public class TemplateMergeService {
this.authToken = authToken; this.authToken = authToken;
} }
public String compile(final Template template, public String compile(final Template template, final Map<String, Object> scopes) throws MalformedURLException, IOException {
final Map<String, Object> scopes) throws MalformedURLException,
IOException {
this.scopes = scopes; this.scopes = scopes;
this.scopes.put("static", new TemplateFunctions()); this.scopes.put("static", new TemplateFunctions());
final MustacheFactory mf = new DefaultMustacheFactory(); final MustacheFactory mf = new DefaultMustacheFactory();
final Mustache mustache = mf.compile( final Mustache mustache = mf.compile(new StringReader(template.getText()), template.getName());
new StringReader(template.getText()), template.getName());
final Map<String, Object> mappers = getCompiledMapFromMappers(template final Map<String, Object> mappers = getCompiledMapFromMappers(template.getMappersAsMap());
.getMappersAsMap());
this.scopes.putAll(mappers); this.scopes.putAll(mappers);
final StringWriter stringWriter = new StringWriter(); final StringWriter stringWriter = new StringWriter();
@@ -70,16 +65,14 @@ public class TemplateMergeService {
return stringWriter.toString(); return stringWriter.toString();
} }
private Map<String, Object> getCompiledMapFromMappers( private Map<String, Object> getCompiledMapFromMappers(final Map<String, String> data) {
final Map<String, String> data) {
final MustacheFactory mf = new DefaultMustacheFactory(); final MustacheFactory mf = new DefaultMustacheFactory();
if (data != null) { if (data != null) {
for (final Map.Entry<String, String> entry : data.entrySet()) { for (final Map.Entry<String, String> entry : data.entrySet()) {
final Mustache mappersMustache = mf.compile(new StringReader( final Mustache mappersMustache = mf.compile(new StringReader(entry.getValue()), "");
entry.getValue()), "");
final StringWriter stringWriter = new StringWriter(); final StringWriter stringWriter = new StringWriter();
mappersMustache.execute(stringWriter, this.scopes); mappersMustache.execute(stringWriter, this.scopes);
@@ -100,13 +93,11 @@ public class TemplateMergeService {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Map<String, Object> getMapFromUrl(final String url) private Map<String, Object> getMapFromUrl(final String url) throws MalformedURLException, IOException {
throws MalformedURLException, IOException {
final HttpURLConnection connection = getConnection(url); final HttpURLConnection connection = getConnection(url);
final String response = getStringFromInputStream(connection final String response = getStringFromInputStream(connection.getInputStream());
.getInputStream());
HashMap<String, Object> result = new HashMap<>(); HashMap<String, Object> result = new HashMap<>();
if (connection.getContentType().equals("text/plain")) { if (connection.getContentType().equals("text/plain")) {
result.put("src", response); result.put("src", response);
@@ -119,17 +110,14 @@ public class TemplateMergeService {
private HttpURLConnection getConnection(final String url) { private HttpURLConnection getConnection(final String url) {
if (this.authToken == null) { if (this.authToken == null) {
final String name = SecurityContextHolder.getContext() final String name = SecurityContextHolder.getContext().getAuthentication().getName();
.getAuthentication().getName(); final String password = SecurityContextHolder.getContext().getAuthentication().getCredentials().toString();
final String password = SecurityContextHolder.getContext()
.getAuthentication().getCredentials().toString();
Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(new Authenticator() {
@Override @Override
protected PasswordAuthentication getPasswordAuthentication() { protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(name, password return new PasswordAuthentication(name, password.toCharArray());
.toCharArray());
} }
}); });
} }
@@ -138,8 +126,7 @@ public class TemplateMergeService {
try { try {
connection = (HttpURLConnection) new URL(url).openConnection(); connection = (HttpURLConnection) new URL(url).openConnection();
if (this.authToken != null) { if (this.authToken != null) {
connection.setRequestProperty("Authorization", "Basic " connection.setRequestProperty("Authorization", "Basic " + this.authToken);
+ this.authToken);
} }
TrustModifier.relaxHostChecking(connection); TrustModifier.relaxHostChecking(connection);
@@ -0,0 +1,2 @@
INSERT INTO `job` (`name`, `display_name`, `cron_expression`, `create_time`) VALUES ('Generate Mandatory Savings Schedule', 'Generate Mandatory Savings Schedule', '0 5 0 1/1 * ? *', now());