You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by amber <am...@hotmail.fr> on 2012/02/19 16:55:38 UTC
openEJB fail on second test
Hi,
I have two tests that are well running within Eclipse (context menu run as
junit test), but under Maven the second always failed (I had tried to
inverted order, but it s always second that failed)
>From the surfire report I got this :
-------------------------------------------------------------------------------
Test set: org.foo.services.category.CategoryServiceBeanTest
-------------------------------------------------------------------------------
Tests run: 5, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 0.016 sec
<<< FAILURE!
createCategory(org.foo.services.category.CategoryServiceBeanTest) Time
elapsed: 0 sec <<< ERROR!
org.apache.openejb.OpenEjbContainer$NoInjectionMetaDataException:
org.foo.services.category.CategoryServiceBeanTest
at org.apache.openejb.OpenEjbContainer.inject(OpenEjbContainer.java:128)
at
org.apache.openejb.OpenEjbContainer$GlobalContext.bind(OpenEjbContainer.java:579)
at
org.foo.services.category.CategoryServiceBeanTest.<init>(CategoryServiceBeanTest.java:53)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at
org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
The line at
org.foo.services.category.CategoryServiceBeanTest.<init>(CategoryServiceBeanTest.java:53)
is
" EJBContainer.createEJBContainer(p).getContext().bind("inject", this); "
any idea?
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4401889.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
seems it is simply a jaxb issue.
here a workaround: create a MovieList class (well maybe find a better name
;)) then add into this brand new class a list of movies. then replace your
webservice return type by this wrapper class and everything should be ok.
- Romain
2012/2/24 amber <am...@hotmail.fr>
> ok : http://www.reliablefilehosting.com/files/jp1eL1330069819.html
>
> thx!
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4416488.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
ok : http://www.reliablefilehosting.com/files/jp1eL1330069819.html
thx!
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4416488.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
without more info i'm not sure what i'll say is relevant but typically you
can createcontainer and close it in @BeforeClass and @AfterClass. To do it
only once you need to
set OpenEjbContainer.Provider.OPENEJB_ADDITIONNAL_CALLERS_KEY property with
the names of test classes.
- Romain
2012/2/19 amber <am...@hotmail.fr>
> beans.xml did not change anything
>
> but..I've found a turnaround : just add ejbContainer.close(); in "@After
> public void release()" method in each test ^^
>
> Why I have to do that I don't know but it's working now
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4402384.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
beans.xml did not change anything
but..I've found a turnaround : just add ejbContainer.close(); in "@After
public void release()" method in each test ^^
Why I have to do that I don't know but it's working now
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4402384.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
Sometimes eclipse merges src/main and src/test, maybe add a beans.xml in
both resources.
Le 19 févr. 2012 16:56, "amber" <am...@hotmail.fr> a écrit :
> Hi,
>
> I have two tests that are well running within Eclipse (context menu run as
> junit test), but under Maven the second always failed (I had tried to
> inverted order, but it s always second that failed)
>
> From the surfire report I got this :
>
>
> -------------------------------------------------------------------------------
> Test set: org.foo.services.category.CategoryServiceBeanTest
>
> -------------------------------------------------------------------------------
> Tests run: 5, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 0.016 sec
> <<< FAILURE!
> createCategory(org.foo.services.category.CategoryServiceBeanTest) Time
> elapsed: 0 sec <<< ERROR!
> org.apache.openejb.OpenEjbContainer$NoInjectionMetaDataException:
> org.foo.services.category.CategoryServiceBeanTest
> at
> org.apache.openejb.OpenEjbContainer.inject(OpenEjbContainer.java:128)
> at
>
> org.apache.openejb.OpenEjbContainer$GlobalContext.bind(OpenEjbContainer.java:579)
> at
>
> org.foo.services.category.CategoryServiceBeanTest.<init>(CategoryServiceBeanTest.java:53)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
>
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> at
>
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> at
>
> org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
> at
>
> org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
> at
>
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
>
> org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
> at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
> at
>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> at
>
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
> at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
> at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
> at
>
> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
> at
>
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
> at
>
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
> at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
>
> The line at
>
> org.foo.services.category.CategoryServiceBeanTest.<init>(CategoryServiceBeanTest.java:53)
> is
>
>
> " EJBContainer.createEJBContainer(p).getContext().bind("inject",
> this); "
>
> any idea?
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4401889.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
maybe share your complete example, will be easier to test locally (github,
code google or any repo is a good idea to do so).
- Romain
2012/2/23 amber <am...@hotmail.fr>
> just adding a println :
>
> public List<Movie> foo() {
> Query query = entityManager.createQuery("SELECT m from
> Movie m");
> List<Movie> movies = query.getResultList();
> System.out.println("movies.size() = " + movies.size());
> return movies;
> }
>
>
>
> giving :
>
> movies.size() = 2
> movies.size() = 0
>
>
> amber wrote
> >
> > sure here the code :
> >
> > public void testWSCreateDelete() throws Exception {
> > Service movieService = Service.create(new
> > URL("http://127.0.0.1:4204/Movies?wsdl"), new
> > QName("http://superbiz.org/wsdl", "MoviesWebService"));
> > assertNotNull(movieService);
> >
> > IMoviesWS mv = movieService.getPort(IMoviesWS.class);
> >
> > mv.addMovie(new Movie("Quentin Tarantino", "Reservoir
> Dogs", 1992));
> > mv.addMovie(new Movie("Joel Coen", "Fargo", 1996));
> >
> > List<Movie> list = mv.foo();
> > assertEquals("List.size()", 2, list.size());
> >
> > for (Movie movie : list) {
> > mv.deleteMovie(movie);
> > }
> >
> > List<Movie> list2 = mv.foo();
> >
> > *// return null*
> > assertEquals("List2.size()", 0, list2.size());
> > }
> >
> >
> >
> > the movies bean :
> > public List<Movie> foo() {
> > Query query = entityManager.createQuery("SELECT m from
> Movie m");
> > List<Movie> movies = query.getResultList();
> > movies.size();
> > return movies;
> > }
> >
> > the trace :
> >
> >
> >
> > java.lang.NullPointerException
> > at
> org.superbiz.altdd.MoviesTest.testWSCreateDelete(MoviesTest.java:128)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at junit.framework.TestCase.runTest(TestCase.java:168)
> > at junit.framework.TestCase.runBare(TestCase.java:134)
> > at junit.framework.TestResult$1.protect(TestResult.java:110)
> > at junit.framework.TestResult.runProtected(TestResult.java:128)
> > at junit.framework.TestResult.run(TestResult.java:113)
> > at junit.framework.TestCase.run(TestCase.java:124)
> > at junit.framework.TestSuite.runTest(TestSuite.java:232)
> > at junit.framework.TestSuite.run(TestSuite.java:227)
> > at
> >
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> > at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> > at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> >
> >
> > I added too the foo() to the Ws interface and the MovieLocal interface
> >
> >
> > Romain Manni-Bucau wrote
> >>
> >> can you try doing something like this please?
> >>
> >> List foo() {
> >> List movies = ...;
> >> movies.size();
> >> return movies;
> >> }
> >>
> >> - Romain
> >>
> >>
> >> 2012/2/23 amber <amber63@>
> >>
> >>> ok for the "as" keyword )
> >>>
> >>> the difference is on the Web Service that failed on the "select m from
> >>> Movie
> >>> m" after a delete operation, works fine when I pass through the @EJB
> >>> injection (like your code)
> >>>
> >>> the getMovies() return an empty List (debugger mark the return value as
> >>> [])
> >>> as expected (we deleted content just before) but from the caller the
> >>> pointer
> >>> is set to null. I don't understand why.
> >>>
> >>>
> >>>
> >>> --
> >>> View this message in context:
> >>>
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414214.html
> >>> Sent from the OpenEJB User mailing list archive at Nabble.com.
> >>>
> >>
> >
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414347.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
just adding a println :
public List<Movie> foo() {
Query query = entityManager.createQuery("SELECT m from Movie m");
List<Movie> movies = query.getResultList();
System.out.println("movies.size() = " + movies.size());
return movies;
}
giving :
movies.size() = 2
movies.size() = 0
amber wrote
>
> sure here the code :
>
> public void testWSCreateDelete() throws Exception {
> Service movieService = Service.create(new
> URL("http://127.0.0.1:4204/Movies?wsdl"), new
> QName("http://superbiz.org/wsdl", "MoviesWebService"));
> assertNotNull(movieService);
>
> IMoviesWS mv = movieService.getPort(IMoviesWS.class);
>
> mv.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
> mv.addMovie(new Movie("Joel Coen", "Fargo", 1996));
>
> List<Movie> list = mv.foo();
> assertEquals("List.size()", 2, list.size());
>
> for (Movie movie : list) {
> mv.deleteMovie(movie);
> }
>
> List<Movie> list2 = mv.foo();
>
> *// return null*
> assertEquals("List2.size()", 0, list2.size());
> }
>
>
>
> the movies bean :
> public List<Movie> foo() {
> Query query = entityManager.createQuery("SELECT m from Movie m");
> List<Movie> movies = query.getResultList();
> movies.size();
> return movies;
> }
>
> the trace :
>
>
>
> java.lang.NullPointerException
> at org.superbiz.altdd.MoviesTest.testWSCreateDelete(MoviesTest.java:128)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
> I added too the foo() to the Ws interface and the MovieLocal interface
>
>
> Romain Manni-Bucau wrote
>>
>> can you try doing something like this please?
>>
>> List foo() {
>> List movies = ...;
>> movies.size();
>> return movies;
>> }
>>
>> - Romain
>>
>>
>> 2012/2/23 amber <amber63@>
>>
>>> ok for the "as" keyword )
>>>
>>> the difference is on the Web Service that failed on the "select m from
>>> Movie
>>> m" after a delete operation, works fine when I pass through the @EJB
>>> injection (like your code)
>>>
>>> the getMovies() return an empty List (debugger mark the return value as
>>> [])
>>> as expected (we deleted content just before) but from the caller the
>>> pointer
>>> is set to null. I don't understand why.
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414214.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>
>>
>
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414347.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
sure here the code :
public void testWSCreateDelete() throws Exception {
Service movieService = Service.create(new
URL("http://127.0.0.1:4204/Movies?wsdl"), new
QName("http://superbiz.org/wsdl", "MoviesWebService"));
assertNotNull(movieService);
IMoviesWS mv = movieService.getPort(IMoviesWS.class);
mv.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
mv.addMovie(new Movie("Joel Coen", "Fargo", 1996));
List<Movie> list = mv.foo();
assertEquals("List.size()", 2, list.size());
for (Movie movie : list) {
mv.deleteMovie(movie);
}
List<Movie> list2 = mv.foo();
*// return null*
assertEquals("List2.size()", 0, list2.size());
}
the movies bean :
public List<Movie> foo() {
Query query = entityManager.createQuery("SELECT m from Movie m");
List<Movie> movies = query.getResultList();
movies.size();
return movies;
}
the trace :
java.lang.NullPointerException
at org.superbiz.altdd.MoviesTest.testWSCreateDelete(MoviesTest.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I added too the foo() to the Ws interface and the MovieLocal interface
Romain Manni-Bucau wrote
>
> can you try doing something like this please?
>
> List foo() {
> List movies = ...;
> movies.size();
> return movies;
> }
>
> - Romain
>
>
> 2012/2/23 amber <amber63@>
>
>> ok for the "as" keyword )
>>
>> the difference is on the Web Service that failed on the "select m from
>> Movie
>> m" after a delete operation, works fine when I pass through the @EJB
>> injection (like your code)
>>
>> the getMovies() return an empty List (debugger mark the return value as
>> [])
>> as expected (we deleted content just before) but from the caller the
>> pointer
>> is set to null. I don't understand why.
>>
>>
>>
>> --
>> View this message in context:
>> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414214.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414299.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
can you try doing something like this please?
List foo() {
List movies = ...;
movies.size();
return movies;
}
- Romain
2012/2/23 amber <am...@hotmail.fr>
> ok for the "as" keyword )
>
> the difference is on the Web Service that failed on the "select m from
> Movie
> m" after a delete operation, works fine when I pass through the @EJB
> injection (like your code)
>
> the getMovies() return an empty List (debugger mark the return value as [])
> as expected (we deleted content just before) but from the caller the
> pointer
> is set to null. I don't understand why.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414214.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
ok for the "as" keyword )
the difference is on the Web Service that failed on the "select m from Movie
m" after a delete operation, works fine when I pass through the @EJB
injection (like your code)
the getMovies() return an empty List (debugger mark the return value as [])
as expected (we deleted content just before) but from the caller the pointer
is set to null. I don't understand why.
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414214.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
"SELECT m from Movie as m" can be "SELECT m from Movie m"
what i sent you works perfectly, not sure what is the difference....
- Romain
2012/2/23 amber <am...@hotmail.fr>
> Romain : "as keyword is useless i think " . which keyword?
>
> A made some tests : the assertion pass when I delete movies from the EJB
> injection (localMovies injected with @EJB annotation) but failed when I
> use
> the Web Service (either by @WebServiceRef or by Ws intrface)
>
> *the Movies EJB :*
>
> @Stateless
> @TransactionAttribute(TransactionAttributeType.REQUIRED)
> @WebService(endpointInterface = "org.superbiz.altdd.IMoviesWS", serviceName
> = "MoviesWebService", targetNamespace = "http://superbiz.org/wsdl")
> public class Movies implements IMoviesWS, MoviesLocal {
>
> @PersistenceContext(unitName = "movie-unit", type =
> PersistenceContextType.TRANSACTION)
> private EntityManager entityManager;
>
> ...
>
> @SuppressWarnings("unchecked")
> public List<Movie> getMovies() throws Exception {
> Query query = entityManager.createQuery("SELECT m from
> Movie as m");
>
> List<Movie> list = query.getResultList();
> //System.out.println("size()= " + list.size());
> //return query.getResultList();
> return list;
> }
> }
>
> *the test :*
>
> @LocalClient
> public class MoviesTest extends TestCase {
>
> @WebServiceRef(wsdlLocation = "http://127.0.0.1:4204/Movies?wsdl")
> private IMoviesWS moviesInject;
>
> @EJB
> private MoviesLocal localMovies;
>
> ...
>
> public void test() throws Exception {
>
> localMovies.addMovie(new Movie("Quentin Tarantino",
> "Reservoir
> Dogs",1992));
> localMovies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
> localMovies.addMovie(new Movie("Joel Coen", "The Big
> Lebowski", 1998));
>
> List<Movie> list = localMovies.getMovies();
> assertEquals("List.size()", 3, list.size());
> for (Movie movie : list) {
> localMovies.deleteMovie(movie);
> }
>
> List<Movie> list2 = localMovies.getMovies();
> System.out.println("size()= " + list2.size());
> *// works fine*
> assertEquals("List.size()", 0, list2.size());
> }
>
>
> public void testWSInjection() throws Exception {
> moviesInject.addMovie(new Movie("Quentin Tarantino",
> "Reservoir
> Dogs",1992));
> moviesInject.addMovie(new Movie("Joel Coen", "Fargo",
> 1996));
> List<Movie> list = moviesInject.getMovies();
> for (Movie movie : list) {
> moviesInject.deleteMovie(movie);
> }
> List<Movie> list2 = moviesInject.getMovies();
> *// the list2 returned is null*
>
> System.out.println("size()= " + list2.size());
>
> assertEquals("List.size()", 0, list2.size());
>
> }
>
>
>
> did I miss something (again) ?
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414065.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
Romain : "as keyword is useless i think " . which keyword?
A made some tests : the assertion pass when I delete movies from the EJB
injection (localMovies injected with @EJB annotation) but failed when I use
the Web Service (either by @WebServiceRef or by Ws intrface)
*the Movies EJB :*
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@WebService(endpointInterface = "org.superbiz.altdd.IMoviesWS", serviceName
= "MoviesWebService", targetNamespace = "http://superbiz.org/wsdl")
public class Movies implements IMoviesWS, MoviesLocal {
@PersistenceContext(unitName = "movie-unit", type =
PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
...
@SuppressWarnings("unchecked")
public List<Movie> getMovies() throws Exception {
Query query = entityManager.createQuery("SELECT m from Movie as m");
List<Movie> list = query.getResultList();
//System.out.println("size()= " + list.size());
//return query.getResultList();
return list;
}
}
*the test :*
@LocalClient
public class MoviesTest extends TestCase {
@WebServiceRef(wsdlLocation = "http://127.0.0.1:4204/Movies?wsdl")
private IMoviesWS moviesInject;
@EJB
private MoviesLocal localMovies;
...
public void test() throws Exception {
localMovies.addMovie(new Movie("Quentin Tarantino", "Reservoir
Dogs",1992));
localMovies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
localMovies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
List<Movie> list = localMovies.getMovies();
assertEquals("List.size()", 3, list.size());
for (Movie movie : list) {
localMovies.deleteMovie(movie);
}
List<Movie> list2 = localMovies.getMovies();
System.out.println("size()= " + list2.size());
*// works fine*
assertEquals("List.size()", 0, list2.size());
}
public void testWSInjection() throws Exception {
moviesInject.addMovie(new Movie("Quentin Tarantino", "Reservoir
Dogs",1992));
moviesInject.addMovie(new Movie("Joel Coen", "Fargo", 1996));
List<Movie> list = moviesInject.getMovies();
for (Movie movie : list) {
moviesInject.deleteMovie(movie);
}
List<Movie> list2 = moviesInject.getMovies();
*// the list2 returned is null*
System.out.println("size()= " + list2.size());
assertEquals("List.size()", 0, list2.size());
}
did I miss something (again) ?
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4414065.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Did you check in the ejb the size of the list?
Note: as keyword is useless i think
Le 22 févr. 2012 21:45, "amber" <am...@hotmail.fr> a écrit :
> Romain, thanks for your advices :)
>
> Of course if I remove the transaction code I have to use the entity manager
> from the EJB and not the one remains in the test class ^^ (I should have
> delete it..)
>
> Anyway the code is working now and I even tried to move it to a Web
> Service.
> works fine..except one thing : after the delete, the final assertion failed
> (null pointer) I don't know why ?
>
> Here the code :
>
> *The movie :*
>
> @Entity
> public class Movie {
>
>
> @Id
> @GeneratedValue
> private long id;
>
> ....
>
>
> *The movies *
> @Stateless
> @TransactionAttribute(TransactionAttributeType.REQUIRED)
> @WebService(endpointInterface = "org.superbiz.altdd.IMoviesWS", serviceName
> = "MoviesWebService", targetNamespace = "http://superbiz.org/wsdl")
> public class Movies implements IMoviesWS {
>
> @PersistenceContext(unitName = "movie-unit", type =
> PersistenceContextType.TRANSACTION)
> private EntityManager entityManager;
>
> public void addMovie(Movie movie) throws Exception {
> entityManager.persist(movie);
> }
>
> public void deleteMovie(Movie movie) throws Exception {
> entityManager.remove(entityManager.find(Movie.class,
> movie.getId()));
> }
>
>
> @SuppressWarnings("unchecked")
> public List<Movie> getMovies() throws Exception {
> Query query = entityManager.createQuery("SELECT m from
> Movie as m");
> return query.getResultList();
> }
> }
>
>
> *The interface of the WS :*
>
> @WebService(name = "IMoviesWS", targetNamespace =
> "http://superbiz.org/wsdl")
> public interface IMoviesWS {
>
>
> void addMovie(Movie movie) throws Exception;
>
> void deleteMovie(Movie movie) throws Exception;
>
> List<Movie> getMovies() throws Exception;
> }
>
> *And the test :*
>
> @LocalClient
> public class MoviesTest extends TestCase {
>
> @WebServiceRef(wsdlLocation = "http://127.0.0.1:4204/Movies?wsdl")
> private IMoviesWS movies;
>
> private InitialContext initialContext;
>
> public void setUp() throws Exception {
>
> Properties properties = new Properties();
> properties.put("movieDatabase",
> "new://Resource?type=DataSource");
> properties.put("movieDatabase.JdbcDriver",
> "org.hsqldb.jdbcDriver");
> properties.put("movieDatabase.JdbcUrl",
> "jdbc:hsqldb:mem:moviedb");
>
> properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>
> "org.apache.openejb.core.LocalInitialContextFactory");
> properties.setProperty("openejb.embedded.remotable",
> "true");
>
> initialContext = new InitialContext(properties);
> initialContext.bind("inject", this);
> }
>
> public void test() throws Exception {
> movies.addMovie(new Movie("Quentin Tarantino", "Reservoir
> Dogs", 1992));
> movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
> movies.addMovie(new Movie("Joel Coen", "The Big Lebowski",
> 1998));
>
> List<Movie> list = movies.getMovies();
> assertEquals("List.size()", 3, list.size());
> for (Movie movie : list) {
> movies.deleteMovie(movie);
> }
> /*// do a null pointer exception why?*/
> // assertEquals("Movies.getMovies()", 0,
> movies.getMovies().size());
> }
>
> public void testWS() throws Exception {
> Service movieService = Service.create(new URL(
> "http://127.0.0.1:4204/Movies?wsdl"), new
> QName(
> "http://superbiz.org/wsdl",
> "MoviesWebService"));
> assertNotNull(movieService);
>
> IMoviesWS mv = movieService.getPort(IMoviesWS.class);
> mv.addMovie(new Movie("Quentin Tarantino", "Reservoir
> Dogs", 1992));
> assertEquals("List.size()", 1, movies.getMovies().size());
> }
> }
>
> thank you for your patience!
> And I hope this will help other noobs like me ))
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4411703.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
Romain, thanks for your advices :)
Of course if I remove the transaction code I have to use the entity manager
from the EJB and not the one remains in the test class ^^ (I should have
delete it..)
Anyway the code is working now and I even tried to move it to a Web Service.
works fine..except one thing : after the delete, the final assertion failed
(null pointer) I don't know why ?
Here the code :
*The movie :*
@Entity
public class Movie {
@Id
@GeneratedValue
private long id;
....
*The movies *
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@WebService(endpointInterface = "org.superbiz.altdd.IMoviesWS", serviceName
= "MoviesWebService", targetNamespace = "http://superbiz.org/wsdl")
public class Movies implements IMoviesWS {
@PersistenceContext(unitName = "movie-unit", type =
PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
public void addMovie(Movie movie) throws Exception {
entityManager.persist(movie);
}
public void deleteMovie(Movie movie) throws Exception {
entityManager.remove(entityManager.find(Movie.class, movie.getId()));
}
@SuppressWarnings("unchecked")
public List<Movie> getMovies() throws Exception {
Query query = entityManager.createQuery("SELECT m from Movie as m");
return query.getResultList();
}
}
*The interface of the WS :*
@WebService(name = "IMoviesWS", targetNamespace =
"http://superbiz.org/wsdl")
public interface IMoviesWS {
void addMovie(Movie movie) throws Exception;
void deleteMovie(Movie movie) throws Exception;
List<Movie> getMovies() throws Exception;
}
*And the test :*
@LocalClient
public class MoviesTest extends TestCase {
@WebServiceRef(wsdlLocation = "http://127.0.0.1:4204/Movies?wsdl")
private IMoviesWS movies;
private InitialContext initialContext;
public void setUp() throws Exception {
Properties properties = new Properties();
properties.put("movieDatabase", "new://Resource?type=DataSource");
properties.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
properties.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.core.LocalInitialContextFactory");
properties.setProperty("openejb.embedded.remotable", "true");
initialContext = new InitialContext(properties);
initialContext.bind("inject", this);
}
public void test() throws Exception {
movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
List<Movie> list = movies.getMovies();
assertEquals("List.size()", 3, list.size());
for (Movie movie : list) {
movies.deleteMovie(movie);
}
/*// do a null pointer exception why?*/
// assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
}
public void testWS() throws Exception {
Service movieService = Service.create(new URL(
"http://127.0.0.1:4204/Movies?wsdl"), new QName(
"http://superbiz.org/wsdl", "MoviesWebService"));
assertNotNull(movieService);
IMoviesWS mv = movieService.getPort(IMoviesWS.class);
mv.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
assertEquals("List.size()", 1, movies.getMovies().size());
}
}
thank you for your patience!
And I hope this will help other noobs like me ))
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4411703.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
it simply says that your test method is not transactional which is true.
here a code which works:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class Movies {
@PersistenceContext(unitName = "movie-unit", type =
PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
public void addMovie(Movie movie) throws Exception {
entityManager.persist(movie);
}
public void deleteMovie(Movie movie) throws Exception {
entityManager.remove(entityManager.find(Movie.class,
movie.getId()));
}
public List<Movie> getMovies() throws Exception {
Query query = entityManager.createQuery("SELECT m from Movie as m");
return query.getResultList();
}
}
public class MoviesTest extends TestCase {
@EJB
private Movies movies;
@PersistenceContext
private EntityManager entityManager;
public void setUp() throws Exception {
Properties p = new Properties();
p.put("movieDatabase", "new://Resource?type=DataSource");
p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
EJBContainer.createEJBContainer(p).getContext().bind("inject",
this);
}
public void test() throws Exception {
movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs",
1992));
movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
List<Movie> list = movies.getMovies();
assertEquals("List.size()", 3, list.size());
for (Movie movie : list) {
movies.deleteMovie(movie);
}
assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
}
}
Note: i added to movie entity:
@Id
@GeneratedValue
private long id;
+ the getId method.
- Romain
2012/2/22 amber <am...@hotmail.fr>
> I've tried to modify the example "alternate-descriptors" from
> openejb-examples-4.0.0-beta-2 to have a bean statless with
> TransactionAttributeType.REQUIRED
>
> To me REQUIRED start a transaction if no one is active.
>
> But i got too a javax.persistence.TransactionRequiredException
>
> Here the code :
>
> movies.java :
>
> import javax.ejb.Stateful;
> import javax.ejb.TransactionAttribute;
> import javax.ejb.TransactionAttributeType;
> import javax.persistence.EntityManager;
> import javax.persistence.PersistenceContext;
> import javax.persistence.PersistenceContextType;
> import javax.persistence.Query;
> import java.util.List;
> import javax.ejb.Stateless;
>
> import static javax.ejb.TransactionAttributeType.MANDATORY;
>
> //START SNIPPET: code
> @Stateless
> @TransactionAttribute(TransactionAttributeType.REQUIRED)
> public class Movies {
>
> @PersistenceContext(unitName = "movie-unit", type =
> PersistenceContextType.TRANSACTION)
> private EntityManager entityManager;
>
> public void addMovie(Movie movie) throws Exception {
> entityManager.persist(movie);
> }
>
> public void deleteMovie(Movie movie) throws Exception {
> entityManager.remove(movie);
> }
>
> public List<Movie> getMovies() throws Exception {
> Query query = entityManager.createQuery("SELECT m from Movie as m");
> return query.getResultList();
> }
> }
>
> MoviesTest.java :
>
> //START SNIPPET: code
> public class MoviesTest extends TestCase {
>
> @EJB
> private Movies movies;
>
> @PersistenceContext
> private EntityManager entityManager;
>
> public void setUp() throws Exception {
> Properties p = new Properties();
> p.put("movieDatabase", "new://Resource?type=DataSource");
> p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
> p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
>
> p.put("openejb.altdd.prefix", "test");
>
> EJBContainer.createEJBContainer(p).getContext().bind("inject",
> this);
> }
>
> public void test() throws Exception {
> entityManager.persist(new Movie("Quentin Tarantino", "Reservoir
> Dogs", 1992));
> entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
> entityManager.persist(new Movie("Joel Coen", "The Big Lebowski",
> 1998));
>
> List<Movie> list = movies.getMovies();
> assertEquals("List.size()", 3, list.size());
>
> for (Movie movie : list) {
> movies.deleteMovie(movie);
> }
> assertEquals("Movies.getMovies()", 0,
> movies.getMovies().size());
> }
> }
>
> result :
>
> javax.persistence.TransactionRequiredException
> at
>
> org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:91)
> at
>
> org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:120)
> at org.superbiz.altdd.MoviesTest.test(MoviesTest.java:55)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at
>
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
> at
>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
> note that I removed the userTransaction part (because the contener has to
> start one)
>
> did i miss something ?
>
> I am a bit disappointed, my app was working fine on openEJB 3.1.4 and I
> can't do it working on 4 (moving EJB 3 to 3.1)
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4410822.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
I've tried to modify the example "alternate-descriptors" from
openejb-examples-4.0.0-beta-2 to have a bean statless with
TransactionAttributeType.REQUIRED
To me REQUIRED start a transaction if no one is active.
But i got too a javax.persistence.TransactionRequiredException
Here the code :
movies.java :
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;
import java.util.List;
import javax.ejb.Stateless;
import static javax.ejb.TransactionAttributeType.MANDATORY;
//START SNIPPET: code
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class Movies {
@PersistenceContext(unitName = "movie-unit", type =
PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
public void addMovie(Movie movie) throws Exception {
entityManager.persist(movie);
}
public void deleteMovie(Movie movie) throws Exception {
entityManager.remove(movie);
}
public List<Movie> getMovies() throws Exception {
Query query = entityManager.createQuery("SELECT m from Movie as m");
return query.getResultList();
}
}
MoviesTest.java :
//START SNIPPET: code
public class MoviesTest extends TestCase {
@EJB
private Movies movies;
@PersistenceContext
private EntityManager entityManager;
public void setUp() throws Exception {
Properties p = new Properties();
p.put("movieDatabase", "new://Resource?type=DataSource");
p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
p.put("openejb.altdd.prefix", "test");
EJBContainer.createEJBContainer(p).getContext().bind("inject",
this);
}
public void test() throws Exception {
entityManager.persist(new Movie("Quentin Tarantino", "Reservoir
Dogs", 1992));
entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
entityManager.persist(new Movie("Joel Coen", "The Big Lebowski",
1998));
List<Movie> list = movies.getMovies();
assertEquals("List.size()", 3, list.size());
for (Movie movie : list) {
movies.deleteMovie(movie);
}
assertEquals("Movies.getMovies()", 0,
movies.getMovies().size());
}
}
result :
javax.persistence.TransactionRequiredException
at
org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:91)
at
org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:120)
at org.superbiz.altdd.MoviesTest.test(MoviesTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
note that I removed the userTransaction part (because the contener has to
start one)
did i miss something ?
I am a bit disappointed, my app was working fine on openEJB 3.1.4 and I
can't do it working on 4 (moving EJB 3 to 3.1)
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4410822.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
right, this field was added after beta-2 release i guess.
so you get 2 possibilities:
1) testing with beta-2-SNAPSHOT
2) just comparing to @Test method
- Romain
2012/2/22 amber <am...@hotmail.fr>
> hi,
>
> if I test this code I got an error on
> ApplicationComposer.OPENEJB_APPLICATION_COMPOSER_CONTEXT :
> cannot be resolved or is not a field.
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4410493.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
hi,
if I test this code I got an error on
ApplicationComposer.OPENEJB_APPLICATION_COMPOSER_CONTEXT :
cannot be resolved or is not a field.
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4410493.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
can you compare what you are doing with the @Test method of the following
test please:
http://svn.apache.org/repos/asf/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulJPATest.java
this test passes.
do you inject the stateful in your bean?
- Romain
2012/2/21 amber <am...@hotmail.fr>
>
> I have another minor issue :
>
>
> The EJB is marked
> "@TransactionAttribute(TransactionAttributeType.REQUIRED)"
> so a create/update action is done inside a transaction
>
> I can trace it : DEBUG [Transaction] TX Required: Started transaction
> org.apache.geronimo.transaction.manager.TransactionImpl@26a150e
>
> ... and all work fine..
>
> but... i have one test fail : the remove operation !
>
> javax.persistence.TransactionRequiredException
> at
>
> org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:91)
> at
>
> org.apache.openejb.persistence.JtaEntityManager.remove(JtaEntityManager.java:140)
> at
> org.foo.services.foo.impl.FooServiceBean.deleteFoo(FooServiceBean.java:84)
> at
>
> org.foo.services.foo.FooServiceBeanTest.deleteFoo(FooServiceBeanTest.java:126)
>
> I have to use the trick :
>
> getTransactionalCaller().call(new Callable() {
> public Object call() throws Exception {
> ... the code ...
> return null;
> }
> });
>
> and the remove() works... Why I have to do that only on the remove
> operation
> and not others ?
>
>
> thanks! and pardon me if my questions are trivials :)
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4406177.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
I have another minor issue :
The EJB is marked "@TransactionAttribute(TransactionAttributeType.REQUIRED)"
so a create/update action is done inside a transaction
I can trace it : DEBUG [Transaction] TX Required: Started transaction
org.apache.geronimo.transaction.manager.TransactionImpl@26a150e
... and all work fine..
but... i have one test fail : the remove operation !
javax.persistence.TransactionRequiredException
at
org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:91)
at
org.apache.openejb.persistence.JtaEntityManager.remove(JtaEntityManager.java:140)
at
org.foo.services.foo.impl.FooServiceBean.deleteFoo(FooServiceBean.java:84)
at
org.foo.services.foo.FooServiceBeanTest.deleteFoo(FooServiceBeanTest.java:126)
I have to use the trick :
getTransactionalCaller().call(new Callable() {
public Object call() throws Exception {
... the code ...
return null;
}
});
and the remove() works... Why I have to do that only on the remove operation
and not others ?
thanks! and pardon me if my questions are trivials :)
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4406177.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
we don't change the behavior of the test if it is not asked but if it is
asked we could be ready.
- Romain
2012/2/20 Alan D. Cabrera <li...@toolazydogs.com>
> I think that it's a bad practice to automagically change the explicit
> behavior of tests. If a test needs to explicitly state a fact about itself
> w/ an explicit annotation to get it to pass then that's what it should do.
>
>
> Regards,
> Alan
>
>
> On Feb 20, 2012, at 12:07 AM, Romain Manni-Bucau wrote:
>
> > it is the second time we have such an issue,
> >
> > maybe we should scan junit/testng annotations (with a good catch if it is
> > not available at the classpath) to add automatically these tests to the
> > managed beans?
> >
> > - Romain
> >
> >
> > ---------- Forwarded message ----------
> > From: amber <am...@hotmail.fr>
> > Date: 2012/2/20
> > Subject: Re: openEJB fail on second test
> > To: users@openejb.apache.org
> >
> >
> > ok @javax.annotation.ManagedBean is the right solution, working for me
> too
> > ^^
> >
> > thx for help
> >
> > --
> > View this message in context:
> >
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4403405.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>
Re: openEJB fail on second test
Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
I think that it's a bad practice to automagically change the explicit behavior of tests. If a test needs to explicitly state a fact about itself w/ an explicit annotation to get it to pass then that's what it should do.
Regards,
Alan
On Feb 20, 2012, at 12:07 AM, Romain Manni-Bucau wrote:
> it is the second time we have such an issue,
>
> maybe we should scan junit/testng annotations (with a good catch if it is
> not available at the classpath) to add automatically these tests to the
> managed beans?
>
> - Romain
>
>
> ---------- Forwarded message ----------
> From: amber <am...@hotmail.fr>
> Date: 2012/2/20
> Subject: Re: openEJB fail on second test
> To: users@openejb.apache.org
>
>
> ok @javax.annotation.ManagedBean is the right solution, working for me too
> ^^
>
> thx for help
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4403405.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Fwd: openEJB fail on second test
Posted by Romain Manni-Bucau <rm...@gmail.com>.
it is the second time we have such an issue,
maybe we should scan junit/testng annotations (with a good catch if it is
not available at the classpath) to add automatically these tests to the
managed beans?
- Romain
---------- Forwarded message ----------
From: amber <am...@hotmail.fr>
Date: 2012/2/20
Subject: Re: openEJB fail on second test
To: users@openejb.apache.org
ok @javax.annotation.ManagedBean is the right solution, working for me too
^^
thx for help
--
View this message in context:
http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4403405.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by amber <am...@hotmail.fr>.
ok @javax.annotation.ManagedBean is the right solution, working for me too ^^
thx for help
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4403405.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: openEJB fail on second test
Posted by afryer <ap...@hotmail.com>.
Amber, that sounds really similar to the issue i just had described
http://openejb.979440.n4.nabble.com/Injection-fails-in-any-class-that-didn-t-instantiate-an-embedded-ejb-container-td4396189.html
here . In my case i had an ejb container instantiated just once and reused
across test cases which sounds similar to your issue.
The fix for me was to upgrade to use openejb 4.0.0-beta-2 and use the
@ManagedBean annotation on my test case classes.
--
View this message in context: http://openejb.979440.n4.nabble.com/openEJB-fail-on-second-test-tp4401889p4402907.html
Sent from the OpenEJB User mailing list archive at Nabble.com.