You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Yann Blazart <ya...@bycode.fr> on 2012/08/28 16:19:28 UTC

OpenEJB Mockito unit test

Hi , is there a way to use Mockito instance with Application composer for
unit tests ?

For example here, is there a solution to use the mockito instance for the
EjbJar ? :


> @RunWith(ApplicationComposer.class)
> public class EchoServiceTest {
>
>     @Mock
>     private DummyService dummyService;
>     @EJB
>     private EchoService echoService;
>     @Before
>     public void init() {
>         MockitoAnnotations.initMocks(this);
>     }
>
>     @Module
>     public EjbJar createEjbJar() {
>         EjbJar ejbJar = new EjbJar(this.getClass().getSimpleName());
>         ejbJar.addEnterpriseBean(new StatelessBean(EchoService.class));
> //        ejbJar.addEnterpriseBean(new StatelessBean);
>         return ejbJar;
>     }

Re: OpenEJB Mockito unit test

Posted by Vishwanath Krishnamurthi <to...@gmail.com>.
Zeeman,

'change-jaxws-url' is one such example which uses Arquillian for testing.

Also we have
https://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian/arquillian-tomee-moviefun-example
in the arquillian module. (probably should be moved to examples module)

-Vishwa

On Sat, Sep 15, 2012 at 1:16 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Hmm maybe look for arquillian here
> http://svn.apache.org/repos/asf/openejb/trunk/openejb/examples/
> Le 15 sept. 2012 07:07, "zeeman" <ha...@fastmail.us> a écrit :
>
> > Romain,
> >
> > Is there a simple project with Tomee that has a unit test with Arquillian
> > working?
> > So far I have not been able to find a complete example of an integration
> > test using Tomee.
> >
> >
> >
> > --
> > View this message in context:
> >
> http://openejb.979440.n4.nabble.com/OpenEJB-Mockito-unit-test-tp4657142p4657433.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
> >
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm maybe look for arquillian here
http://svn.apache.org/repos/asf/openejb/trunk/openejb/examples/
Le 15 sept. 2012 07:07, "zeeman" <ha...@fastmail.us> a écrit :

> Romain,
>
> Is there a simple project with Tomee that has a unit test with Arquillian
> working?
> So far I have not been able to find a complete example of an integration
> test using Tomee.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-Mockito-unit-test-tp4657142p4657433.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: OpenEJB Mockito unit test

Posted by zeeman <ha...@fastmail.us>.
Romain, 

Is there a simple project with Tomee that has a unit test with Arquillian
working?
So far I have not been able to find a complete example of an integration
test using Tomee.



--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-Mockito-unit-test-tp4657142p4657433.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

RES: OpenEJB Mockito unit test

Posted by Elton Kuzniewski <el...@softplan.com.br>.
Great Romain! :)

Some weeks ago I worked in that approach.
Your first idea is great because in that way we can isolate the ejb's method
to run a real UnitTest using Mockito API that is a knew and well documented
project.
The only issue that I still see here is about CDI inside the EJB, where we
still without options to mock it directly.
An way that I solved it is using ShrinkWrap to create, in runtime, a package
where I have mocked EJBs that are dependencies (by CDI) from the real EJB
that I'm interested to test.
I need to do some tests here, but  your work is of great value.

About your second news, I didn't use Arquillian Test Runner. Instead this I
created a custom Runner because I had a lot of custom configurations that I
should do before run container.
I just have one thing against, where I'm not able to extends
org.apache.openejb.config.ConfigurationFactory to inject, in run time, a new
declaredApp created by ShrinkWrap.
It would be great too if this class could have protected method where we can
do this (example method List<String> getDeclaredApps()).


Att,

Elton Kuzniewski
Analista de Sup. Desenvolvimento e Arquitetura
CSM, SCJA, SCJP 5, SCWCD 5, SCBCD 5
Pesquisa & Desenvolvimento
Softplan/Poligraph
+ 55 48 3027-8000
www.softplan.com.br


-----Mensagem original-----
De: Romain Manni-Bucau [mailto:rmannibucau@gmail.com] 
Enviada em: terça-feira, 11 de setembro de 2012 10:09
Para: users@openejb.apache.org
Assunto: Re: OpenEJB Mockito unit test

some news:

application composer + mockito:
http://svn.apache.org/repos/asf/openejb/trunk/openejb/utils/openejb-mockito/
src/test/java/org/apache/openejb/mockito/MockitoAndAppComposerTest.java

the idea is to provide a custom injector (for @EJB) and an extension is
automatically discovered for cdi

*and the arquillian version: *
http://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian/arquillian-
openejb-embedded-4/src/test/java/org/apache/openejb/arquillian/openejb/Arqui
llianAndMockitoTest.java

here bean are produces (in static) and mock are automatically injected (but
because of current arquillian lifecycle some werid cases can fail :(...for
them manual mocking is the solution)

it can pby be enhanced but we now have a base ;)
*
*
*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/5 Romain Manni-Bucau <rm...@gmail.com>

