[Mifos-developer] Testing time-dependent scenarios

3 views
Skip to first unread message

Keith Pierce

unread,
Jun 10, 2008, 9:42:35 AM6/10/08
to Developer
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

Adam Monsen

unread,
Jun 10, 2008, 12:12:40 PM6/10/08
to Mifos Developer Discussions
On Tue, 2008-06-10 at 09:42 -0400, Keith Pierce wrote:
> 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?

I agree with you as far as the long-term solution is concerned. I feel
like any of the "quick" fixes we might try (such as direct object
manipulation, as you mentioned) will still take significant time, and
will give us more code to undo later.

Perhaps it would be worth starting small, but proper:
* set up a simple time wrapper
* write light documentation for using the new time wrapper
* use the wrapper only as needed at first; refactor incrementally

http://mifos.org/developers/wiki/ImproveTimeHandling

--
Adam Monsen


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

Reply all
Reply to author
Forward
0 new messages