Hi Stripes Users,
Currently I want to test an action bean. It gets a Spring bean (service class)
injected via the @SpringBean annotation. Now I want this service to be mocked
with Mockito. My current solution works like this:
I have an interface LoginService and a real implementation
Hi Marcus,
Not sure I understand what you're trying to do...
Why do you have to wrap the mock ?
Cheers
Remi
2011/2/22 Marcus Kraßmann m...@syn-online.de
Hi Stripes Users,
Currently I want to test an action bean. It gets a Spring bean (service
class) injected via the @SpringBean
Hi Remi,
Thanks for your reply. Actually I have to wrap it because MockRoundtrip uses
another Spring ApplicationContext than JUnit itself. Fact is that if I inject
LoginService into JUnit (which is configured to be a singleton instance of
MockitoLoginService), then it is another instance than
Yeah your first attempt makes much more sense than this static field :)
One thing though, what do you mean by injecting into JUnit ?
From what I understood, you want to configure the mock object *prior* to
performing a mock round trip, don't you ?
Cheers
Remi
2011/2/22 Marcus Kraßmann
Btw, what about :
// create the Spring context for our test
ApplicationContext appCtx = createSpringAppCtx()
// play with the mockito bean
LoginService ls = (LoginService)appCtx.getBean(...)
...
// create a mock servlet context, without the Spring context loader
MockServletContext ctx =
Well, my test case looks like this:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class})
@ContextConfiguration(locations = classpath:test-context.xml)
public class
I had no idea you could do this kind of Spring/JUnit integration. Looks
cool. It probably has a way to tell it to use some supplied
ApplicationContext though, instead of creating one itself... Like injecting
the bean factory itself (??? :P)
Cheers
Remi
2011/2/22 Marcus Kraßmann
Hi Remi,
ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEX_ATTRIBUTE,
springContext)
I also had this idea some weeks ago. I cannot surely remember the reason why I
dropped it, but I think that I was not able to convert the ApplicationContext
used by JUnit to a
H, then do it the other way maybe ?
Let Stripes create a real WebApplicationContext (in MockServletContext,
using Spring's loader) and use it before you roundtrip :
// create stripes mock context (loads spring via context listener)
MockServletContext ctx = createMockServletContextWithSpring()
Hi Marcus,
I was testing my action beans as Remi suggested, so it should work.
Currently, I use a custom interceptor and a modified version of
SpringHelper to create/inject mock spring beans into an action bean
automatically.
As it's a little bit tricky to explain, I would create a simple
Hi Iwao,
Without a modified SpringHelper the suggested way fails with an
IllegalStateException (Context attribute is not of type
WebApplicationContext). I guess I know how you solved this issue, but IMHO
that requires more Stripes related changes than my current way (a simple
getBean method
11 matches
Mail list logo