> Currently no but should be pretty easy ;)
>
> Not sure i can go further today but the idea is:
> 1) create an fallback injector with a map string/object you can feed
> statically
> 2) implement getvalue method simply getting in the map the key i said
> before
> 3) return an instance in the test class with mockinjector annotation
> 4) when the mock is created put it in the map
> 5) clean the map (optional IMO)
>
> You can test between 4 and 5 ;)
>
> Ps/note: if it was only resources creation the issue we could make them
> lazy
> Le 5 sept. 2012 09:22, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> écrit :
>
> any basic sample to give it a try?
>> Very interesting BTW
>>
>> JLouis
>>
>> 2012/9/5 Romain Manni-Bucau <rm...@gmail.com>
>>
>> > added org.apache.openejb.injection.FallbackPropertyInjector which
should
>> > manage failling injections (so you can inject a mock) and in
application
>> > composer you can return your injector annotating @MockInjector a
method.
>> >
>> > i didnt test too much, was just trying to find a way which doesn't
>> impact
>> > the core in particular from a perf point of view. this one should be
>> fine
>> > for @EJB injections.
>> >
>> > It will probably be reworked a bit but would like to discuss a bit
>> before.
>> >
>> > For mockito the impl could use a map (injection.getTarget().getName() +
>> "/"
>> > + injection.getName() as key, mock as value)
>> >
>> > wdyt?
>> >
>> > *Romain Manni-Bucau*
>> > *Twitter: @rmannibucau*
>> > *Blog: http://rmannibucau.wordpress.com*
>> >
>> >
>> >
>> >
>> > 2012/8/31 Romain Manni-Bucau <rm...@gmail.com>
>> >
>> > > Nothing against it but here is my opinion,
>> > >
>> > > JEE is designed to be testable so no need of any "complicated for
>> > nothing"
>> > > framework.
>> > >
>> > > For me mockito answer to a different need.
>> > >
>> > > For a cdi sample we have an example on trunk using alternatives ans
>> > > stereotypes.
>> > >
>> > > - Romain
>> > > Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a
>> écrit :
>> > >
>> > > I'm agree but tests with arquilian take more time than simple unit
>> tests.
>> > >> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a
>> > >> écrit :
>> > >>
>> > >> > Waiting for Romain's answer, but I guess it will be. Mocking is an
>> old
>> > >> > school solution ;-)
>> > >> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and
>> so
>> > >> on,
>> > >> > it's far easier to get simple integration tests. So the need to
>> really
>> > >> > write unit tests is smaller.
>> > >> >
>> > >> > Just some thoughts.
>> > >> > Romain is currently on holidays, but quite sure he will find a
hack
>> > for
>> > >> you
>> > >> > when he'll be back ;-)
>> > >> >
>> > >> > Jean-Louis
>> > >> >
>> > >> >
>> > >> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
>> > >> >
>> > >> > > Well, in fact I'm not sure to go in the right way.
>> > >> > >
>> > >> > > I wan't to make the demonstration that jee6 can now replace
>> spring.
>> > >> > > One thing very interesting in spring is about that faculty to
>> make
>> > >> > > "unit-test" between real unit-test and integration tests with
>> > >> > > @Configuration. I wanted to make the same thing.
>> > >> > >
>> > >> > > I can reproduce it with cdi-unit for example, but I wan't to use
>> EJB
>> > >> > > 3.1 too (transaction, and security), my research show me the
>> OpenEjb
>> > >> > > stack with the ApplicationComposer runner, this is very cool !
>> > >> > >
>> > >> > > Well to get back to my main subject. In fact that should be very
>> > nice
>> > >> > > to be able to use Mocks from Mockito instead of the instances
>> > produced
>> > >> > > by the container.
>> > >> > >
>> > >> > > Example : I have my business service a Stateless localbean, this
>> one
>> > >> > > use a DAO, same Stateless localbean with no interface. This DAO
>> use
>> > a
>> > >> > > persistence manager. As the DAO has no interface, I cannot
>> replace
>> > his
>> > >> > > implementation in the @Module by writing a mock by hand, the
>> simple
>> > >> > > extended class do not work. The problem is that this dao
>> absolutely
>> > >> > > need the EntityManager in this case, so I need to provide it,
I'm
>> > >> > > going to write an integration test, not a unit test.
>> > >> > >
>> > >> > > I'm currently studying the openjeb code to find a solution, made
>> > some
>> > >> > > things but no results for the moment.
>> > >> > >
>> > >> > > That would be nice to ben able to make someting like this :
>> > >> > >
>> > >> > >  ejbJar.addEnterpriseBean(new
>> > >> > > MockStatelessBean(DAO.class,daoMockInstance));
>> > >> > >
>> > >> > > If anybody have an idea or suggestion :)
>> > >> > >
>> > >> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
>> > >> > > > I dont think so (the proxy). The need is more than it: vetoing
>> a
>> > >> bean
>> > >> > > > deployment (not managed today i think) + mocking (i would like
>> to
>> > >> avoid
>> > >> > > to
>> > >> > > > update core for this need)
>> > >> > > >
>> > >> > > > - Romain
>> > >> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <
>> jeanouii@gmail.com>
>> > a
>> > >> > > écrit :
>> > >> > > >
>> > >> > > >> Romain,
>> > >> > > >>
>> > >> > > >> maybe a proxy handler on top of the business interface can do
>> the
>> > >> > trick.
>> > >> > > >> Not sure it will work, but it should be able to provide any
>> > >> > > >> implementation
>> > >> > > >> even a mock to a business interface.
>> > >> > > >>
>> > >> > > >> The need is there, so that be great to have a look.
>> > >> > > >> Any other ideas?
>> > >> > > >>
>> > >> > > >> Jean-Louis
>> > >> > > >>
>> > >> > > >>
>> > >> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
>> > >> > > >>
>> > >> > > >> > Hmm, not sure i get what is hard, never tried it but using
>> > >> > alternative
>> > >> > > >> > of
>> > >> > > >> > cdi or specialize should do the trick.
>> > >> > > >> >
>> > >> > > >> > To use mockito you need to change deep in the code the way
>> ejb
>> > >> are
>> > >> > > >> > instantiated+scanned (doable but i really think it is
>> easier to
>> > >> mock
>> > >> > > an
>> > >> > > >> ejb
>> > >> > > >> > than using mockito)
>> > >> > > >> >
>> > >> > > >> > Another lazy solution is to divide your module in submodule
>> to
>> > be
>> > >> > > >> > modular
>> > >> > > >> > even for testing
>> > >> > > >> >
>> > >> > > >> > - Romain
>> > >> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <
>> yann.blazart@bycode.fr>
>> > a
>> > >> > > écrit
>> > >> > > >> > :
>> > >> > > >> >
>> > >> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
>> > >> > > >> > >
>> > >> > > >> > > Why I want to use mockito ? Simply because I wan't to
make
>> > some
>> > >> > unit
>> > >> > > >> > tests
>> > >> > > >> > > without have to get all.
>> > >> > > >> > >
>> > >> > > >> > > For example I wan't to test a business service, a
>> stateless
>> > >> ejb.
>> > >> > > This
>> > >> > > >> one
>> > >> > > >> > > use another one that make some things with mms, databases
>> and
>> > >> > other
>> > >> > > >> > things.
>> > >> > > >> > > The only things I wan't to test are the calling sequences
>> to
>> > >> the
>> > >> > > >> > > second
>> > >> > > >> > ejb
>> > >> > > >> > > by the first one. That's why I wan't to use mockito as I
>> > don't
>> > >> > need
>> > >> > > >> > > to
>> > >> > > >> > > prepare the resources (jms db). if I use a class that
>> extends
>> > >> the
>> > >> > > >> second
>> > >> > > >> > > ejb, it will try to inject the resources I don't need....
>> > >> > > >> > >
>> > >> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
>> > >> > > >> > >
>> > >> > > >> > > > Mockito is more easy to use than extends the ejb class.
>> > >> > > >> > > >
>> > >> > > >> > > > I will search for a way to make that works.
>> > >> > > >> > > >
>> > >> > > >> > > >
>> > >> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
>> > >> > > >> > > >
>> > >> > > >> > > >> Hi,
>> > >> > > >> > > >>
>> > >> > > >> > > >> Generally we mock services replacing them by child or
>> > >> another
>> > >> > > >> > > >> implementation so no need of mockito and you keep
>> > injection
>> > >> > > >> > > >> consistent...but you can use mockito to implement this
>> > other
>> > >> > > class
>> > >> > > >> > with
>> > >> > > >> > > a
>> > >> > > >> > > >> kind of delegate pattern.
>> > >> > > >> > > >>
>> > >> > > >> > > >> - Romain
>> > >> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
>> > >> yann.blazart@bycode.fr>
>> > >> > a
>> > >> > > >> > écrit
>> > >> > > >> > > :
>> > >> > > >> > > >>
>> > >> > > >> > > >> > Hi , is there a way to use Mockito instance with
>> > >> Application
>> > >> > > >> > composer
>> > >> > > >> > > >> for
>> > >> > > >> > > >> > unit tests ?
>> > >> > > >> > > >> >
>> > >> > > >> > > >> > For example here, is there a solution to use the
>> mockito
>> > >> > > >> > > >> > instance
>> > >> > > >> > for
>> > >> > > >> > > >> the
>> > >> > > >> > > >> > EjbJar ? :
>> > >> > > >> > > >> >
>> > >> > > >> > > >> >
>> > >> > > >> > > >> > > @RunWith(ApplicationComposer.class)
>> > >> > > >> > > >> > > public class EchoServiceTest {
>> > >> > > >> > > >> > >
>> > >> > > >> > > >> > >     @Mock
>> > >> > > >> > > >> > >     private DummyService dummyService;
>> > >> > > >> > > >> > >     @EJB
>> > >> > > >> > > >> > >     private EchoService echoService;
>> > >> > > >> > > >> > >     @Before
>> > >> > > >> > > >> > >     public void init() {
>> > >> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
>> > >> > > >> > > >> > >     }
>> > >> > > >> > > >> > >
>> > >> > > >> > > >> > >     @Module
>> > >> > > >> > > >> > >     public EjbJar createEjbJar() {
>> > >> > > >> > > >> > >         EjbJar ejbJar = new
>> > >> > > >> > EjbJar(this.getClass().getSimpleName());
>> > >> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
>> > >> > > >> > > >> StatelessBean(EchoService.class));
>> > >> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new
>> StatelessBean);
>> > >> > > >> > > >> > >         return ejbJar;
>> > >> > > >> > > >> > >     }
>> > >> > > >> > > >> >
>> > >> > > >> > > >>
>> > >> > > >> > > >
>> > >> > > >> > > >
>> > >> > > >> > >
>> > >> > > >> >
>> > >> > > >>
>> > >> > > >
>> > >> > >
>> > >> >
>> > >>
>> > >
>> >
>>
>


Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm you can mock @Inject in EJB (that's what does the test). The opposite
can be done too. So not sure i got your point :s

dependending on the conf you need we can enhance tomee runner to support it
if it is not already the case.

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/11 Elton Kuzniewski <el...@softplan.com.br>

> Great Romain! :)
>
> Some weeks ago I worked in that approach.
> Your first idea is great because in that way we can isolate the ejb's
> method
> to run a real UnitTest using Mockito API that is a knew and well documented
> project.
> The only issue that I still see here is about CDI inside the EJB, where we
> still without options to mock it directly.
> An way that I solved it is using ShrinkWrap to create, in runtime, a
> package
> where I have mocked EJBs that are dependencies (by CDI) from the real EJB
> that I'm interested to test.
> I need to do some tests here, but  your work is of great value.
>
> About your second news, I didn't use Arquillian Test Runner. Instead this I
> created a custom Runner because I had a lot of custom configurations that I
> should do before run container.
> I just have one thing against, where I'm not able to extends
> org.apache.openejb.config.ConfigurationFactory to inject, in run time, a
> new
> declaredApp created by ShrinkWrap.
> It would be great too if this class could have protected method where we
> can
> do this (example method List<String> getDeclaredApps()).
>
>
> Att,
>
> Elton Kuzniewski
> Analista de Sup. Desenvolvimento e Arquitetura
> CSM, SCJA, SCJP 5, SCWCD 5, SCBCD 5
> Pesquisa & Desenvolvimento
> Softplan/Poligraph
> + 55 48 3027-8000
> www.softplan.com.br
>
>
> -----Mensagem original-----
> De: Romain Manni-Bucau [mailto:rmannibucau@gmail.com]
> Enviada em: terça-feira, 11 de setembro de 2012 10:09
> Para: users@openejb.apache.org
> Assunto: Re: OpenEJB Mockito unit test
>
> some news:
>
> application composer + mockito:
>
> http://svn.apache.org/repos/asf/openejb/trunk/openejb/utils/openejb-mockito/
> src/test/java/org/apache/openejb/mockito/MockitoAndAppComposerTest.java
>
> the idea is to provide a custom injector (for @EJB) and an extension is
> automatically discovered for cdi
>
> *and the arquillian version: *
>
> http://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian/arquillian-
>
> openejb-embedded-4/src/test/java/org/apache/openejb/arquillian/openejb/Arqui
> llianAndMockitoTest.java
>
> here bean are produces (in static) and mock are automatically injected (but
> because of current arquillian lifecycle some werid cases can fail :(...for
> them manual mocking is the solution)
>
> it can pby be enhanced but we now have a base ;)
> *
> *
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau*
> *Blog: http://rmannibucau.wordpress.com*
>
>
>
>
> 2012/9/5 Romain Manni-Bucau <rm...@gmail.com>
>
> > Currently no but should be pretty easy ;)
> >
> > Not sure i can go further today but the idea is:
> > 1) create an fallback injector with a map string/object you can feed
> > statically
> > 2) implement getvalue method simply getting in the map the key i said
> > before
> > 3) return an instance in the test class with mockinjector annotation
> > 4) when the mock is created put it in the map
> > 5) clean the map (optional IMO)
> >
> > You can test between 4 and 5 ;)
> >
> > Ps/note: if it was only resources creation the issue we could make them
> > lazy
> > Le 5 sept. 2012 09:22, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> > écrit :
> >
> > any basic sample to give it a try?
> >> Very interesting BTW
> >>
> >> JLouis
> >>
> >> 2012/9/5 Romain Manni-Bucau <rm...@gmail.com>
> >>
> >> > added org.apache.openejb.injection.FallbackPropertyInjector which
> should
> >> > manage failling injections (so you can inject a mock) and in
> application
> >> > composer you can return your injector annotating @MockInjector a
> method.
> >> >
> >> > i didnt test too much, was just trying to find a way which doesn't
> >> impact
> >> > the core in particular from a perf point of view. this one should be
> >> fine
> >> > for @EJB injections.
> >> >
> >> > It will probably be reworked a bit but would like to discuss a bit
> >> before.
> >> >
> >> > For mockito the impl could use a map (injection.getTarget().getName()
> +
> >> "/"
> >> > + injection.getName() as key, mock as value)
> >> >
> >> > wdyt?
> >> >
> >> > *Romain Manni-Bucau*
> >> > *Twitter: @rmannibucau*
> >> > *Blog: http://rmannibucau.wordpress.com*
> >> >
> >> >
> >> >
> >> >
> >> > 2012/8/31 Romain Manni-Bucau <rm...@gmail.com>
> >> >
> >> > > Nothing against it but here is my opinion,
> >> > >
> >> > > JEE is designed to be testable so no need of any "complicated for
> >> > nothing"
> >> > > framework.
> >> > >
> >> > > For me mockito answer to a different need.
> >> > >
> >> > > For a cdi sample we have an example on trunk using alternatives ans
> >> > > stereotypes.
> >> > >
> >> > > - Romain
> >> > > Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a
> >> écrit :
> >> > >
> >> > > I'm agree but tests with arquilian take more time than simple unit
> >> tests.
> >> > >> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com>
> a
> >> > >> écrit :
> >> > >>
> >> > >> > Waiting for Romain's answer, but I guess it will be. Mocking is
> an
> >> old
> >> > >> > school solution ;-)
> >> > >> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian,
> and
> >> so
> >> > >> on,
> >> > >> > it's far easier to get simple integration tests. So the need to
> >> really
> >> > >> > write unit tests is smaller.
> >> > >> >
> >> > >> > Just some thoughts.
> >> > >> > Romain is currently on holidays, but quite sure he will find a
> hack
> >> > for
> >> > >> you
> >> > >> > when he'll be back ;-)
> >> > >> >
> >> > >> > Jean-Louis
> >> > >> >
> >> > >> >
> >> > >> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
> >> > >> >
> >> > >> > > Well, in fact I'm not sure to go in the right way.
> >> > >> > >
> >> > >> > > I wan't to make the demonstration that jee6 can now replace
> >> spring.
> >> > >> > > One thing very interesting in spring is about that faculty to
> >> make
> >> > >> > > "unit-test" between real unit-test and integration tests with
> >> > >> > > @Configuration. I wanted to make the same thing.
> >> > >> > >
> >> > >> > > I can reproduce it with cdi-unit for example, but I wan't to
> use
> >> EJB
> >> > >> > > 3.1 too (transaction, and security), my research show me the
> >> OpenEjb
> >> > >> > > stack with the ApplicationComposer runner, this is very cool !
> >> > >> > >
> >> > >> > > Well to get back to my main subject. In fact that should be
> very
> >> > nice
> >> > >> > > to be able to use Mocks from Mockito instead of the instances
> >> > produced
> >> > >> > > by the container.
> >> > >> > >
> >> > >> > > Example : I have my business service a Stateless localbean,
> this
> >> one
> >> > >> > > use a DAO, same Stateless localbean with no interface. This DAO
> >> use
> >> > a
> >> > >> > > persistence manager. As the DAO has no interface, I cannot
> >> replace
> >> > his
> >> > >> > > implementation in the @Module by writing a mock by hand, the
> >> simple
> >> > >> > > extended class do not work. The problem is that this dao
> >> absolutely
> >> > >> > > need the EntityManager in this case, so I need to provide it,
> I'm
> >> > >> > > going to write an integration test, not a unit test.
> >> > >> > >
> >> > >> > > I'm currently studying the openjeb code to find a solution,
> made
> >> > some
> >> > >> > > things but no results for the moment.
> >> > >> > >
> >> > >> > > That would be nice to ben able to make someting like this :
> >> > >> > >
> >> > >> > >  ejbJar.addEnterpriseBean(new
> >> > >> > > MockStatelessBean(DAO.class,daoMockInstance));
> >> > >> > >
> >> > >> > > If anybody have an idea or suggestion :)
> >> > >> > >
> >> > >> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> >> > >> > > > I dont think so (the proxy). The need is more than it:
> vetoing
> >> a
> >> > >> bean
> >> > >> > > > deployment (not managed today i think) + mocking (i would
> like
> >> to
> >> > >> avoid
> >> > >> > > to
> >> > >> > > > update core for this need)
> >> > >> > > >
> >> > >> > > > - Romain
> >> > >> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <
> >> jeanouii@gmail.com>
> >> > a
> >> > >> > > écrit :
> >> > >> > > >
> >> > >> > > >> Romain,
> >> > >> > > >>
> >> > >> > > >> maybe a proxy handler on top of the business interface can
> do
> >> the
> >> > >> > trick.
> >> > >> > > >> Not sure it will work, but it should be able to provide any
> >> > >> > > >> implementation
> >> > >> > > >> even a mock to a business interface.
> >> > >> > > >>
> >> > >> > > >> The need is there, so that be great to have a look.
> >> > >> > > >> Any other ideas?
> >> > >> > > >>
> >> > >> > > >> Jean-Louis
> >> > >> > > >>
> >> > >> > > >>
> >> > >> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> >> > >> > > >>
> >> > >> > > >> > Hmm, not sure i get what is hard, never tried it but using
> >> > >> > alternative
> >> > >> > > >> > of
> >> > >> > > >> > cdi or specialize should do the trick.
> >> > >> > > >> >
> >> > >> > > >> > To use mockito you need to change deep in the code the way
> >> ejb
> >> > >> are
> >> > >> > > >> > instantiated+scanned (doable but i really think it is
> >> easier to
> >> > >> mock
> >> > >> > > an
> >> > >> > > >> ejb
> >> > >> > > >> > than using mockito)
> >> > >> > > >> >
> >> > >> > > >> > Another lazy solution is to divide your module in
> submodule
> >> to
> >> > be
> >> > >> > > >> > modular
> >> > >> > > >> > even for testing
> >> > >> > > >> >
> >> > >> > > >> > - Romain
> >> > >> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <
> >> yann.blazart@bycode.fr>
> >> > a
> >> > >> > > écrit
> >> > >> > > >> > :
> >> > >> > > >> >
> >> > >> > > >> > > Wo I'm studying applicationComposer code. It's
> difficult.
> >> > >> > > >> > >
> >> > >> > > >> > > Why I want to use mockito ? Simply because I wan't to
> make
> >> > some
> >> > >> > unit
> >> > >> > > >> > tests
> >> > >> > > >> > > without have to get all.
> >> > >> > > >> > >
> >> > >> > > >> > > For example I wan't to test a business service, a
> >> stateless
> >> > >> ejb.
> >> > >> > > This
> >> > >> > > >> one
> >> > >> > > >> > > use another one that make some things with mms,
> databases
> >> and
> >> > >> > other
> >> > >> > > >> > things.
> >> > >> > > >> > > The only things I wan't to test are the calling
> sequences
> >> to
> >> > >> the
> >> > >> > > >> > > second
> >> > >> > > >> > ejb
> >> > >> > > >> > > by the first one. That's why I wan't to use mockito as I
> >> > don't
> >> > >> > need
> >> > >> > > >> > > to
> >> > >> > > >> > > prepare the resources (jms db). if I use a class that
> >> extends
> >> > >> the
> >> > >> > > >> second
> >> > >> > > >> > > ejb, it will try to inject the resources I don't
> need....
> >> > >> > > >> > >
> >> > >> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> >> > >> > > >> > >
> >> > >> > > >> > > > Mockito is more easy to use than extends the ejb
> class.
> >> > >> > > >> > > >
> >> > >> > > >> > > > I will search for a way to make that works.
> >> > >> > > >> > > >
> >> > >> > > >> > > >
> >> > >> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> >> > >> > > >> > > >
> >> > >> > > >> > > >> Hi,
> >> > >> > > >> > > >>
> >> > >> > > >> > > >> Generally we mock services replacing them by child or
> >> > >> another
> >> > >> > > >> > > >> implementation so no need of mockito and you keep
> >> > injection
> >> > >> > > >> > > >> consistent...but you can use mockito to implement
> this
> >> > other
> >> > >> > > class
> >> > >> > > >> > with
> >> > >> > > >> > > a
> >> > >> > > >> > > >> kind of delegate pattern.
> >> > >> > > >> > > >>
> >> > >> > > >> > > >> - Romain
> >> > >> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
> >> > >> yann.blazart@bycode.fr>
> >> > >> > a
> >> > >> > > >> > écrit
> >> > >> > > >> > > :
> >> > >> > > >> > > >>
> >> > >> > > >> > > >> > Hi , is there a way to use Mockito instance with
> >> > >> Application
> >> > >> > > >> > composer
> >> > >> > > >> > > >> for
> >> > >> > > >> > > >> > unit tests ?
> >> > >> > > >> > > >> >
> >> > >> > > >> > > >> > For example here, is there a solution to use the
> >> mockito
> >> > >> > > >> > > >> > instance
> >> > >> > > >> > for
> >> > >> > > >> > > >> the
> >> > >> > > >> > > >> > EjbJar ? :
> >> > >> > > >> > > >> >
> >> > >> > > >> > > >> >
> >> > >> > > >> > > >> > > @RunWith(ApplicationComposer.class)
> >> > >> > > >> > > >> > > public class EchoServiceTest {
> >> > >> > > >> > > >> > >
> >> > >> > > >> > > >> > >     @Mock
> >> > >> > > >> > > >> > >     private DummyService dummyService;
> >> > >> > > >> > > >> > >     @EJB
> >> > >> > > >> > > >> > >     private EchoService echoService;
> >> > >> > > >> > > >> > >     @Before
> >> > >> > > >> > > >> > >     public void init() {
> >> > >> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
> >> > >> > > >> > > >> > >     }
> >> > >> > > >> > > >> > >
> >> > >> > > >> > > >> > >     @Module
> >> > >> > > >> > > >> > >     public EjbJar createEjbJar() {
> >> > >> > > >> > > >> > >         EjbJar ejbJar = new
> >> > >> > > >> > EjbJar(this.getClass().getSimpleName());
> >> > >> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
> >> > >> > > >> > > >> StatelessBean(EchoService.class));
> >> > >> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new
> >> StatelessBean);
> >> > >> > > >> > > >> > >         return ejbJar;
> >> > >> > > >> > > >> > >     }
> >> > >> > > >> > > >> >
> >> > >> > > >> > > >>
> >> > >> > > >> > > >
> >> > >> > > >> > > >
> >> > >> > > >> > >
> >> > >> > > >> >
> >> > >> > > >>
> >> > >> > > >
> >> > >> > >
> >> > >> >
> >> > >>
> >> > >
> >> >
> >>
> >
>
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
some news:

