You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Michiel De Smet <md...@gmail.com> on 2014/01/14 17:12:54 UTC
How to rebind
I want to rebind some EJB's to their mock counterparts after initializing
the initial context trough class path scanning.
I tried following but this did not work:
@LocalClient
class MyTestClass() {
...
initialContext = new InitialContext(properties);
IFoo foo = EasyMock.createNiceMock(IFoo.class);
...
initialContext.rebind("FooImplLocal", foo);
initialContext.bind("inject", this);
...
}
The binding succeeds without a NamingException but however the original EJB
is injected in the MyTestClass...
Any ideas?
Re: How to rebind
Posted by Romain Manni-Bucau <rm...@gmail.com>.
just scan your mock or provide a fallback injector if you don't lookup
directly the class but only inject it through @EJB. BTW using
arquillian make it easier:
http://svn.apache.org/repos/asf/tomee/tomee/trunk/arquillian/arquillian-openejb-embedded-4/src/test/java/org/apache/openejb/arquillian/openejb/ArquillianAndMockitoTest.java
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014/1/14 Michiel De Smet <md...@gmail.com>:
> I find a result for ctx.lookup("openejb/localFooImplLocal"). Now I want to
> rebind that to my mocked class. How would I do that?
>
> If I don't scan that class I would still have to bind it right?
>
>
> On Tue, Jan 14, 2014 at 5:20 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
>> binding doesn't use this context, and not sure it will use this name
>> (well no in fact). The context can be accessed through
>> SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext()
>> btw.
>>
>> But not using scanning would make it smoother
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014/1/14 Michiel De Smet <md...@gmail.com>:
>> > I want to rebind some EJB's to their mock counterparts after initializing
>> > the initial context trough class path scanning.
>> >
>> > I tried following but this did not work:
>> > @LocalClient
>> > class MyTestClass() {
>> > ...
>> > initialContext = new InitialContext(properties);
>> > IFoo foo = EasyMock.createNiceMock(IFoo.class);
>> > ...
>> > initialContext.rebind("FooImplLocal", foo);
>> > initialContext.bind("inject", this);
>> > ...
>> > }
>> >
>> > The binding succeeds without a NamingException but however the original
>> EJB
>> > is injected in the MyTestClass...
>> >
>> >
>> > Any ideas?
>>
Re: How to rebind
Posted by Michiel De Smet <md...@gmail.com>.
I find a result for ctx.lookup("openejb/localFooImplLocal"). Now I want to
rebind that to my mocked class. How would I do that?
If I don't scan that class I would still have to bind it right?
On Tue, Jan 14, 2014 at 5:20 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:
> binding doesn't use this context, and not sure it will use this name
> (well no in fact). The context can be accessed through
> SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext()
> btw.
>
> But not using scanning would make it smoother
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/14 Michiel De Smet <md...@gmail.com>:
> > I want to rebind some EJB's to their mock counterparts after initializing
> > the initial context trough class path scanning.
> >
> > I tried following but this did not work:
> > @LocalClient
> > class MyTestClass() {
> > ...
> > initialContext = new InitialContext(properties);
> > IFoo foo = EasyMock.createNiceMock(IFoo.class);
> > ...
> > initialContext.rebind("FooImplLocal", foo);
> > initialContext.bind("inject", this);
> > ...
> > }
> >
> > The binding succeeds without a NamingException but however the original
> EJB
> > is injected in the MyTestClass...
> >
> >
> > Any ideas?
>
Re: How to rebind
Posted by Romain Manni-Bucau <rm...@gmail.com>.
binding doesn't use this context, and not sure it will use this name
(well no in fact). The context can be accessed through
SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext()
btw.
But not using scanning would make it smoother
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014/1/14 Michiel De Smet <md...@gmail.com>:
> I want to rebind some EJB's to their mock counterparts after initializing
> the initial context trough class path scanning.
>
> I tried following but this did not work:
> @LocalClient
> class MyTestClass() {
> ...
> initialContext = new InitialContext(properties);
> IFoo foo = EasyMock.createNiceMock(IFoo.class);
> ...
> initialContext.rebind("FooImplLocal", foo);
> initialContext.bind("inject", this);
> ...
> }
>
> The binding succeeds without a NamingException but however the original EJB
> is injected in the MyTestClass...
>
>
> Any ideas?