开发者

Using MockRoundtrip in Stripes with Guice

开发者 https://www.devze.com 2023-03-12 14:49 出处:网络
I\'ve recently introduced Guice into my ActionBeans, where previously the actionbean had its data access layer implementation hardcoded.

I've recently introduced Guice into my ActionBeans, where previously the actionbean had its data access layer implementation hardcoded.

I have an integration test like this:

MockServletContext context = TestHelper.getServletContext();
MockRoundtrip trip = new MockRoundtrip(context, LoginActionBean.class);


trip.setParameter("authenticate", "Login");
trip.setParameter("username", "testuser2");
trip.setParameter("password", "testuser2pass");
trip.setParame开发者_运维知识库ter("targetUrl", "Activity.action?jobId=1");
trip.execute();

LoginActionBean bean = trip.getActionBean(LoginActionBean.class);

Now that I'm using Guice, I can't find a way to inject the dependencies into the LoginActionBean, since I never actually instantiate it myself.

How can I tell guice to inject the dependencies into this class?


You will need to configure the MockServletContext with a Guice configuration, like you have in your web.xml (probably in your TestHelper class getServletContext() method).

0

精彩评论

暂无评论...
验证码 换一张
取 消