application composer + mockito:
http://svn.apache.org/repos/asf/openejb/trunk/openejb/utils/openejb-mockito/src/test/java/org/apache/openejb/mockito/MockitoAndAppComposerTest.java

the idea is to provide a custom injector (for @EJB) and an extension is
automatically discovered for cdi

*and the arquillian version: *
http://svn.apache.org/repos/asf/openejb/trunk/openejb/arquillian/arquillian-openejb-embedded-4/src/test/java/org/apache/openejb/arquillian/openejb/ArquillianAndMockitoTest.java

here bean are produces (in static) and mock are automatically injected (but
because of current arquillian lifecycle some werid cases can fail :(...for
them manual mocking is the solution)

it can pby be enhanced but we now have a base ;)
*
*
*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/5 Romain Manni-Bucau <rm...@gmail.com>

> Currently no but should be pretty easy ;)
>
> Not sure i can go further today but the idea is:
> 1) create an fallback injector with a map string/object you can feed
> statically
> 2) implement getvalue method simply getting in the map the key i said
> before
> 3) return an instance in the test class with mockinjector annotation
> 4) when the mock is created put it in the map
> 5) clean the map (optional IMO)
>
> You can test between 4 and 5 ;)
>
> Ps/note: if it was only resources creation the issue we could make them
> lazy
> Le 5 sept. 2012 09:22, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> écrit :
>
> any basic sample to give it a try?
>> Very interesting BTW
>>
>> JLouis
>>
>> 2012/9/5 Romain Manni-Bucau <rm...@gmail.com>
>>
>> > added org.apache.openejb.injection.FallbackPropertyInjector which should
>> > manage failling injections (so you can inject a mock) and in application
>> > composer you can return your injector annotating @MockInjector a method.
>> >
>> > i didnt test too much, was just trying to find a way which doesn't
>> impact
>> > the core in particular from a perf point of view. this one should be
>> fine
>> > for @EJB injections.
>> >
>> > It will probably be reworked a bit but would like to discuss a bit
>> before.
>> >
>> > For mockito the impl could use a map (injection.getTarget().getName() +
>> "/"
>> > + injection.getName() as key, mock as value)
>> >
>> > wdyt?
>> >
>> > *Romain Manni-Bucau*
>> > *Twitter: @rmannibucau*
>> > *Blog: http://rmannibucau.wordpress.com*
>> >
>> >
>> >
>> >
>> > 2012/8/31 Romain Manni-Bucau <rm...@gmail.com>
>> >
>> > > Nothing against it but here is my opinion,
>> > >
>> > > JEE is designed to be testable so no need of any "complicated for
>> > nothing"
>> > > framework.
>> > >
>> > > For me mockito answer to a different need.
>> > >
>> > > For a cdi sample we have an example on trunk using alternatives ans
>> > > stereotypes.
>> > >
>> > > - Romain
>> > > Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a
>> écrit :
>> > >
>> > > I'm agree but tests with arquilian take more time than simple unit
>> tests.
>> > >> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a
>> > >> écrit :
>> > >>
>> > >> > Waiting for Romain's answer, but I guess it will be. Mocking is an
>> old
>> > >> > school solution ;-)
>> > >> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and
>> so
>> > >> on,
>> > >> > it's far easier to get simple integration tests. So the need to
>> really
>> > >> > write unit tests is smaller.
>> > >> >
>> > >> > Just some thoughts.
>> > >> > Romain is currently on holidays, but quite sure he will find a hack
>> > for
>> > >> you
>> > >> > when he'll be back ;-)
>> > >> >
>> > >> > Jean-Louis
>> > >> >
>> > >> >
>> > >> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
>> > >> >
>> > >> > > Well, in fact I'm not sure to go in the right way.
>> > >> > >
>> > >> > > I wan't to make the demonstration that jee6 can now replace
>> spring.
>> > >> > > One thing very interesting in spring is about that faculty to
>> make
>> > >> > > "unit-test" between real unit-test and integration tests with
>> > >> > > @Configuration. I wanted to make the same thing.
>> > >> > >
>> > >> > > I can reproduce it with cdi-unit for example, but I wan't to use
>> EJB
>> > >> > > 3.1 too (transaction, and security), my research show me the
>> OpenEjb
>> > >> > > stack with the ApplicationComposer runner, this is very cool !
>> > >> > >
>> > >> > > Well to get back to my main subject. In fact that should be very
>> > nice
>> > >> > > to be able to use Mocks from Mockito instead of the instances
>> > produced
>> > >> > > by the container.
>> > >> > >
>> > >> > > Example : I have my business service a Stateless localbean, this
>> one
>> > >> > > use a DAO, same Stateless localbean with no interface. This DAO
>> use
>> > a
>> > >> > > persistence manager. As the DAO has no interface, I cannot
>> replace
>> > his
>> > >> > > implementation in the @Module by writing a mock by hand, the
>> simple
>> > >> > > extended class do not work. The problem is that this dao
>> absolutely
>> > >> > > need the EntityManager in this case, so I need to provide it, I'm
>> > >> > > going to write an integration test, not a unit test.
>> > >> > >
>> > >> > > I'm currently studying the openjeb code to find a solution, made
>> > some
>> > >> > > things but no results for the moment.
>> > >> > >
>> > >> > > That would be nice to ben able to make someting like this :
>> > >> > >
>> > >> > >  ejbJar.addEnterpriseBean(new
>> > >> > > MockStatelessBean(DAO.class,daoMockInstance));
>> > >> > >
>> > >> > > If anybody have an idea or suggestion :)
>> > >> > >
>> > >> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
>> > >> > > > I dont think so (the proxy). The need is more than it: vetoing
>> a
>> > >> bean
>> > >> > > > deployment (not managed today i think) + mocking (i would like
>> to
>> > >> avoid
>> > >> > > to
>> > >> > > > update core for this need)
>> > >> > > >
>> > >> > > > - Romain
>> > >> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <
>> jeanouii@gmail.com>
>> > a
>> > >> > > écrit :
>> > >> > > >
>> > >> > > >> Romain,
>> > >> > > >>
>> > >> > > >> maybe a proxy handler on top of the business interface can do
>> the
>> > >> > trick.
>> > >> > > >> Not sure it will work, but it should be able to provide any
>> > >> > > >> implementation
>> > >> > > >> even a mock to a business interface.
>> > >> > > >>
>> > >> > > >> The need is there, so that be great to have a look.
>> > >> > > >> Any other ideas?
>> > >> > > >>
>> > >> > > >> Jean-Louis
>> > >> > > >>
>> > >> > > >>
>> > >> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
>> > >> > > >>
>> > >> > > >> > Hmm, not sure i get what is hard, never tried it but using
>> > >> > alternative
>> > >> > > >> > of
>> > >> > > >> > cdi or specialize should do the trick.
>> > >> > > >> >
>> > >> > > >> > To use mockito you need to change deep in the code the way
>> ejb
>> > >> are
>> > >> > > >> > instantiated+scanned (doable but i really think it is
>> easier to
>> > >> mock
>> > >> > > an
>> > >> > > >> ejb
>> > >> > > >> > than using mockito)
>> > >> > > >> >
>> > >> > > >> > Another lazy solution is to divide your module in submodule
>> to
>> > be
>> > >> > > >> > modular
>> > >> > > >> > even for testing
>> > >> > > >> >
>> > >> > > >> > - Romain
>> > >> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <
>> yann.blazart@bycode.fr>
>> > a
>> > >> > > écrit
>> > >> > > >> > :
>> > >> > > >> >
>> > >> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
>> > >> > > >> > >
>> > >> > > >> > > Why I want to use mockito ? Simply because I wan't to make
>> > some
>> > >> > unit
>> > >> > > >> > tests
>> > >> > > >> > > without have to get all.
>> > >> > > >> > >
>> > >> > > >> > > For example I wan't to test a business service, a
>> stateless
>> > >> ejb.
>> > >> > > This
>> > >> > > >> one
>> > >> > > >> > > use another one that make some things with mms, databases
>> and
>> > >> > other
>> > >> > > >> > things.
>> > >> > > >> > > The only things I wan't to test are the calling sequences
>> to
>> > >> the
>> > >> > > >> > > second
>> > >> > > >> > ejb
>> > >> > > >> > > by the first one. That's why I wan't to use mockito as I
>> > don't
>> > >> > need
>> > >> > > >> > > to
>> > >> > > >> > > prepare the resources (jms db). if I use a class that
>> extends
>> > >> the
>> > >> > > >> second
>> > >> > > >> > > ejb, it will try to inject the resources I don't need....
>> > >> > > >> > >
>> > >> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
>> > >> > > >> > >
>> > >> > > >> > > > Mockito is more easy to use than extends the ejb class.
>> > >> > > >> > > >
>> > >> > > >> > > > I will search for a way to make that works.
>> > >> > > >> > > >
>> > >> > > >> > > >
>> > >> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
>> > >> > > >> > > >
>> > >> > > >> > > >> Hi,
>> > >> > > >> > > >>
>> > >> > > >> > > >> Generally we mock services replacing them by child or
>> > >> another
>> > >> > > >> > > >> implementation so no need of mockito and you keep
>> > injection
>> > >> > > >> > > >> consistent...but you can use mockito to implement this
>> > other
>> > >> > > class
>> > >> > > >> > with
>> > >> > > >> > > a
>> > >> > > >> > > >> kind of delegate pattern.
>> > >> > > >> > > >>
>> > >> > > >> > > >> - Romain
>> > >> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
>> > >> yann.blazart@bycode.fr>
>> > >> > a
>> > >> > > >> > écrit
>> > >> > > >> > > :
>> > >> > > >> > > >>
>> > >> > > >> > > >> > Hi , is there a way to use Mockito instance with
>> > >> Application
>> > >> > > >> > composer
>> > >> > > >> > > >> for
>> > >> > > >> > > >> > unit tests ?
>> > >> > > >> > > >> >
>> > >> > > >> > > >> > For example here, is there a solution to use the
>> mockito
>> > >> > > >> > > >> > instance
>> > >> > > >> > for
>> > >> > > >> > > >> the
>> > >> > > >> > > >> > EjbJar ? :
>> > >> > > >> > > >> >
>> > >> > > >> > > >> >
>> > >> > > >> > > >> > > @RunWith(ApplicationComposer.class)
>> > >> > > >> > > >> > > public class EchoServiceTest {
>> > >> > > >> > > >> > >
>> > >> > > >> > > >> > >     @Mock
>> > >> > > >> > > >> > >     private DummyService dummyService;
>> > >> > > >> > > >> > >     @EJB
>> > >> > > >> > > >> > >     private EchoService echoService;
>> > >> > > >> > > >> > >     @Before
>> > >> > > >> > > >> > >     public void init() {
>> > >> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
>> > >> > > >> > > >> > >     }
>> > >> > > >> > > >> > >
>> > >> > > >> > > >> > >     @Module
>> > >> > > >> > > >> > >     public EjbJar createEjbJar() {
>> > >> > > >> > > >> > >         EjbJar ejbJar = new
>> > >> > > >> > EjbJar(this.getClass().getSimpleName());
>> > >> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
>> > >> > > >> > > >> StatelessBean(EchoService.class));
>> > >> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new
>> StatelessBean);
>> > >> > > >> > > >> > >         return ejbJar;
>> > >> > > >> > > >> > >     }
>> > >> > > >> > > >> >
>> > >> > > >> > > >>
>> > >> > > >> > > >
>> > >> > > >> > > >
>> > >> > > >> > >
>> > >> > > >> >
>> > >> > > >>
>> > >> > > >
>> > >> > >
>> > >> >
>> > >>
>> > >
>> >
>>
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Currently no but should be pretty easy ;)

