Jeth01
asked on
How to use different application context for JUnit versus regular execution
Hi,
I have some mock DAOs that I created for some JUnits. I have them autowired with a separate application context file. (They are in a different package and I'm using the component scan) They just return dummy objects instead of fetching from the database. The regular DAOs are through hibernate.
My problem is, I can't figure out how to tell Spring to use that file when running JUnits, and to use the regular XML file otherwise. I want the JUnits to run with the mock DAOs, so we don't need a DB for those. But then when running the application normally, use the real DAOs.
I am fairly new to Spring so this is all a learning experience for me. Any help would be appreciated. Thanks.
One other thing -- I have them in a separate file because they are the same names as the regular DAOs, so that nothing else has to change. But if there is a way to tell Spring to only load the mock ones, or to only use the mock ones for JUnit, then I don't need the separate file.
I have some mock DAOs that I created for some JUnits. I have them autowired with a separate application context file. (They are in a different package and I'm using the component scan) They just return dummy objects instead of fetching from the database. The regular DAOs are through hibernate.
My problem is, I can't figure out how to tell Spring to use that file when running JUnits, and to use the regular XML file otherwise. I want the JUnits to run with the mock DAOs, so we don't need a DB for those. But then when running the application normally, use the real DAOs.
I am fairly new to Spring so this is all a learning experience for me. Any help would be appreciated. Thanks.
One other thing -- I have them in a separate file because they are the same names as the regular DAOs, so that nothing else has to change. But if there is a way to tell Spring to only load the mock ones, or to only use the mock ones for JUnit, then I don't need the separate file.
ASKER
Ok, I thought about that. But where would I put it? We just have our Spring Dispatcher Servlet defined in the web.xml, so then that picks up the application context. Could I just overwrite the one that is loaded after the fact? We are using GWT, so I'm not sure where to put that. I guess in onModuleLoad()? Would that work?
Thanks!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If this doesn't work
use String[]
--
Thanks
Subin Sugunan
http://www.subinsugunan.com/
More spring posts
ClassPathXmlApplicationContext(
“application-config.xml”, “test-infrastructure-config.xml” );
use String[]
ClassPathXmlApplicationContext(new String[] {
“application-config.xml”, “test-infrastructure-config.xml” });
--
Thanks
Subin Sugunan
http://www.subinsugunan.com/
More spring posts
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
E.g.
public ApplicationContext getApplicationContext(Stri
ApplicationContext context = null;
if("JUnit".equalsIgnoreCas
context = <load from mock DAO context file>
}else{
context = <load from DB DAO context file>
}
return context;
}