I am hoping that
someone has some insight into how to do this in MifOS.
I am testing that
new rounding rules apply correctly when a loan is redone and the loan schedule
is re-generated. In order to unit-test the code I planned to carry out these
steps, assuming that manipulating dates would be doable:
1. Create a weekly
loan on the date three weeks ago, coupled to a weekly meeting that met on that
date.
2. Advance the date
a week and disburse the loan.
3. Advance the date
a week and make a payment.
4. Advance the date
a few days and redo the loan.
5. Verify that the
redone loan's payment schedule matches the original.
Unfortunately, the
application is tightly coupled to external system time, making it impossible to
manipulate what "today" is. For example, when trying to create an instance of
LoanOfferingBO with which to create the original loan, the start date of the
offering must be today or later, otherwise its constructor throws an exception.
If an instance of LoanOffering BO is created "today", it cannot be used to
create a loan with a prior disbursement date.
Noticing that
LoanOfferingBO's date verification occurs in a protected method validateStartDateAgainstCurrentDate(). I tried subclassing LoanOfferingBO
and overriding this method to force it to accept any date. But that failed when
hibernate threw a MappingException: Unknown Entity:
org.mifos.application.productdefinition.business.LoanOfferingBOForTesting (the
subclass).
So I'm stuck. One
option might be to create objects "today", then directly manipulate instance
variables in those objects to force dates into the past. That feels quite
dangerous as it may put the objects into an inconsistent state with
unpredictable behavior.
The obvious
long-term solution is to refactor the application so that it accesses time and
date information via wrapper classes. The wrapper classes default to accessing
environment classes (Date, Calendar), but can be configured to access mock
classes that force dates.
However, that is not
possible in the short run. Any suggestions?
Keith
Pierce