Not sure i can go further today but the idea is:
1) create an fallback injector with a map string/object you can feed
statically
2) implement getvalue method simply getting in the map the key i said before
3) return an instance in the test class with mockinjector annotation
4) when the mock is created put it in the map
5) clean the map (optional IMO)

You can test between 4 and 5 ;)

Ps/note: if it was only resources creation the issue we could make them lazy
Le 5 sept. 2012 09:22, "Jean-Louis MONTEIRO" <je...@gmail.com> a écrit :

> any basic sample to give it a try?
> Very interesting BTW
>
> JLouis
>
> 2012/9/5 Romain Manni-Bucau <rm...@gmail.com>
>
> > added org.apache.openejb.injection.FallbackPropertyInjector which should
> > manage failling injections (so you can inject a mock) and in application
> > composer you can return your injector annotating @MockInjector a method.
> >
> > i didnt test too much, was just trying to find a way which doesn't impact
> > the core in particular from a perf point of view. this one should be fine
> > for @EJB injections.
> >
> > It will probably be reworked a bit but would like to discuss a bit
> before.
> >
> > For mockito the impl could use a map (injection.getTarget().getName() +
> "/"
> > + injection.getName() as key, mock as value)
> >
> > wdyt?
> >
> > *Romain Manni-Bucau*
> > *Twitter: @rmannibucau*
> > *Blog: http://rmannibucau.wordpress.com*
> >
> >
> >
> >
> > 2012/8/31 Romain Manni-Bucau <rm...@gmail.com>
> >
> > > Nothing against it but here is my opinion,
> > >
> > > JEE is designed to be testable so no need of any "complicated for
> > nothing"
> > > framework.
> > >
> > > For me mockito answer to a different need.
> > >
> > > For a cdi sample we have an example on trunk using alternatives ans
> > > stereotypes.
> > >
> > > - Romain
> > > Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a
> écrit :
> > >
> > > I'm agree but tests with arquilian take more time than simple unit
> tests.
> > >> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> > >> écrit :
> > >>
> > >> > Waiting for Romain's answer, but I guess it will be. Mocking is an
> old
> > >> > school solution ;-)
> > >> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and
> so
> > >> on,
> > >> > it's far easier to get simple integration tests. So the need to
> really
> > >> > write unit tests is smaller.
> > >> >
> > >> > Just some thoughts.
> > >> > Romain is currently on holidays, but quite sure he will find a hack
> > for
> > >> you
> > >> > when he'll be back ;-)
> > >> >
> > >> > Jean-Louis
> > >> >
> > >> >
> > >> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
> > >> >
> > >> > > Well, in fact I'm not sure to go in the right way.
> > >> > >
> > >> > > I wan't to make the demonstration that jee6 can now replace
> spring.
> > >> > > One thing very interesting in spring is about that faculty to make
> > >> > > "unit-test" between real unit-test and integration tests with
> > >> > > @Configuration. I wanted to make the same thing.
> > >> > >
> > >> > > I can reproduce it with cdi-unit for example, but I wan't to use
> EJB
> > >> > > 3.1 too (transaction, and security), my research show me the
> OpenEjb
> > >> > > stack with the ApplicationComposer runner, this is very cool !
> > >> > >
> > >> > > Well to get back to my main subject. In fact that should be very
> > nice
> > >> > > to be able to use Mocks from Mockito instead of the instances
> > produced
> > >> > > by the container.
> > >> > >
> > >> > > Example : I have my business service a Stateless localbean, this
> one
> > >> > > use a DAO, same Stateless localbean with no interface. This DAO
> use
> > a
> > >> > > persistence manager. As the DAO has no interface, I cannot replace
> > his
> > >> > > implementation in the @Module by writing a mock by hand, the
> simple
> > >> > > extended class do not work. The problem is that this dao
> absolutely
> > >> > > need the EntityManager in this case, so I need to provide it, I'm
> > >> > > going to write an integration test, not a unit test.
> > >> > >
> > >> > > I'm currently studying the openjeb code to find a solution, made
> > some
> > >> > > things but no results for the moment.
> > >> > >
> > >> > > That would be nice to ben able to make someting like this :
> > >> > >
> > >> > >  ejbJar.addEnterpriseBean(new
> > >> > > MockStatelessBean(DAO.class,daoMockInstance));
> > >> > >
> > >> > > If anybody have an idea or suggestion :)
> > >> > >
> > >> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> > >> > > > I dont think so (the proxy). The need is more than it: vetoing a
> > >> bean
> > >> > > > deployment (not managed today i think) + mocking (i would like
> to
> > >> avoid
> > >> > > to
> > >> > > > update core for this need)
> > >> > > >
> > >> > > > - Romain
> > >> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <
> jeanouii@gmail.com>
> > a
> > >> > > écrit :
> > >> > > >
> > >> > > >> Romain,
> > >> > > >>
> > >> > > >> maybe a proxy handler on top of the business interface can do
> the
> > >> > trick.
> > >> > > >> Not sure it will work, but it should be able to provide any
> > >> > > >> implementation
> > >> > > >> even a mock to a business interface.
> > >> > > >>
> > >> > > >> The need is there, so that be great to have a look.
> > >> > > >> Any other ideas?
> > >> > > >>
> > >> > > >> Jean-Louis
> > >> > > >>
> > >> > > >>
> > >> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> > >> > > >>
> > >> > > >> > Hmm, not sure i get what is hard, never tried it but using
> > >> > alternative
> > >> > > >> > of
> > >> > > >> > cdi or specialize should do the trick.
> > >> > > >> >
> > >> > > >> > To use mockito you need to change deep in the code the way
> ejb
> > >> are
> > >> > > >> > instantiated+scanned (doable but i really think it is easier
> to
> > >> mock
> > >> > > an
> > >> > > >> ejb
> > >> > > >> > than using mockito)
> > >> > > >> >
> > >> > > >> > Another lazy solution is to divide your module in submodule
> to
> > be
> > >> > > >> > modular
> > >> > > >> > even for testing
> > >> > > >> >
> > >> > > >> > - Romain
> > >> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <
> yann.blazart@bycode.fr>
> > a
> > >> > > écrit
> > >> > > >> > :
> > >> > > >> >
> > >> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
> > >> > > >> > >
> > >> > > >> > > Why I want to use mockito ? Simply because I wan't to make
> > some
> > >> > unit
> > >> > > >> > tests
> > >> > > >> > > without have to get all.
> > >> > > >> > >
> > >> > > >> > > For example I wan't to test a business service, a stateless
> > >> ejb.
> > >> > > This
> > >> > > >> one
> > >> > > >> > > use another one that make some things with mms, databases
> and
> > >> > other
> > >> > > >> > things.
> > >> > > >> > > The only things I wan't to test are the calling sequences
> to
> > >> the
> > >> > > >> > > second
> > >> > > >> > ejb
> > >> > > >> > > by the first one. That's why I wan't to use mockito as I
> > don't
> > >> > need
> > >> > > >> > > to
> > >> > > >> > > prepare the resources (jms db). if I use a class that
> extends
> > >> the
> > >> > > >> second
> > >> > > >> > > ejb, it will try to inject the resources I don't need....
> > >> > > >> > >
> > >> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> > >> > > >> > >
> > >> > > >> > > > Mockito is more easy to use than extends the ejb class.
> > >> > > >> > > >
> > >> > > >> > > > I will search for a way to make that works.
> > >> > > >> > > >
> > >> > > >> > > >
> > >> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> > >> > > >> > > >
> > >> > > >> > > >> Hi,
> > >> > > >> > > >>
> > >> > > >> > > >> Generally we mock services replacing them by child or
> > >> another
> > >> > > >> > > >> implementation so no need of mockito and you keep
> > injection
> > >> > > >> > > >> consistent...but you can use mockito to implement this
> > other
> > >> > > class
> > >> > > >> > with
> > >> > > >> > > a
> > >> > > >> > > >> kind of delegate pattern.
> > >> > > >> > > >>
> > >> > > >> > > >> - Romain
> > >> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
> > >> yann.blazart@bycode.fr>
> > >> > a
> > >> > > >> > écrit
> > >> > > >> > > :
> > >> > > >> > > >>
> > >> > > >> > > >> > Hi , is there a way to use Mockito instance with
> > >> Application
> > >> > > >> > composer
> > >> > > >> > > >> for
> > >> > > >> > > >> > unit tests ?
> > >> > > >> > > >> >
> > >> > > >> > > >> > For example here, is there a solution to use the
> mockito
> > >> > > >> > > >> > instance
> > >> > > >> > for
> > >> > > >> > > >> the
> > >> > > >> > > >> > EjbJar ? :
> > >> > > >> > > >> >
> > >> > > >> > > >> >
> > >> > > >> > > >> > > @RunWith(ApplicationComposer.class)
> > >> > > >> > > >> > > public class EchoServiceTest {
> > >> > > >> > > >> > >
> > >> > > >> > > >> > >     @Mock
> > >> > > >> > > >> > >     private DummyService dummyService;
> > >> > > >> > > >> > >     @EJB
> > >> > > >> > > >> > >     private EchoService echoService;
> > >> > > >> > > >> > >     @Before
> > >> > > >> > > >> > >     public void init() {
> > >> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
> > >> > > >> > > >> > >     }
> > >> > > >> > > >> > >
> > >> > > >> > > >> > >     @Module
> > >> > > >> > > >> > >     public EjbJar createEjbJar() {
> > >> > > >> > > >> > >         EjbJar ejbJar = new
> > >> > > >> > EjbJar(this.getClass().getSimpleName());
> > >> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
> > >> > > >> > > >> StatelessBean(EchoService.class));
> > >> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new
> StatelessBean);
> > >> > > >> > > >> > >         return ejbJar;
> > >> > > >> > > >> > >     }
> > >> > > >> > > >> >
> > >> > > >> > > >>
> > >> > > >> > > >
> > >> > > >> > > >
> > >> > > >> > >
> > >> > > >> >
> > >> > > >>
> > >> > > >
> > >> > >
> > >> >
> > >>
> > >
> >
>

Re: OpenEJB Mockito unit test

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
any basic sample to give it a try?
Very interesting BTW

JLouis

2012/9/5 Romain Manni-Bucau <rm...@gmail.com>

