users
[Top] [All Lists]

Re: [cinjug-users] help: How to create virtual current system date for J

To: Keshav Kode <keshav.kode@xxxxxxxxx>, users@xxxxxxxxxx
Subject: Re: [cinjug-users] help: How to create virtual current system date for J2EE applications hosted under the same WAS?
From: "Jonathan A. Chase" <chaseja@xxxxxxxxxx>
Date: Tue, 22 Mar 2005 15:52:26 -0500
Delivered-to: mailing list users@cinjug.org
In-reply-to: <dff5562005032114026e0e0ddb@mail.gmail.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Organization: Miami University DARS Project
References: <dff5562005032114026e0e0ddb@mail.gmail.com>
User-agent: Opera7.23/Win32 M2 build 3227
We had a similar problem. It sounds like we did the same thing you're thinking about:

1) we defined an interface, say, DateProvider, with one method, getDate()
2) our default implementation of the interface, DefaultDateProvider, looked like:
/** return the real date, according to the OS */
public Date getDate() {
return new java.util.Date();
}
3) the implementation we used for (junit) testing, AssignableDateProvider, looked like:
/** saves a date passed in by the user */
public AssignableDateProvider(Date d) {
this.date = d;
}
/** return whatever date you set in the constructor */
public Date getDate() {
return this.date;
}


In our test code we used the AssignableDateProvider implementation, in production we used the DefaultDateProvider implementation.

So you could either use a sigleton like you suggested with the above strategy, or better yet, make the DateProvider an attribute of whatever class it is that's using it, and make sure the class uses a DefaultDateProvider by default (say, set in the constructor). Then, for testing, call yourObject.setDateProvider(new AssignableDateProvider(your date)) and you should be good to go. With the latter approach, you don't run into any of the nastiness of singletons:D.

HTH,
Jon

On Mon, 21 Mar 2005 16:02:51 -0600, Keshav Kode <keshav.kode@xxxxxxxxx> wrote:

Hello Cinjuggers,

We are working with a client who has multiple J2EE projects under WAS.
They want to be able to do functional testing of those applications
with different "Current SYSTEM_DATE" then the actual SYSTEM_DATE for
some functionality. To explain this lets say today (i.e. on
03/21/2005) Tester A wants to test Application APP_A with current
system date as "01/01/2005" a the same time Tester B wants to test
APP_B with system date as "02/24/2003" in same WAS test environment.

To accomplish it right now they are modifying the SYSTEM_DATE at OS
level and testing their applications. But it is causing lot of problem
to the other application on that server. Also this does not allow them
to test multiple applications at same time with different system
dates.

To resolve the problem we are suggesting them to add abstraction
layer, which based on Production or test environment will return
actual system date or configured test SYSTEM_DATE. All the application
will have to use this layer (may be Singleton object) to get current
system time. This singleton object will also save different current
time for different applications so that they can be tested separately.

Is this the right way to solve this problem? Is there are other option
available with minimal performance impact? Has anyone faced similar
problem earlier? Any pointer will be greatly appreciated.

Thanks a lot in advance,
Keshav.

---------
You may unsubscribe from this mailing list
by sending a blank email addressed to:
users-unsubscribe@xxxxxxxxxx

--
Find additional help by sending a blank email
addressed to:
users-help@xxxxxxxxxx




-- Jonathan A. Chase Miami University DARS Project http://www.dars.muohio.edu chaseja@xxxxxxxxxx (513) 529-1401

<Prev in Thread] Current Thread [Next in Thread>