You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by juicetime <mz...@gmail.com> on 2012/05/27 15:43:52 UTC
JNDI problem with an EJB that's a subclass of another EJB
Hello
We have a class having some of its dependencies @Injected. The component
test of this class resides in another project where all the injected
dependencies are mocked like so:
- the mock extends the original class so that they share the same type
- the mocks are marked as @Alternatives and configured for injection in the
component test's beans.xml
For simple POJOs, this approach works fine, but for EJBs it doesn't. I have
a stateless SB that I mock by extension. When I start the test and the
container starts up, I see the EJBs being registered in JNDI one after the
other, including the EJB that is mocked, this is fine so far. But then it
seems that when the container initializes the mock, an attempt is made to
register the same (original) EJB once again in JNDI, the log message says:
<pre>
Jndi name could not be bound; it may be taken by another ejb.
Jndi(name=openejb/Deployment/ccmAdapter/com.juicetime.ccmservice.CmServiceAdapter!LocalBeanHome)
</pre>
It doesn't seem to matter if I explicitly set the mock as a stateless bean
or not, and if I do, it doesn't matter how I configure the name and
mappedName properties. It seems that after creating and initializing the
subclass (the mock), an attempt is made to once again register the original
class in the naming context.
In the EJB spec, I didn't find much restrictions when it come to inheritance
between EJBs, so I guess a lot is left for the container developers to
decide? So I guess my question is this: is this the way this is supposed to
work? Am I not supposed to extend from an EJB?
I was able to work around this by not having a mock EJB extend the original
one, but instead extracting an interface from the original EJB and have the
mock implement it. I guess another way to try to work around this would be
to somehow have the container skip initializing the original bean. But I'm
still curious as to why the solution we thought would be the simplest and
easiest to maintain won't work.
Thanks for the answer in advance
--
View this message in context: http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: JNDI problem with an EJB that's a subclass of another EJB
Posted by juicetime <mz...@gmail.com>.
Nope, seems it's not that simple after all. If I just extend from an EJB,
both work fine. There's something special going on in that piece of code
I'm having problems with, I'll try to figure out what it is and post it.
Thanks
2012/5/27 Romain Manni-Bucau [via OpenEJB] <
ml-node+s979440n4655133h82@n4.nabble.com>
> Hmm, inheritance should work.
>
> If you can share a project (maven or ant is possible) thats the best
>
> - Romain
> Le 27 mai 2012 18:52, "juicetime" <[hidden email]<http://user/SendEmail.jtp?type=node&node=4655133&i=0>>
> a écrit :
>
> > Hi
> >
> > By mock by extension I mean that I subclass my original class in order
> to
> > be
> > able to mock it - and by mock I mean manually, as in rewriting its
> methods
> > to suit the needs of a component test.
> >
> > So what it comes down to is this: it seems that an EJB and its subclass
> can
> > not coexist, because it seems that OpenEJB attempts to register the
> parent
> > EJB again in JNDI when processing its subclass.
> >
> > And my question is whether this is a planned behaviour or not.
> >
> > I'm happy to recreate a separate project to illustrate this behaviour if
> my
> > description is not clear enough.
> >
> > Thanks very much
> >
> > --
> > View this message in context:
> >
> http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127p4655130.html
>
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127p4655133.html
> To unsubscribe from JNDI problem with an EJB that's a subclass of another
> EJB, click here<http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4655127&code=bXoubGlzdGFAZ21haWwuY29tfDQ2NTUxMjd8LTg1MDg0ODA4Nw==>
> .
> NAML<http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127p4655160.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: JNDI problem with an EJB that's a subclass of another EJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm, inheritance should work.
If you can share a project (maven or ant is possible) thats the best
- Romain
Le 27 mai 2012 18:52, "juicetime" <mz...@gmail.com> a écrit :
> Hi
>
> By mock by extension I mean that I subclass my original class in order to
> be
> able to mock it - and by mock I mean manually, as in rewriting its methods
> to suit the needs of a component test.
>
> So what it comes down to is this: it seems that an EJB and its subclass can
> not coexist, because it seems that OpenEJB attempts to register the parent
> EJB again in JNDI when processing its subclass.
>
> And my question is whether this is a planned behaviour or not.
>
> I'm happy to recreate a separate project to illustrate this behaviour if my
> description is not clear enough.
>
> Thanks very much
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127p4655130.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: JNDI problem with an EJB that's a subclass of another EJB
Posted by juicetime <mz...@gmail.com>.
Hi
By mock by extension I mean that I subclass my original class in order to be
able to mock it - and by mock I mean manually, as in rewriting its methods
to suit the needs of a component test.
So what it comes down to is this: it seems that an EJB and its subclass can
not coexist, because it seems that OpenEJB attempts to register the parent
EJB again in JNDI when processing its subclass.
And my question is whether this is a planned behaviour or not.
I'm happy to recreate a separate project to illustrate this behaviour if my
description is not clear enough.
Thanks very much
--
View this message in context: http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127p4655130.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: JNDI problem with an EJB that's a subclass of another EJB
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
What do you mean by "mock by extension"?
Typically vetoing an ejb is not defined.
- Romain
Le 27 mai 2012 15:44, "juicetime" <mz...@gmail.com> a écrit :
> Hello
>
> We have a class having some of its dependencies @Injected. The component
> test of this class resides in another project where all the injected
> dependencies are mocked like so:
>
> - the mock extends the original class so that they share the same type
> - the mocks are marked as @Alternatives and configured for injection in the
> component test's beans.xml
>
> For simple POJOs, this approach works fine, but for EJBs it doesn't. I have
> a stateless SB that I mock by extension. When I start the test and the
> container starts up, I see the EJBs being registered in JNDI one after the
> other, including the EJB that is mocked, this is fine so far. But then it
> seems that when the container initializes the mock, an attempt is made to
> register the same (original) EJB once again in JNDI, the log message says:
>
> <pre>
> Jndi name could not be bound; it may be taken by another ejb.
>
> Jndi(name=openejb/Deployment/ccmAdapter/com.juicetime.ccmservice.CmServiceAdapter!LocalBeanHome)
> </pre>
>
> It doesn't seem to matter if I explicitly set the mock as a stateless bean
> or not, and if I do, it doesn't matter how I configure the name and
> mappedName properties. It seems that after creating and initializing the
> subclass (the mock), an attempt is made to once again register the original
> class in the naming context.
>
> In the EJB spec, I didn't find much restrictions when it come to
> inheritance
> between EJBs, so I guess a lot is left for the container developers to
> decide? So I guess my question is this: is this the way this is supposed to
> work? Am I not supposed to extend from an EJB?
>
> I was able to work around this by not having a mock EJB extend the original
> one, but instead extracting an interface from the original EJB and have the
> mock implement it. I guess another way to try to work around this would be
> to somehow have the container skip initializing the original bean. But I'm
> still curious as to why the solution we thought would be the simplest and
> easiest to maintain won't work.
>
> Thanks for the answer in advance
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JNDI-problem-with-an-EJB-that-s-a-subclass-of-another-EJB-tp4655127.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>