> added org.apache.openejb.injection.FallbackPropertyInjector which should
> manage failling injections (so you can inject a mock) and in application
> composer you can return your injector annotating @MockInjector a method.
>
> i didnt test too much, was just trying to find a way which doesn't impact
> the core in particular from a perf point of view. this one should be fine
> for @EJB injections.
>
> It will probably be reworked a bit but would like to discuss a bit before.
>
> For mockito the impl could use a map (injection.getTarget().getName() + "/"
> + injection.getName() as key, mock as value)
>
> wdyt?
>
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau*
> *Blog: http://rmannibucau.wordpress.com*
>
>
>
>
> 2012/8/31 Romain Manni-Bucau <rm...@gmail.com>
>
> > Nothing against it but here is my opinion,
> >
> > JEE is designed to be testable so no need of any "complicated for
> nothing"
> > framework.
> >
> > For me mockito answer to a different need.
> >
> > For a cdi sample we have an example on trunk using alternatives ans
> > stereotypes.
> >
> > - Romain
> > Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a écrit :
> >
> > I'm agree but tests with arquilian take more time than simple unit tests.
> >> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> >> écrit :
> >>
> >> > Waiting for Romain's answer, but I guess it will be. Mocking is an old
> >> > school solution ;-)
> >> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and so
> >> on,
> >> > it's far easier to get simple integration tests. So the need to really
> >> > write unit tests is smaller.
> >> >
> >> > Just some thoughts.
> >> > Romain is currently on holidays, but quite sure he will find a hack
> for
> >> you
> >> > when he'll be back ;-)
> >> >
> >> > Jean-Louis
> >> >
> >> >
> >> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
> >> >
> >> > > Well, in fact I'm not sure to go in the right way.
> >> > >
> >> > > I wan't to make the demonstration that jee6 can now replace spring.
> >> > > One thing very interesting in spring is about that faculty to make
> >> > > "unit-test" between real unit-test and integration tests with
> >> > > @Configuration. I wanted to make the same thing.
> >> > >
> >> > > I can reproduce it with cdi-unit for example, but I wan't to use EJB
> >> > > 3.1 too (transaction, and security), my research show me the OpenEjb
> >> > > stack with the ApplicationComposer runner, this is very cool !
> >> > >
> >> > > Well to get back to my main subject. In fact that should be very
> nice
> >> > > to be able to use Mocks from Mockito instead of the instances
> produced
> >> > > by the container.
> >> > >
> >> > > Example : I have my business service a Stateless localbean, this one
> >> > > use a DAO, same Stateless localbean with no interface. This DAO use
> a
> >> > > persistence manager. As the DAO has no interface, I cannot replace
> his
> >> > > implementation in the @Module by writing a mock by hand, the simple
> >> > > extended class do not work. The problem is that this dao absolutely
> >> > > need the EntityManager in this case, so I need to provide it, I'm
> >> > > going to write an integration test, not a unit test.
> >> > >
> >> > > I'm currently studying the openjeb code to find a solution, made
> some
> >> > > things but no results for the moment.
> >> > >
> >> > > That would be nice to ben able to make someting like this :
> >> > >
> >> > >  ejbJar.addEnterpriseBean(new
> >> > > MockStatelessBean(DAO.class,daoMockInstance));
> >> > >
> >> > > If anybody have an idea or suggestion :)
> >> > >
> >> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> >> > > > I dont think so (the proxy). The need is more than it: vetoing a
> >> bean
> >> > > > deployment (not managed today i think) + mocking (i would like to
> >> avoid
> >> > > to
> >> > > > update core for this need)
> >> > > >
> >> > > > - Romain
> >> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com>
> a
> >> > > écrit :
> >> > > >
> >> > > >> Romain,
> >> > > >>
> >> > > >> maybe a proxy handler on top of the business interface can do the
> >> > trick.
> >> > > >> Not sure it will work, but it should be able to provide any
> >> > > >> implementation
> >> > > >> even a mock to a business interface.
> >> > > >>
> >> > > >> The need is there, so that be great to have a look.
> >> > > >> Any other ideas?
> >> > > >>
> >> > > >> Jean-Louis
> >> > > >>
> >> > > >>
> >> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> >> > > >>
> >> > > >> > Hmm, not sure i get what is hard, never tried it but using
> >> > alternative
> >> > > >> > of
> >> > > >> > cdi or specialize should do the trick.
> >> > > >> >
> >> > > >> > To use mockito you need to change deep in the code the way ejb
> >> are
> >> > > >> > instantiated+scanned (doable but i really think it is easier to
> >> mock
> >> > > an
> >> > > >> ejb
> >> > > >> > than using mockito)
> >> > > >> >
> >> > > >> > Another lazy solution is to divide your module in submodule to
> be
> >> > > >> > modular
> >> > > >> > even for testing
> >> > > >> >
> >> > > >> > - Romain
> >> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr>
> a
> >> > > écrit
> >> > > >> > :
> >> > > >> >
> >> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
> >> > > >> > >
> >> > > >> > > Why I want to use mockito ? Simply because I wan't to make
> some
> >> > unit
> >> > > >> > tests
> >> > > >> > > without have to get all.
> >> > > >> > >
> >> > > >> > > For example I wan't to test a business service, a stateless
> >> ejb.
> >> > > This
> >> > > >> one
> >> > > >> > > use another one that make some things with mms, databases and
> >> > other
> >> > > >> > things.
> >> > > >> > > The only things I wan't to test are the calling sequences to
> >> the
> >> > > >> > > second
> >> > > >> > ejb
> >> > > >> > > by the first one. That's why I wan't to use mockito as I
> don't
> >> > need
> >> > > >> > > to
> >> > > >> > > prepare the resources (jms db). if I use a class that extends
> >> the
> >> > > >> second
> >> > > >> > > ejb, it will try to inject the resources I don't need....
> >> > > >> > >
> >> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> >> > > >> > >
> >> > > >> > > > Mockito is more easy to use than extends the ejb class.
> >> > > >> > > >
> >> > > >> > > > I will search for a way to make that works.
> >> > > >> > > >
> >> > > >> > > >
> >> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> >> > > >> > > >
> >> > > >> > > >> Hi,
> >> > > >> > > >>
> >> > > >> > > >> Generally we mock services replacing them by child or
> >> another
> >> > > >> > > >> implementation so no need of mockito and you keep
> injection
> >> > > >> > > >> consistent...but you can use mockito to implement this
> other
> >> > > class
> >> > > >> > with
> >> > > >> > > a
> >> > > >> > > >> kind of delegate pattern.
> >> > > >> > > >>
> >> > > >> > > >> - Romain
> >> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
> >> yann.blazart@bycode.fr>
> >> > a
> >> > > >> > écrit
> >> > > >> > > :
> >> > > >> > > >>
> >> > > >> > > >> > Hi , is there a way to use Mockito instance with
> >> Application
> >> > > >> > composer
> >> > > >> > > >> for
> >> > > >> > > >> > unit tests ?
> >> > > >> > > >> >
> >> > > >> > > >> > For example here, is there a solution to use the mockito
> >> > > >> > > >> > instance
> >> > > >> > for
> >> > > >> > > >> the
> >> > > >> > > >> > EjbJar ? :
> >> > > >> > > >> >
> >> > > >> > > >> >
> >> > > >> > > >> > > @RunWith(ApplicationComposer.class)
> >> > > >> > > >> > > public class EchoServiceTest {
> >> > > >> > > >> > >
> >> > > >> > > >> > >     @Mock
> >> > > >> > > >> > >     private DummyService dummyService;
> >> > > >> > > >> > >     @EJB
> >> > > >> > > >> > >     private EchoService echoService;
> >> > > >> > > >> > >     @Before
> >> > > >> > > >> > >     public void init() {
> >> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
> >> > > >> > > >> > >     }
> >> > > >> > > >> > >
> >> > > >> > > >> > >     @Module
> >> > > >> > > >> > >     public EjbJar createEjbJar() {
> >> > > >> > > >> > >         EjbJar ejbJar = new
> >> > > >> > EjbJar(this.getClass().getSimpleName());
> >> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
> >> > > >> > > >> StatelessBean(EchoService.class));
> >> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> >> > > >> > > >> > >         return ejbJar;
> >> > > >> > > >> > >     }
> >> > > >> > > >> >
> >> > > >> > > >>
> >> > > >> > > >
> >> > > >> > > >
> >> > > >> > >
> >> > > >> >
> >> > > >>
> >> > > >
> >> > >
> >> >
> >>
> >
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
added org.apache.openejb.injection.FallbackPropertyInjector which should
manage failling injections (so you can inject a mock) and in application
composer you can return your injector annotating @MockInjector a method.

i didnt test too much, was just trying to find a way which doesn't impact
the core in particular from a perf point of view. this one should be fine
for @EJB injections.

It will probably be reworked a bit but would like to discuss a bit before.

For mockito the impl could use a map (injection.getTarget().getName() + "/"
+ injection.getName() as key, mock as value)

wdyt?

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/8/31 Romain Manni-Bucau <rm...@gmail.com>

> Nothing against it but here is my opinion,
>
> JEE is designed to be testable so no need of any "complicated for nothing"
> framework.
>
> For me mockito answer to a different need.
>
> For a cdi sample we have an example on trunk using alternatives ans
> stereotypes.
>
> - Romain
> Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a écrit :
>
> I'm agree but tests with arquilian take more time than simple unit tests.
>> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a
>> écrit :
>>
>> > Waiting for Romain's answer, but I guess it will be. Mocking is an old
>> > school solution ;-)
>> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and so
>> on,
>> > it's far easier to get simple integration tests. So the need to really
>> > write unit tests is smaller.
>> >
>> > Just some thoughts.
>> > Romain is currently on holidays, but quite sure he will find a hack for
>> you
>> > when he'll be back ;-)
>> >
>> > Jean-Louis
>> >
>> >
>> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
>> >
>> > > Well, in fact I'm not sure to go in the right way.
>> > >
>> > > I wan't to make the demonstration that jee6 can now replace spring.
>> > > One thing very interesting in spring is about that faculty to make
>> > > "unit-test" between real unit-test and integration tests with
>> > > @Configuration. I wanted to make the same thing.
>> > >
>> > > I can reproduce it with cdi-unit for example, but I wan't to use EJB
>> > > 3.1 too (transaction, and security), my research show me the OpenEjb
>> > > stack with the ApplicationComposer runner, this is very cool !
>> > >
>> > > Well to get back to my main subject. In fact that should be very nice
>> > > to be able to use Mocks from Mockito instead of the instances produced
>> > > by the container.
>> > >
>> > > Example : I have my business service a Stateless localbean, this one
>> > > use a DAO, same Stateless localbean with no interface. This DAO use a
>> > > persistence manager. As the DAO has no interface, I cannot replace his
>> > > implementation in the @Module by writing a mock by hand, the simple
>> > > extended class do not work. The problem is that this dao absolutely
>> > > need the EntityManager in this case, so I need to provide it, I'm
>> > > going to write an integration test, not a unit test.
>> > >
>> > > I'm currently studying the openjeb code to find a solution, made some
>> > > things but no results for the moment.
>> > >
>> > > That would be nice to ben able to make someting like this :
>> > >
>> > >  ejbJar.addEnterpriseBean(new
>> > > MockStatelessBean(DAO.class,daoMockInstance));
>> > >
>> > > If anybody have an idea or suggestion :)
>> > >
>> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
>> > > > I dont think so (the proxy). The need is more than it: vetoing a
>> bean
>> > > > deployment (not managed today i think) + mocking (i would like to
>> avoid
>> > > to
>> > > > update core for this need)
>> > > >
>> > > > - Romain
>> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a
>> > > écrit :
>> > > >
>> > > >> Romain,
>> > > >>
>> > > >> maybe a proxy handler on top of the business interface can do the
>> > trick.
>> > > >> Not sure it will work, but it should be able to provide any
>> > > >> implementation
>> > > >> even a mock to a business interface.
>> > > >>
>> > > >> The need is there, so that be great to have a look.
>> > > >> Any other ideas?
>> > > >>
>> > > >> Jean-Louis
>> > > >>
>> > > >>
>> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
>> > > >>
>> > > >> > Hmm, not sure i get what is hard, never tried it but using
>> > alternative
>> > > >> > of
>> > > >> > cdi or specialize should do the trick.
>> > > >> >
>> > > >> > To use mockito you need to change deep in the code the way ejb
>> are
>> > > >> > instantiated+scanned (doable but i really think it is easier to
>> mock
>> > > an
>> > > >> ejb
>> > > >> > than using mockito)
>> > > >> >
>> > > >> > Another lazy solution is to divide your module in submodule to be
>> > > >> > modular
>> > > >> > even for testing
>> > > >> >
>> > > >> > - Romain
>> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a
>> > > écrit
>> > > >> > :
>> > > >> >
>> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
>> > > >> > >
>> > > >> > > Why I want to use mockito ? Simply because I wan't to make some
>> > unit
>> > > >> > tests
>> > > >> > > without have to get all.
>> > > >> > >
>> > > >> > > For example I wan't to test a business service, a stateless
>> ejb.
>> > > This
>> > > >> one
>> > > >> > > use another one that make some things with mms, databases and
>> > other
>> > > >> > things.
>> > > >> > > The only things I wan't to test are the calling sequences to
>> the
>> > > >> > > second
>> > > >> > ejb
>> > > >> > > by the first one. That's why I wan't to use mockito as I don't
>> > need
>> > > >> > > to
>> > > >> > > prepare the resources (jms db). if I use a class that extends
>> the
>> > > >> second
>> > > >> > > ejb, it will try to inject the resources I don't need....
>> > > >> > >
>> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
>> > > >> > >
>> > > >> > > > Mockito is more easy to use than extends the ejb class.
>> > > >> > > >
>> > > >> > > > I will search for a way to make that works.
>> > > >> > > >
>> > > >> > > >
>> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
>> > > >> > > >
>> > > >> > > >> Hi,
>> > > >> > > >>
>> > > >> > > >> Generally we mock services replacing them by child or
>> another
>> > > >> > > >> implementation so no need of mockito and you keep injection
>> > > >> > > >> consistent...but you can use mockito to implement this other
>> > > class
>> > > >> > with
>> > > >> > > a
>> > > >> > > >> kind of delegate pattern.
>> > > >> > > >>
>> > > >> > > >> - Romain
>> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
>> yann.blazart@bycode.fr>
>> > a
>> > > >> > écrit
>> > > >> > > :
>> > > >> > > >>
>> > > >> > > >> > Hi , is there a way to use Mockito instance with
>> Application
>> > > >> > composer
>> > > >> > > >> for
>> > > >> > > >> > unit tests ?
>> > > >> > > >> >
>> > > >> > > >> > For example here, is there a solution to use the mockito
>> > > >> > > >> > instance
>> > > >> > for
>> > > >> > > >> the
>> > > >> > > >> > EjbJar ? :
>> > > >> > > >> >
>> > > >> > > >> >
>> > > >> > > >> > > @RunWith(ApplicationComposer.class)
>> > > >> > > >> > > public class EchoServiceTest {
>> > > >> > > >> > >
>> > > >> > > >> > >     @Mock
>> > > >> > > >> > >     private DummyService dummyService;
>> > > >> > > >> > >     @EJB
>> > > >> > > >> > >     private EchoService echoService;
>> > > >> > > >> > >     @Before
>> > > >> > > >> > >     public void init() {
>> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
>> > > >> > > >> > >     }
>> > > >> > > >> > >
>> > > >> > > >> > >     @Module
>> > > >> > > >> > >     public EjbJar createEjbJar() {
>> > > >> > > >> > >         EjbJar ejbJar = new
>> > > >> > EjbJar(this.getClass().getSimpleName());
>> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
>> > > >> > > >> StatelessBean(EchoService.class));
>> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
>> > > >> > > >> > >         return ejbJar;
>> > > >> > > >> > >     }
>> > > >> > > >> >
>> > > >> > > >>
>> > > >> > > >
>> > > >> > > >
>> > > >> > >
>> > > >> >
>> > > >>
>> > > >
>> > >
>> >
>>
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Nothing against it but here is my opinion,

