tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John D. Ament" <>
Subject RE: Howto exchange bean implementation for testing?
Date Thu, 18 Feb 2010 19:20:39 GMT
Not sure if it is an option, but if you can use weld/cdi, it's designed for this kind of use
case.  Take a look at their "alternatives"

Stephen Davidson <> wrote:

>Currently looking into Aspect Oriented programming for another issue,
>but maybe
> might
>be useful in this case?  You might be able to set up something (a
>test-only aspect) to do an injection post-startup, but pre-call.
>Just an idea.
>-----Original Message-----
>From: Per Newgro [] 
>Sent: Thursday, February 18, 2010 3:01 AM
>Subject: Re: Howto exchange bean implementation for testing?
>Hi Stephen,
>the splitting of both implementations in src/main/java and src/test/java
>is clear.
>But the problem is how can i load the TestSessionManager instead of 
>in my tests. Both implement SessionManagerLocal which is used by the
>I think they get both deployed, because they in the same project 
>(different source folders).
>So how can i guarantee that the tests use the TestSessionManager?
>Ehm, this is much the same to your P.S. :-) But howto configure openejb?
>Is there a property / wiki
>or whatever. I don't know which search term to use (I did already but 
>didn't find anything related)
>> I would refactor how you package up these things.
>> You would put the SessionManagerImpl in one module
>> You can then have SessionManagerTestImpl (because Test*.java and
>> will be picked up by surefire as JUnit test cases) in src/test/java of
>> module which uses SessionManager, and do not depend on the module with
>> real SessionManagerImpl...
>> Then finally when you package everything up, as SessionManagerTestImpl
>is in
>> src/test/java then there is no fear of it being in your final EAR
>> -Stephen
>> P.S.
>> If you have more confidence you can configure openejb to wire up
>> SessionManagerTestImpl for the test cases where you need it and use
>> SessionManagerImpl for the test cases where you don't... you'd still
>> SessionManagerTestImpl in src/test/java, but you'd be relying on your
>> configuration of openejb to ensure that your test cases get the
>> SessionManager injected per their requirements (the advantage is that
>> wouldn't end up with an EJB module per EJB ;-) )
>> On 18 February 2010 08:13, Per Newgro<>  wrote:
>>> Hi *,
>>> this is not realy a openejb question but anyway.
>>> I have following scenario. After login a "business"-session will be
>>> for userId
>>> with language and current date in it (has nothing to do with
>>> or so).
>>> The session is created by singleton bean SessionManager which is
>>> the session
>>> in a map. Internally the session manager sets the current date (new
>>> Date()).
>>> For testing issues i would like to preset the current date. But
>because the
>>> session times
>>> out after date change i can't manipulate it. So a setter for current
>>> is impossible.
>>> What i would like to do is to exchange the session manager
>>> by a
>>> test session manager implementation in which i could implement an
>>> appripriate behavior
>>> for test.
>>> So how can i guarantee that my tests are using the TestSessionManager
>>> the business
>>> client the SessionManager? Is there something like
>>> "IgnoreBeanXYWhileDeployForMyTest"?
>>> Cheers
>>> Per
>    *
View raw message