On Wed, May 13, 2009 at 3:00 PM, Kawczynski, David
<[email protected]> wrote:
> I'm certainly no magician, but was still able to do this.
>
> If your action depends on session info, implement SessionAware
> and provide it with a Map of name-value pairs in the testcase.
>
> If your action depends on request info, implement RequestAware
> and provide it with a Map of name-value pairs in the testcase.
>
> If everything is spring-driven, you can start Spring without a
> web container via ClassPathXmlApplicationContext:
>
> AbstractApplicationContext springContext =
> new ClassPathXmlApplicationContext("applicationContext.xml");
>
> springContext.registerShutdownHook();
>
> SomeAction someAction =
> (SomeAction)springContext.getBean("someAction");
Or even better, you can tell JUnit to run your test with Spring's
JUnit runner... Here's what I do -
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:applicationContext-test.xml"})
public class SecurityManagerImplTest {
@Autowired
private SecurityManager<AppUserEntity,AppRoleEntity> sm ;
@Autowired @Qualifier("appUserDao")
private GenericDao<AppUserEntity,String> appUserDao ;
@Autowired @Qualifier("appRoleDao")
private GenericDao<AppRoleEntity,String> appRoleDao;
@Test public void testSomeFunctionality() {
Then, you can just mark classes with @Test and you don't have to worry
about directly loading a spring application context. The properties
annotated with @Autowired will be autowired by type and the @Qualifier
let's you specify a bean-name if autowiring by type causes trouble.
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]