JEE is designed to be testable so no need of any "complicated for nothing"
framework.

For me mockito answer to a different need.

For a cdi sample we have an example on trunk using alternatives ans
stereotypes.

- Romain
Le 31 août 2012 12:45, "Yann Blazart" <ya...@bycode.fr> a écrit :

> I'm agree but tests with arquilian take more time than simple unit tests.
> Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a écrit
> :
>
> > Waiting for Romain's answer, but I guess it will be. Mocking is an old
> > school solution ;-)
> > Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and so on,
> > it's far easier to get simple integration tests. So the need to really
> > write unit tests is smaller.
> >
> > Just some thoughts.
> > Romain is currently on holidays, but quite sure he will find a hack for
> you
> > when he'll be back ;-)
> >
> > Jean-Louis
> >
> >
> > 2012/8/31 Yann Blazart <ya...@bycode.fr>
> >
> > > Well, in fact I'm not sure to go in the right way.
> > >
> > > I wan't to make the demonstration that jee6 can now replace spring.
> > > One thing very interesting in spring is about that faculty to make
> > > "unit-test" between real unit-test and integration tests with
> > > @Configuration. I wanted to make the same thing.
> > >
> > > I can reproduce it with cdi-unit for example, but I wan't to use EJB
> > > 3.1 too (transaction, and security), my research show me the OpenEjb
> > > stack with the ApplicationComposer runner, this is very cool !
> > >
> > > Well to get back to my main subject. In fact that should be very nice
> > > to be able to use Mocks from Mockito instead of the instances produced
> > > by the container.
> > >
> > > Example : I have my business service a Stateless localbean, this one
> > > use a DAO, same Stateless localbean with no interface. This DAO use a
> > > persistence manager. As the DAO has no interface, I cannot replace his
> > > implementation in the @Module by writing a mock by hand, the simple
> > > extended class do not work. The problem is that this dao absolutely
> > > need the EntityManager in this case, so I need to provide it, I'm
> > > going to write an integration test, not a unit test.
> > >
> > > I'm currently studying the openjeb code to find a solution, made some
> > > things but no results for the moment.
> > >
> > > That would be nice to ben able to make someting like this :
> > >
> > >  ejbJar.addEnterpriseBean(new
> > > MockStatelessBean(DAO.class,daoMockInstance));
> > >
> > > If anybody have an idea or suggestion :)
> > >
> > > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> > > > I dont think so (the proxy). The need is more than it: vetoing a bean
> > > > deployment (not managed today i think) + mocking (i would like to
> avoid
> > > to
> > > > update core for this need)
> > > >
> > > > - Romain
> > > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> > > écrit :
> > > >
> > > >> Romain,
> > > >>
> > > >> maybe a proxy handler on top of the business interface can do the
> > trick.
> > > >> Not sure it will work, but it should be able to provide any
> > > >> implementation
> > > >> even a mock to a business interface.
> > > >>
> > > >> The need is there, so that be great to have a look.
> > > >> Any other ideas?
> > > >>
> > > >> Jean-Louis
> > > >>
> > > >>
> > > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> > > >>
> > > >> > Hmm, not sure i get what is hard, never tried it but using
> > alternative
> > > >> > of
> > > >> > cdi or specialize should do the trick.
> > > >> >
> > > >> > To use mockito you need to change deep in the code the way ejb are
> > > >> > instantiated+scanned (doable but i really think it is easier to
> mock
> > > an
> > > >> ejb
> > > >> > than using mockito)
> > > >> >
> > > >> > Another lazy solution is to divide your module in submodule to be
> > > >> > modular
> > > >> > even for testing
> > > >> >
> > > >> > - Romain
> > > >> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a
> > > écrit
> > > >> > :
> > > >> >
> > > >> > > Wo I'm studying applicationComposer code. It's difficult.
> > > >> > >
> > > >> > > Why I want to use mockito ? Simply because I wan't to make some
> > unit
> > > >> > tests
> > > >> > > without have to get all.
> > > >> > >
> > > >> > > For example I wan't to test a business service, a stateless ejb.
> > > This
> > > >> one
> > > >> > > use another one that make some things with mms, databases and
> > other
> > > >> > things.
> > > >> > > The only things I wan't to test are the calling sequences to the
> > > >> > > second
> > > >> > ejb
> > > >> > > by the first one. That's why I wan't to use mockito as I don't
> > need
> > > >> > > to
> > > >> > > prepare the resources (jms db). if I use a class that extends
> the
> > > >> second
> > > >> > > ejb, it will try to inject the resources I don't need....
> > > >> > >
> > > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> > > >> > >
> > > >> > > > Mockito is more easy to use than extends the ejb class.
> > > >> > > >
> > > >> > > > I will search for a way to make that works.
> > > >> > > >
> > > >> > > >
> > > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> > > >> > > >
> > > >> > > >> Hi,
> > > >> > > >>
> > > >> > > >> Generally we mock services replacing them by child or another
> > > >> > > >> implementation so no need of mockito and you keep injection
> > > >> > > >> consistent...but you can use mockito to implement this other
> > > class
> > > >> > with
> > > >> > > a
> > > >> > > >> kind of delegate pattern.
> > > >> > > >>
> > > >> > > >> - Romain
> > > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <
> yann.blazart@bycode.fr>
> > a
> > > >> > écrit
> > > >> > > :
> > > >> > > >>
> > > >> > > >> > Hi , is there a way to use Mockito instance with
> Application
> > > >> > composer
> > > >> > > >> for
> > > >> > > >> > unit tests ?
> > > >> > > >> >
> > > >> > > >> > For example here, is there a solution to use the mockito
> > > >> > > >> > instance
> > > >> > for
> > > >> > > >> the
> > > >> > > >> > EjbJar ? :
> > > >> > > >> >
> > > >> > > >> >
> > > >> > > >> > > @RunWith(ApplicationComposer.class)
> > > >> > > >> > > public class EchoServiceTest {
> > > >> > > >> > >
> > > >> > > >> > >     @Mock
> > > >> > > >> > >     private DummyService dummyService;
> > > >> > > >> > >     @EJB
> > > >> > > >> > >     private EchoService echoService;
> > > >> > > >> > >     @Before
> > > >> > > >> > >     public void init() {
> > > >> > > >> > >         MockitoAnnotations.initMocks(this);
> > > >> > > >> > >     }
> > > >> > > >> > >
> > > >> > > >> > >     @Module
> > > >> > > >> > >     public EjbJar createEjbJar() {
> > > >> > > >> > >         EjbJar ejbJar = new
> > > >> > EjbJar(this.getClass().getSimpleName());
> > > >> > > >> > >         ejbJar.addEnterpriseBean(new
> > > >> > > >> StatelessBean(EchoService.class));
> > > >> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> > > >> > > >> > >         return ejbJar;
> > > >> > > >> > >     }
> > > >> > > >> >
> > > >> > > >>
> > > >> > > >
> > > >> > > >
> > > >> > >
> > > >> >
> > > >>
> > > >
> > >
> >
>

Re: OpenEJB Mockito unit test

Posted by Yann Blazart <ya...@bycode.fr>.
I'm agree but tests with arquilian take more time than simple unit tests.
Le 31 août 2012 11:21, "Jean-Louis MONTEIRO" <je...@gmail.com> a écrit :

> Waiting for Romain's answer, but I guess it will be. Mocking is an old
> school solution ;-)
> Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and so on,
> it's far easier to get simple integration tests. So the need to really
> write unit tests is smaller.
>
> Just some thoughts.
> Romain is currently on holidays, but quite sure he will find a hack for you
> when he'll be back ;-)
>
> Jean-Louis
>
>
> 2012/8/31 Yann Blazart <ya...@bycode.fr>
>
> > Well, in fact I'm not sure to go in the right way.
> >
> > I wan't to make the demonstration that jee6 can now replace spring.
> > One thing very interesting in spring is about that faculty to make
> > "unit-test" between real unit-test and integration tests with
> > @Configuration. I wanted to make the same thing.
> >
> > I can reproduce it with cdi-unit for example, but I wan't to use EJB
> > 3.1 too (transaction, and security), my research show me the OpenEjb
> > stack with the ApplicationComposer runner, this is very cool !
> >
> > Well to get back to my main subject. In fact that should be very nice
> > to be able to use Mocks from Mockito instead of the instances produced
> > by the container.
> >
> > Example : I have my business service a Stateless localbean, this one
> > use a DAO, same Stateless localbean with no interface. This DAO use a
> > persistence manager. As the DAO has no interface, I cannot replace his
> > implementation in the @Module by writing a mock by hand, the simple
> > extended class do not work. The problem is that this dao absolutely
> > need the EntityManager in this case, so I need to provide it, I'm
> > going to write an integration test, not a unit test.
> >
> > I'm currently studying the openjeb code to find a solution, made some
> > things but no results for the moment.
> >
> > That would be nice to ben able to make someting like this :
> >
> >  ejbJar.addEnterpriseBean(new
> > MockStatelessBean(DAO.class,daoMockInstance));
> >
> > If anybody have an idea or suggestion :)
> >
> > 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> > > I dont think so (the proxy). The need is more than it: vetoing a bean
> > > deployment (not managed today i think) + mocking (i would like to avoid
> > to
> > > update core for this need)
> > >
> > > - Romain
> > > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> > écrit :
> > >
> > >> Romain,
> > >>
> > >> maybe a proxy handler on top of the business interface can do the
> trick.
> > >> Not sure it will work, but it should be able to provide any
> > >> implementation
> > >> even a mock to a business interface.
> > >>
> > >> The need is there, so that be great to have a look.
> > >> Any other ideas?
> > >>
> > >> Jean-Louis
> > >>
> > >>
> > >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> > >>
> > >> > Hmm, not sure i get what is hard, never tried it but using
> alternative
> > >> > of
> > >> > cdi or specialize should do the trick.
> > >> >
> > >> > To use mockito you need to change deep in the code the way ejb are
> > >> > instantiated+scanned (doable but i really think it is easier to mock
> > an
> > >> ejb
> > >> > than using mockito)
> > >> >
> > >> > Another lazy solution is to divide your module in submodule to be
> > >> > modular
> > >> > even for testing
> > >> >
> > >> > - Romain
> > >> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a
> > écrit
> > >> > :
> > >> >
> > >> > > Wo I'm studying applicationComposer code. It's difficult.
> > >> > >
> > >> > > Why I want to use mockito ? Simply because I wan't to make some
> unit
> > >> > tests
> > >> > > without have to get all.
> > >> > >
> > >> > > For example I wan't to test a business service, a stateless ejb.
> > This
> > >> one
> > >> > > use another one that make some things with mms, databases and
> other
> > >> > things.
> > >> > > The only things I wan't to test are the calling sequences to the
> > >> > > second
> > >> > ejb
> > >> > > by the first one. That's why I wan't to use mockito as I don't
> need
> > >> > > to
> > >> > > prepare the resources (jms db). if I use a class that extends the
> > >> second
> > >> > > ejb, it will try to inject the resources I don't need....
> > >> > >
> > >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> > >> > >
> > >> > > > Mockito is more easy to use than extends the ejb class.
> > >> > > >
> > >> > > > I will search for a way to make that works.
> > >> > > >
> > >> > > >
> > >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> > >> > > >
> > >> > > >> Hi,
> > >> > > >>
> > >> > > >> Generally we mock services replacing them by child or another
> > >> > > >> implementation so no need of mockito and you keep injection
> > >> > > >> consistent...but you can use mockito to implement this other
> > class
> > >> > with
> > >> > > a
> > >> > > >> kind of delegate pattern.
> > >> > > >>
> > >> > > >> - Romain
> > >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr>
> a
> > >> > écrit
> > >> > > :
> > >> > > >>
> > >> > > >> > Hi , is there a way to use Mockito instance with Application
> > >> > composer
> > >> > > >> for
> > >> > > >> > unit tests ?
> > >> > > >> >
> > >> > > >> > For example here, is there a solution to use the mockito
> > >> > > >> > instance
> > >> > for
> > >> > > >> the
> > >> > > >> > EjbJar ? :
> > >> > > >> >
> > >> > > >> >
> > >> > > >> > > @RunWith(ApplicationComposer.class)
> > >> > > >> > > public class EchoServiceTest {
> > >> > > >> > >
> > >> > > >> > >     @Mock
> > >> > > >> > >     private DummyService dummyService;
> > >> > > >> > >     @EJB
> > >> > > >> > >     private EchoService echoService;
> > >> > > >> > >     @Before
> > >> > > >> > >     public void init() {
> > >> > > >> > >         MockitoAnnotations.initMocks(this);
> > >> > > >> > >     }
> > >> > > >> > >
> > >> > > >> > >     @Module
> > >> > > >> > >     public EjbJar createEjbJar() {
> > >> > > >> > >         EjbJar ejbJar = new
> > >> > EjbJar(this.getClass().getSimpleName());
> > >> > > >> > >         ejbJar.addEnterpriseBean(new
> > >> > > >> StatelessBean(EchoService.class));
> > >> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> > >> > > >> > >         return ejbJar;
> > >> > > >> > >     }
> > >> > > >> >
> > >> > > >>
> > >> > > >
> > >> > > >
> > >> > >
> > >> >
> > >>
> > >
> >
>

Re: OpenEJB Mockito unit test

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Waiting for Romain's answer, but I guess it will be. Mocking is an old
school solution ;-)
Indeed, nowadays, and mainly thanks to EJB 3 lite, Arquillian, and so on,
it's far easier to get simple integration tests. So the need to really
write unit tests is smaller.

