tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John D. Ament" <my.repr...@gmail.com>
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 <stephen.davidson@etcc.com> wrote:

>Currently looking into Aspect Oriented programming for another issue,
>but maybe
>http://www.eclipse.org/aspectj/doc/released/progguide/index.html 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.
>
>-Steve
>
>-----Original Message-----
>From: Per Newgro [mailto:per.newgro@gmx.ch] 
>Sent: Thursday, February 18, 2010 3:01 AM
>To: users@openejb.apache.org
>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 
>BusinessSessionManager
>in my tests. Both implement SessionManagerLocal which is used by the
>beans.
>
>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)
>
>Cheers
>Per
>
>> 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
>*Test.java
>> will be picked up by surefire as JUnit test cases) in src/test/java of
>the
>> module which uses SessionManager, and do not depend on the module with
>the
>> 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
>keep
>> SessionManagerTestImpl in src/test/java, but you'd be relying on your
>> configuration of openejb to ensure that your test cases get the
>correct
>> SessionManager injected per their requirements (the advantage is that
>you
>> wouldn't end up with an EJB module per EJB ;-) )
>>
>> On 18 February 2010 08:13, Per Newgro<per.newgro@gmx.ch>  wrote:
>>
>>    
>>> Hi *,
>>>
>>> this is not realy a openejb question but anyway.
>>>
>>> I have following scenario. After login a "business"-session will be
>created
>>> for userId
>>> with language and current date in it (has nothing to do with
>http-sessions
>>> or so).
>>> The session is created by singleton bean SessionManager which is
>storing
>>> 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
>date
>>> is impossible.
>>>
>>> What i would like to do is to exchange the session manager
>implementation
>>> 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
>and
>>> the business
>>> client the SessionManager? Is there something like
>>> "IgnoreBeanXYWhileDeployForMyTest"?
>>>
>>> Cheers
>>> Per
>>>
>>>      
>>    
>
>    *
>
>
Mime
View raw message