You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by hwaastad <he...@waastad.org> on 2014/05/26 10:53:37 UTC
OpenEJB/TomEE and mocking
Hi,
I've been using App composer and mockito and its working nicely,
However, after reading Romains blog (which has a lot of interesting hints
regarding new feature in TomEE/OpenEJB) about ejbcontainer and junit rules
my question is this.
Is it possible to use mocking in these kinds of scenarios?
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Andy Gumbrecht <ag...@tomitribe.com>.
Yep, been down for maint. all day.
Andy.
On 26/05/2014 13:34, hwaastad wrote:
> Great!,
> I'll test it when the apache snapshot repo is alive:
>
> Return code is: 503 , ReasonPhrase:Service Temporarily Unavailable.
>
> hw
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669673.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>
--
Andy Gumbrecht
http://www.tomitribe.com
agumbrecht@tomitribe.com
https://twitter.com/AndyGeeDe
TomEE treibt Tomitribe! | http://tomee.apache.org
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Great!,
I'll test it when the apache snapshot repo is alive:
Return code is: 503 , ReasonPhrase:Service Temporarily Unavailable.
hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669673.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
yes, fallbackinjector goal is a bit different.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-29 11:00 GMT+02:00 hwaastad <he...@waastad.org>:
> Yep,
> and why not use CDI for all it's worth :-)
>
>
> Well, until next time,
> thanks.
>
> br hw
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669726.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Yep,
and why not use CDI for all it's worth :-)
Well, until next time,
thanks.
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669726.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Make me think to
http://tomee.apache.org/examples/cdi-alternative-and-stereotypes/README.html
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-29 10:08 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi Romain,
> after a few more thoughts and trying to decode youre one-liners I think I
> got what you were trying to say.
>
> I made an @alternative mock....
> It was just to think a little bit different :-)
>
> br hw
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669722.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Hi Romain,
after a few more thoughts and trying to decode youre one-liners I think I
got what you were trying to say.
I made an @alternative mock....
It was just to think a little bit different :-)
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669722.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
or
1/ dont provide impl of the mocked class
2/ inject interface
3/ configure fallbackInjector
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-27 23:43 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi,
> probably easier said than done.....at least for me :-)
> The only way it's working right now is.
>
> 1. mock implementation
> 2. inject implementation and not interface of the class to be mocked in
> class-in-test
> 3. skip mockitoannotations.initmocks(this)
>
> There are almost a billion ways of container testing using openejb
> now...like a swiss army knife :-)
>
> br
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669698.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Hi,
probably easier said than done.....at least for me :-)
The only way it's working right now is.
1. mock implementation
2. inject implementation and not interface of the class to be mocked in
class-in-test
3. skip mockitoannotations.initmocks(this)
There are almost a billion ways of container testing using openejb
now...like a swiss army knife :-)
br
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669698.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
remove the impl (not the interface) otherwise no need of a fallback injector
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-27 7:11 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi Romain,
> did a test this morning, but my project is still not mocking.
> (did not build from source, just updated maven repos)
>
> br hw
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669684.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Hi Romain,
did a test this morning, but my project is still not mocking.
(did not build from source, just updated maven repos)
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669684.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hello
this patch fixes it:
Index:
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
===================================================================
---
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
(revision
1597526)
+++
container/openejb-junit/src/main/java/org/apache/openejb/junit/jee/statement/InjectStatement.java
(working
copy)
@@ -16,17 +16,21 @@
*/
package org.apache.openejb.junit.jee.statement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Hashtable;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+
import org.apache.openejb.Injector;
import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.injection.FallbackPropertyInjector;
import org.apache.openejb.junit.jee.resources.TestResource;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.testing.TestInstance;
import org.junit.runners.model.Statement;
-import javax.ejb.embeddable.EJBContainer;
-import javax.naming.Context;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Hashtable;
-
public class InjectStatement extends Statement {
private final StartingStatement startingStatement;
private final Object test;
@@ -66,6 +70,8 @@
}
}
if (test != null) {
+ SystemInstance.get().setComponent(TestInstance.class, new
TestInstance(test.getClass(), test));
+ SystemInstance.get().getComponent(FallbackPropertyInjector.class); //
force eager init (MockitoInjector initialize eveything in its constructor)
Injector.inject(test);
}
if (statement != null) {
You just need to remove your Mockito.init call in your test then
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-26 12:01 GMT+02:00 hwaastad <he...@waastad.org>:
> I guess I must be doing something wrong here:
> Maybe the inject rule?
>
> https://github.com/hwaastad/ContainerTest.git
>
> @ClassRule
> public static final EJBContainerRule CONTAINER_RULE = new
> EJBContainerRule();
> @Rule
> public final InjectRule injectRule = new InjectRule(this,
> CONTAINER_RULE);
>
> @EJB
> private HelloBeanLocal helloBeanLocal;
>
>
> @Properties({
> @Property(key =
> "org.apache.openejb.injection.FallbackPropertyInjector",value =
> "org.apache.openejb.mockito.MockitoInjector")
> })
>
> @Mock
> private TestBeanLocal mockTestBean;
>
> @Before
> public void setUp() {
> MockitoAnnotations.initMocks(this);
> }
>
> @Test
> public void testSayHello() throws Exception {
> Mockito.when(mockTestBean.doTest()).thenReturn("ompalompa");
> helloBeanLocal.sayHello();
> }
>
> But mocking is not working.
>
> No hurry here, i just wanted to implement parts of your blog :-)
>
> br hw
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669670.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
I guess I must be doing something wrong here:
Maybe the inject rule?
https://github.com/hwaastad/ContainerTest.git
@ClassRule
public static final EJBContainerRule CONTAINER_RULE = new
EJBContainerRule();
@Rule
public final InjectRule injectRule = new InjectRule(this,
CONTAINER_RULE);
@EJB
private HelloBeanLocal helloBeanLocal;
@Properties({
@Property(key =
"org.apache.openejb.injection.FallbackPropertyInjector",value =
"org.apache.openejb.mockito.MockitoInjector")
})
@Mock
private TestBeanLocal mockTestBean;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testSayHello() throws Exception {
Mockito.when(mockTestBean.doTest()).thenReturn("ompalompa");
helloBeanLocal.sayHello();
}
But mocking is not working.
No hurry here, i just wanted to implement parts of your blog :-)
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669670.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Think
org.apache.openejb.injection.FallbackPropertyInjector=org.apache.openejb.mockito.MockitoInjector
should work (of course you need openejb-mockito in the classpath)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-26 11:24 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi Romain,
> Have you got a oneliner for the fallback injector property?
> (@Property(key=?,value=?)
>
> br hw
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669668.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: OpenEJB/TomEE and mocking
Posted by hwaastad <he...@waastad.org>.
Hi Romain,
Have you got a oneliner for the fallback injector property?
(@Property(key=?,value=?)
br hw
--
View this message in context: http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665p4669668.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: OpenEJB/TomEE and mocking
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
same tricks should work. Just set the fallback injector in properties of
the container and Mockito helper to get @Mock working
(org.mockito.MockitoAnnotations.initMocks()
IIRC)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-26 10:53 GMT+02:00 hwaastad <he...@waastad.org>:
> Hi,
> I've been using App composer and mockito and its working nicely,
> However, after reading Romains blog (which has a lot of interesting hints
> regarding new feature in TomEE/OpenEJB) about ejbcontainer and junit rules
> my question is this.
>
> Is it possible to use mocking in these kinds of scenarios?
>
> br hw
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/OpenEJB-TomEE-and-mocking-tp4669665.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>