Just some thoughts.
Romain is currently on holidays, but quite sure he will find a hack for you
when he'll be back ;-)

Jean-Louis


2012/8/31 Yann Blazart <ya...@bycode.fr>

> Well, in fact I'm not sure to go in the right way.
>
> I wan't to make the demonstration that jee6 can now replace spring.
> One thing very interesting in spring is about that faculty to make
> "unit-test" between real unit-test and integration tests with
> @Configuration. I wanted to make the same thing.
>
> I can reproduce it with cdi-unit for example, but I wan't to use EJB
> 3.1 too (transaction, and security), my research show me the OpenEjb
> stack with the ApplicationComposer runner, this is very cool !
>
> Well to get back to my main subject. In fact that should be very nice
> to be able to use Mocks from Mockito instead of the instances produced
> by the container.
>
> Example : I have my business service a Stateless localbean, this one
> use a DAO, same Stateless localbean with no interface. This DAO use a
> persistence manager. As the DAO has no interface, I cannot replace his
> implementation in the @Module by writing a mock by hand, the simple
> extended class do not work. The problem is that this dao absolutely
> need the EntityManager in this case, so I need to provide it, I'm
> going to write an integration test, not a unit test.
>
> I'm currently studying the openjeb code to find a solution, made some
> things but no results for the moment.
>
> That would be nice to ben able to make someting like this :
>
>  ejbJar.addEnterpriseBean(new
> MockStatelessBean(DAO.class,daoMockInstance));
>
> If anybody have an idea or suggestion :)
>
> 2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> > I dont think so (the proxy). The need is more than it: vetoing a bean
> > deployment (not managed today i think) + mocking (i would like to avoid
> to
> > update core for this need)
> >
> > - Romain
> > Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a
> écrit :
> >
> >> Romain,
> >>
> >> maybe a proxy handler on top of the business interface can do the trick.
> >> Not sure it will work, but it should be able to provide any
> >> implementation
> >> even a mock to a business interface.
> >>
> >> The need is there, so that be great to have a look.
> >> Any other ideas?
> >>
> >> Jean-Louis
> >>
> >>
> >> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
> >>
> >> > Hmm, not sure i get what is hard, never tried it but using alternative
> >> > of
> >> > cdi or specialize should do the trick.
> >> >
> >> > To use mockito you need to change deep in the code the way ejb are
> >> > instantiated+scanned (doable but i really think it is easier to mock
> an
> >> ejb
> >> > than using mockito)
> >> >
> >> > Another lazy solution is to divide your module in submodule to be
> >> > modular
> >> > even for testing
> >> >
> >> > - Romain
> >> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a
> écrit
> >> > :
> >> >
> >> > > Wo I'm studying applicationComposer code. It's difficult.
> >> > >
> >> > > Why I want to use mockito ? Simply because I wan't to make some unit
> >> > tests
> >> > > without have to get all.
> >> > >
> >> > > For example I wan't to test a business service, a stateless ejb.
> This
> >> one
> >> > > use another one that make some things with mms, databases and other
> >> > things.
> >> > > The only things I wan't to test are the calling sequences to the
> >> > > second
> >> > ejb
> >> > > by the first one. That's why I wan't to use mockito as I don't need
> >> > > to
> >> > > prepare the resources (jms db). if I use a class that extends the
> >> second
> >> > > ejb, it will try to inject the resources I don't need....
> >> > >
> >> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> >> > >
> >> > > > Mockito is more easy to use than extends the ejb class.
> >> > > >
> >> > > > I will search for a way to make that works.
> >> > > >
> >> > > >
> >> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> >> > > >
> >> > > >> Hi,
> >> > > >>
> >> > > >> Generally we mock services replacing them by child or another
> >> > > >> implementation so no need of mockito and you keep injection
> >> > > >> consistent...but you can use mockito to implement this other
> class
> >> > with
> >> > > a
> >> > > >> kind of delegate pattern.
> >> > > >>
> >> > > >> - Romain
> >> > > >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a
> >> > écrit
> >> > > :
> >> > > >>
> >> > > >> > Hi , is there a way to use Mockito instance with Application
> >> > composer
> >> > > >> for
> >> > > >> > unit tests ?
> >> > > >> >
> >> > > >> > For example here, is there a solution to use the mockito
> >> > > >> > instance
> >> > for
> >> > > >> the
> >> > > >> > EjbJar ? :
> >> > > >> >
> >> > > >> >
> >> > > >> > > @RunWith(ApplicationComposer.class)
> >> > > >> > > public class EchoServiceTest {
> >> > > >> > >
> >> > > >> > >     @Mock
> >> > > >> > >     private DummyService dummyService;
> >> > > >> > >     @EJB
> >> > > >> > >     private EchoService echoService;
> >> > > >> > >     @Before
> >> > > >> > >     public void init() {
> >> > > >> > >         MockitoAnnotations.initMocks(this);
> >> > > >> > >     }
> >> > > >> > >
> >> > > >> > >     @Module
> >> > > >> > >     public EjbJar createEjbJar() {
> >> > > >> > >         EjbJar ejbJar = new
> >> > EjbJar(this.getClass().getSimpleName());
> >> > > >> > >         ejbJar.addEnterpriseBean(new
> >> > > >> StatelessBean(EchoService.class));
> >> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> >> > > >> > >         return ejbJar;
> >> > > >> > >     }
> >> > > >> >
> >> > > >>
> >> > > >
> >> > > >
> >> > >
> >> >
> >>
> >
>

Re: OpenEJB Mockito unit test

Posted by Yann Blazart <ya...@bycode.fr>.
Well, in fact I'm not sure to go in the right way.

I wan't to make the demonstration that jee6 can now replace spring.
One thing very interesting in spring is about that faculty to make
"unit-test" between real unit-test and integration tests with
@Configuration. I wanted to make the same thing.

I can reproduce it with cdi-unit for example, but I wan't to use EJB
3.1 too (transaction, and security), my research show me the OpenEjb
stack with the ApplicationComposer runner, this is very cool !

Well to get back to my main subject. In fact that should be very nice
to be able to use Mocks from Mockito instead of the instances produced
by the container.

Example : I have my business service a Stateless localbean, this one
use a DAO, same Stateless localbean with no interface. This DAO use a
persistence manager. As the DAO has no interface, I cannot replace his
implementation in the @Module by writing a mock by hand, the simple
extended class do not work. The problem is that this dao absolutely
need the EntityManager in this case, so I need to provide it, I'm
going to write an integration test, not a unit test.

I'm currently studying the openjeb code to find a solution, made some
things but no results for the moment.

That would be nice to ben able to make someting like this :

 ejbJar.addEnterpriseBean(new MockStatelessBean(DAO.class,daoMockInstance));

If anybody have an idea or suggestion :)

