You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by zeddius <av...@gmail.com> on 2013/07/03 10:20:35 UTC

@Alternative for observer method

Hi,

While trying to create a mock bean for a bean that declares both producer
method and an observer method.





Producer method seems to work fine however the observer method is invoked
for both bean regardless if alternative is enable or not. I've tried
@Specializes but it completely overrides OneBean and producer alternative
doesn't work in this case.

What is the correct way to mock observer method if any?



--
View this message in context: http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @Alternative for observer method

Posted by zeddius <av...@gmail.com>.
Thanks, this make sense but will be not a beautiful decision. I will have to
introduce extra abstractions to mock what is happening inside observer
method even if there is a single line of code. 

I wonder why that couldn't make @Alternative to hide observer methods...



--
View this message in context: http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084p4664089.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @Alternative for observer method

Posted by Romain Manni-Bucau <rm...@gmail.com>.
you can put it elsewhere or just not redefine it

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/7/3 zeddius <av...@gmail.com>

> In this case the observer method will still be invoked twice. First time
> for
> OneBean and second time for MockBean.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084p4664086.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: @Alternative for observer method

Posted by zeddius <av...@gmail.com>.
This only could help me if @Alternative continue to work in this case. But
what happens if I annotate my MockBean with both @Alternative and
@Specializes is that if alternative is disabled in beans.xml the OneBean is
still not visible and MockBean is not visible (at least producer method).



--
View this message in context: http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084p4664090.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @Alternative for observer method

Posted by Mark Struberg <st...@yahoo.de>.
Works as designed from the spec perspective.
What you could do is to use @Specializes which would 'disable' your original class as CDI Bean<?>


LieGrue,
strub




----- Original Message -----
From: zeddius <av...@gmail.com>
To: users@openejb.apache.org
Cc: 
Sent: Wednesday, 3 July 2013, 10:34
Subject: Re: @Alternative for observer method

In this case the observer method will still be invoked twice. First time for
OneBean and second time for MockBean.



--
View this message in context: http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084p4664086.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: @Alternative for observer method

Posted by zeddius <av...@gmail.com>.
In this case the observer method will still be invoked twice. First time for
OneBean and second time for MockBean.



--
View this message in context: http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084p4664086.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @Alternative for observer method

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

i'd mock a bean/service invoked in the observer rather than the observer
itself

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/7/3 zeddius <av...@gmail.com>

> Hi,
>
> While trying to create a mock bean for a bean that declares both producer
> method and an observer method.
>
>
>
>
>
> Producer method seems to work fine however the observer method is invoked
> for both bean regardless if alternative is enable or not. I've tried
> @Specializes but it completely overrides OneBean and producer alternative
> doesn't work in this case.
>
> What is the correct way to mock observer method if any?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Alternative-for-observer-method-tp4664084.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>