2012/8/31, Romain Manni-Bucau <rm...@gmail.com>:
> I dont think so (the proxy). The need is more than it: vetoing a bean
> deployment (not managed today i think) + mocking (i would like to avoid to
> update core for this need)
>
> - Romain
> Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a écrit :
>
>> Romain,
>>
>> maybe a proxy handler on top of the business interface can do the trick.
>> Not sure it will work, but it should be able to provide any
>> implementation
>> even a mock to a business interface.
>>
>> The need is there, so that be great to have a look.
>> Any other ideas?
>>
>> Jean-Louis
>>
>>
>> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
>>
>> > Hmm, not sure i get what is hard, never tried it but using alternative
>> > of
>> > cdi or specialize should do the trick.
>> >
>> > To use mockito you need to change deep in the code the way ejb are
>> > instantiated+scanned (doable but i really think it is easier to mock an
>> ejb
>> > than using mockito)
>> >
>> > Another lazy solution is to divide your module in submodule to be
>> > modular
>> > even for testing
>> >
>> > - Romain
>> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a écrit
>> > :
>> >
>> > > Wo I'm studying applicationComposer code. It's difficult.
>> > >
>> > > Why I want to use mockito ? Simply because I wan't to make some unit
>> > tests
>> > > without have to get all.
>> > >
>> > > For example I wan't to test a business service, a stateless ejb. This
>> one
>> > > use another one that make some things with mms, databases and other
>> > things.
>> > > The only things I wan't to test are the calling sequences to the
>> > > second
>> > ejb
>> > > by the first one. That's why I wan't to use mockito as I don't need
>> > > to
>> > > prepare the resources (jms db). if I use a class that extends the
>> second
>> > > ejb, it will try to inject the resources I don't need....
>> > >
>> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
>> > >
>> > > > Mockito is more easy to use than extends the ejb class.
>> > > >
>> > > > I will search for a way to make that works.
>> > > >
>> > > >
>> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
>> > > >
>> > > >> Hi,
>> > > >>
>> > > >> Generally we mock services replacing them by child or another
>> > > >> implementation so no need of mockito and you keep injection
>> > > >> consistent...but you can use mockito to implement this other class
>> > with
>> > > a
>> > > >> kind of delegate pattern.
>> > > >>
>> > > >> - Romain
>> > > >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a
>> > écrit
>> > > :
>> > > >>
>> > > >> > Hi , is there a way to use Mockito instance with Application
>> > composer
>> > > >> for
>> > > >> > unit tests ?
>> > > >> >
>> > > >> > For example here, is there a solution to use the mockito
>> > > >> > instance
>> > for
>> > > >> the
>> > > >> > EjbJar ? :
>> > > >> >
>> > > >> >
>> > > >> > > @RunWith(ApplicationComposer.class)
>> > > >> > > public class EchoServiceTest {
>> > > >> > >
>> > > >> > >     @Mock
>> > > >> > >     private DummyService dummyService;
>> > > >> > >     @EJB
>> > > >> > >     private EchoService echoService;
>> > > >> > >     @Before
>> > > >> > >     public void init() {
>> > > >> > >         MockitoAnnotations.initMocks(this);
>> > > >> > >     }
>> > > >> > >
>> > > >> > >     @Module
>> > > >> > >     public EjbJar createEjbJar() {
>> > > >> > >         EjbJar ejbJar = new
>> > EjbJar(this.getClass().getSimpleName());
>> > > >> > >         ejbJar.addEnterpriseBean(new
>> > > >> StatelessBean(EchoService.class));
>> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
>> > > >> > >         return ejbJar;
>> > > >> > >     }
>> > > >> >
>> > > >>
>> > > >
>> > > >
>> > >
>> >
>>
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I dont think so (the proxy). The need is more than it: vetoing a bean
deployment (not managed today i think) + mocking (i would like to avoid to
update core for this need)

- Romain
Le 31 août 2012 09:15, "Jean-Louis MONTEIRO" <je...@gmail.com> a écrit :

> Romain,
>
> maybe a proxy handler on top of the business interface can do the trick.
> Not sure it will work, but it should be able to provide any implementation
> even a mock to a business interface.
>
> The need is there, so that be great to have a look.
> Any other ideas?
>
> Jean-Louis
>
>
> 2012/8/30 Romain Manni-Bucau <rm...@gmail.com>
>
> > Hmm, not sure i get what is hard, never tried it but using alternative of
> > cdi or specialize should do the trick.
> >
> > To use mockito you need to change deep in the code the way ejb are
> > instantiated+scanned (doable but i really think it is easier to mock an
> ejb
> > than using mockito)
> >
> > Another lazy solution is to divide your module in submodule to be modular
> > even for testing
> >
> > - Romain
> > Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a écrit :
> >
> > > Wo I'm studying applicationComposer code. It's difficult.
> > >
> > > Why I want to use mockito ? Simply because I wan't to make some unit
> > tests
> > > without have to get all.
> > >
> > > For example I wan't to test a business service, a stateless ejb. This
> one
> > > use another one that make some things with mms, databases and other
> > things.
> > > The only things I wan't to test are the calling sequences to the second
> > ejb
> > > by the first one. That's why I wan't to use mockito as I don't need to
> > > prepare the resources (jms db). if I use a class that extends the
> second
> > > ejb, it will try to inject the resources I don't need....
> > >
> > > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> > >
> > > > Mockito is more easy to use than extends the ejb class.
> > > >
> > > > I will search for a way to make that works.
> > > >
> > > >
> > > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> > > >
> > > >> Hi,
> > > >>
> > > >> Generally we mock services replacing them by child or another
> > > >> implementation so no need of mockito and you keep injection
> > > >> consistent...but you can use mockito to implement this other class
> > with
> > > a
> > > >> kind of delegate pattern.
> > > >>
> > > >> - Romain
> > > >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a
> > écrit
> > > :
> > > >>
> > > >> > Hi , is there a way to use Mockito instance with Application
> > composer
> > > >> for
> > > >> > unit tests ?
> > > >> >
> > > >> > For example here, is there a solution to use the mockito instance
> > for
> > > >> the
> > > >> > EjbJar ? :
> > > >> >
> > > >> >
> > > >> > > @RunWith(ApplicationComposer.class)
> > > >> > > public class EchoServiceTest {
> > > >> > >
> > > >> > >     @Mock
> > > >> > >     private DummyService dummyService;
> > > >> > >     @EJB
> > > >> > >     private EchoService echoService;
> > > >> > >     @Before
> > > >> > >     public void init() {
> > > >> > >         MockitoAnnotations.initMocks(this);
> > > >> > >     }
> > > >> > >
> > > >> > >     @Module
> > > >> > >     public EjbJar createEjbJar() {
> > > >> > >         EjbJar ejbJar = new
> > EjbJar(this.getClass().getSimpleName());
> > > >> > >         ejbJar.addEnterpriseBean(new
> > > >> StatelessBean(EchoService.class));
> > > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> > > >> > >         return ejbJar;
> > > >> > >     }
> > > >> >
> > > >>
> > > >
> > > >
> > >
> >
>

Re: OpenEJB Mockito unit test

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Romain,

maybe a proxy handler on top of the business interface can do the trick.
Not sure it will work, but it should be able to provide any implementation
even a mock to a business interface.

The need is there, so that be great to have a look.
Any other ideas?

Jean-Louis


2012/8/30 Romain Manni-Bucau <rm...@gmail.com>

> Hmm, not sure i get what is hard, never tried it but using alternative of
> cdi or specialize should do the trick.
>
> To use mockito you need to change deep in the code the way ejb are
> instantiated+scanned (doable but i really think it is easier to mock an ejb
> than using mockito)
>
> Another lazy solution is to divide your module in submodule to be modular
> even for testing
>
> - Romain
> Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a écrit :
>
> > Wo I'm studying applicationComposer code. It's difficult.
> >
> > Why I want to use mockito ? Simply because I wan't to make some unit
> tests
> > without have to get all.
> >
> > For example I wan't to test a business service, a stateless ejb. This one
> > use another one that make some things with mms, databases and other
> things.
> > The only things I wan't to test are the calling sequences to the second
> ejb
> > by the first one. That's why I wan't to use mockito as I don't need to
> > prepare the resources (jms db). if I use a class that extends the second
> > ejb, it will try to inject the resources I don't need....
> >
> > 2012/8/28 Yann Blazart <ya...@bycode.fr>
> >
> > > Mockito is more easy to use than extends the ejb class.
> > >
> > > I will search for a way to make that works.
> > >
> > >
> > > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> > >
> > >> Hi,
> > >>
> > >> Generally we mock services replacing them by child or another
> > >> implementation so no need of mockito and you keep injection
> > >> consistent...but you can use mockito to implement this other class
> with
> > a
> > >> kind of delegate pattern.
> > >>
> > >> - Romain
> > >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a
> écrit
> > :
> > >>
> > >> > Hi , is there a way to use Mockito instance with Application
> composer
> > >> for
> > >> > unit tests ?
> > >> >
> > >> > For example here, is there a solution to use the mockito instance
> for
> > >> the
> > >> > EjbJar ? :
> > >> >
> > >> >
> > >> > > @RunWith(ApplicationComposer.class)
> > >> > > public class EchoServiceTest {
> > >> > >
> > >> > >     @Mock
> > >> > >     private DummyService dummyService;
> > >> > >     @EJB
> > >> > >     private EchoService echoService;
> > >> > >     @Before
> > >> > >     public void init() {
> > >> > >         MockitoAnnotations.initMocks(this);
> > >> > >     }
> > >> > >
> > >> > >     @Module
> > >> > >     public EjbJar createEjbJar() {
> > >> > >         EjbJar ejbJar = new
> EjbJar(this.getClass().getSimpleName());
> > >> > >         ejbJar.addEnterpriseBean(new
> > >> StatelessBean(EchoService.class));
> > >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> > >> > >         return ejbJar;
> > >> > >     }
> > >> >
> > >>
> > >
> > >
> >
>

Re: OpenEJB Mockito unit test

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm, not sure i get what is hard, never tried it but using alternative of
cdi or specialize should do the trick.

To use mockito you need to change deep in the code the way ejb are
instantiated+scanned (doable but i really think it is easier to mock an ejb
than using mockito)

Another lazy solution is to divide your module in submodule to be modular
even for testing

- Romain
Le 29 août 2012 13:34, "Yann Blazart" <ya...@bycode.fr> a écrit :

> Wo I'm studying applicationComposer code. It's difficult.
>
> Why I want to use mockito ? Simply because I wan't to make some unit tests
> without have to get all.
>
> For example I wan't to test a business service, a stateless ejb. This one
> use another one that make some things with mms, databases and other things.
> The only things I wan't to test are the calling sequences to the second ejb
> by the first one. That's why I wan't to use mockito as I don't need to
> prepare the resources (jms db). if I use a class that extends the second
> ejb, it will try to inject the resources I don't need....
>
> 2012/8/28 Yann Blazart <ya...@bycode.fr>
>
> > Mockito is more easy to use than extends the ejb class.
> >
> > I will search for a way to make that works.
> >
> >
> > 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
> >
> >> Hi,
> >>
> >> Generally we mock services replacing them by child or another
> >> implementation so no need of mockito and you keep injection
> >> consistent...but you can use mockito to implement this other class with
> a
> >> kind of delegate pattern.
> >>
> >> - Romain
> >> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a écrit
> :
> >>
> >> > Hi , is there a way to use Mockito instance with Application composer
> >> for
> >> > unit tests ?
> >> >
> >> > For example here, is there a solution to use the mockito instance for
> >> the
> >> > EjbJar ? :
> >> >
> >> >
> >> > > @RunWith(ApplicationComposer.class)
> >> > > public class EchoServiceTest {
> >> > >
> >> > >     @Mock
> >> > >     private DummyService dummyService;
> >> > >     @EJB
> >> > >     private EchoService echoService;
> >> > >     @Before
> >> > >     public void init() {
> >> > >         MockitoAnnotations.initMocks(this);
> >> > >     }
> >> > >
> >> > >     @Module
> >> > >     public EjbJar createEjbJar() {
> >> > >         EjbJar ejbJar = new EjbJar(this.getClass().getSimpleName());
> >> > >         ejbJar.addEnterpriseBean(new
> >> StatelessBean(EchoService.class));
> >> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> >> > >         return ejbJar;
> >> > >     }
> >> >
> >>
> >
> >
>

Re: OpenEJB Mockito unit test

Posted by Yann Blazart <ya...@bycode.fr>.
Wo I'm studying applicationComposer code. It's difficult.

Why I want to use mockito ? Simply because I wan't to make some unit tests
without have to get all.

For example I wan't to test a business service, a stateless ejb. This one
use another one that make some things with mms, databases and other things.
The only things I wan't to test are the calling sequences to the second ejb
by the first one. That's why I wan't to use mockito as I don't need to
prepare the resources (jms db). if I use a class that extends the second
ejb, it will try to inject the resources I don't need....

2012/8/28 Yann Blazart <ya...@bycode.fr>

> Mockito is more easy to use than extends the ejb class.
>
> I will search for a way to make that works.
>
>
> 2012/8/28 Romain Manni-Bucau <rm...@gmail.com>
>
>> Hi,
>>
>> Generally we mock services replacing them by child or another
>> implementation so no need of mockito and you keep injection
>> consistent...but you can use mockito to implement this other class with a
>> kind of delegate pattern.
>>
>> - Romain
>> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a écrit :
>>
>> > Hi , is there a way to use Mockito instance with Application composer
>> for
>> > unit tests ?
>> >
>> > For example here, is there a solution to use the mockito instance for
>> the
>> > EjbJar ? :
>> >
>> >
>> > > @RunWith(ApplicationComposer.class)
>> > > public class EchoServiceTest {
>> > >
>> > >     @Mock
>> > >     private DummyService dummyService;
>> > >     @EJB
>> > >     private EchoService echoService;
>> > >     @Before
>> > >     public void init() {
>> > >         MockitoAnnotations.initMocks(this);
>> > >     }
>> > >
>> > >     @Module
>> > >     public EjbJar createEjbJar() {
>> > >         EjbJar ejbJar = new EjbJar(this.getClass().getSimpleName());
>> > >         ejbJar.addEnterpriseBean(new
>> StatelessBean(EchoService.class));
>> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
>> > >         return ejbJar;
>> > >     }
>> >
>>
>
>

Re: OpenEJB Mockito unit test

Posted by Yann Blazart <ya...@bycode.fr>.
Mockito is more easy to use than extends the ejb class.

I will search for a way to make that works.

2012/8/28 Romain Manni-Bucau <rm...@gmail.com>

> Hi,
>
> Generally we mock services replacing them by child or another
> implementation so no need of mockito and you keep injection
> consistent...but you can use mockito to implement this other class with a
> kind of delegate pattern.
>
> - Romain
> Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a écrit :
>
> > Hi , is there a way to use Mockito instance with Application composer for
> > unit tests ?
> >
> > For example here, is there a solution to use the mockito instance for the
> > EjbJar ? :
> >
> >
> > > @RunWith(ApplicationComposer.class)
> > > public class EchoServiceTest {
> > >
> > >     @Mock
> > >     private DummyService dummyService;
> > >     @EJB
> > >     private EchoService echoService;
> > >     @Before
> > >     public void init() {
> > >         MockitoAnnotations.initMocks(this);
> > >     }
> > >
> > >     @Module
> > >     public EjbJar createEjbJar() {
> > >         EjbJar ejbJar = new EjbJar(this.getClass().getSimpleName());
> > >         ejbJar.addEnterpriseBean(new StatelessBean(EchoService.class));
> > > //        ejbJar.addEnterpriseBean(new StatelessBean);
> > >         return ejbJar;
> > >     }
> >
>

Re: OpenEJB Mockito unit test

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

Generally we mock services replacing them by child or another
implementation so no need of mockito and you keep injection
consistent...but you can use mockito to implement this other class with a
kind of delegate pattern.

- Romain
Le 28 août 2012 16:19, "Yann Blazart" <ya...@bycode.fr> a écrit :

> Hi , is there a way to use Mockito instance with Application composer for
> unit tests ?
>
> For example here, is there a solution to use the mockito instance for the
> EjbJar ? :
>
>
> > @RunWith(ApplicationComposer.class)
> > public class EchoServiceTest {
> >
> >     @Mock
> >     private DummyService dummyService;
> >     @EJB
> >     private EchoService echoService;
> >     @Before
> >     public void init() {
> >         MockitoAnnotations.initMocks(this);
> >     }
> >
> >     @Module
> >     public EjbJar createEjbJar() {
> >         EjbJar ejbJar = new EjbJar(this.getClass().getSimpleName());
> >         ejbJar.addEnterpriseBean(new StatelessBean(EchoService.class));
> > //        ejbJar.addEnterpriseBean(new StatelessBean);
> >         return ejbJar;
> >     }
>