You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by David Blevins <da...@visi.com> on 2008/10/08 23:24:41 UTC
Re: Override annotations in ejb-jar.xml for a test case
On Sep 22, 2008, at 5:33 AM, Marcin Kwapisz wrote:
> Hi,
>
> I would like to add an interceptor to my EJB but only in a test. I
> have separate ejb-jar.xml for tests and all my EJBs are annotated.
We don't have any functionality for supplying an alternate ejb-jar.xml
for testing purposes. It's not a bad idea and is something we might
be able to add after we get the 3.1 release out the door.
> When ejb-jar.xml is empty everything works fine. When I change ejb-
> jar and add for example:
>
> <assembly-descriptor>
> <interceptor-binding>
> <ejb-name>StudentEndpointBean</ejb-name>
> <interceptor-
> class>pl.zsk.sos.interceptor.TestInterceptor</interceptor-class>
> </interceptor-binding>
> </assembly-descriptor>
>
> automatic configuration does not find my EJBs and I get
> javax.naming.NameNotFoundException
This might be because the ejb-jar.xml is with the ejbs that are
annotated.
A small workaround might be to add an interceptor to your main app and
have it look for a special system property of your creation in its
constructor. The system property can be the name of an interceptor
class that it should delegate to. If the system property is not
specified then it does nothing. The test case could set the special
system property to point to pl.zsk.sos.interceptor.TestInterceptor or
any other interceptor you wish to write for a given test case. You
could potentially then have an interceptor dedicated to each test case
to help with testing yet still only have one active at a time.
-David
Re: Override annotations in ejb-jar.xml for a test case
Posted by David Blevins <da...@visi.com>.
On Oct 9, 2008, at 3:16 AM, Marcin Kwapisz wrote:
> Correct me if I am wrong: when ejb-jar is empty OpenEJB process all
> class files (in classes and test-classes) and looks for annotated
> EJBs. When ejb-jar is modified, OpenEJB process that file and looks
> for annotated EJBs in test-classes only.
We look for annotated ejbs in classes/ if we find a classes/META-INF/
ejb-jar.xml file and the ejb-jar.xml file does not have 'metadata-
complete' attribute set to 'true'. Aside from the metadata-complete
attribute, the contents of the ejb-jar.xml do not prevent searching
for annotations or annotated ejbs. The classes/ directory is treated
as a single ejb jar and the contents of the classes/META-INF/ejb-
jar.xml apply only to the beans in classes/.
The same rule applies for test-classes/. Specifically, we look for
annotated ejbs in test-classes/ if we find a test-classes/META-INF/ejb-
jar.xml file and the ejb-jar.xml file does not have 'metadata-
complete' attribute set to 'true' and the test-classes/ directory is
treated as a single ejb jar, separate from classes/, and the contents
of the test-classes/META-INF/ejb-jar.xml apply only to the beans in
test-classes/.
Hope that helps.
-David
RE: Override annotations in ejb-jar.xml for a test case
Posted by Marcin Kwapisz <mk...@zsk.p.lodz.pl>.
Hi,
> We don't have any functionality for supplying an alternate ejb-jar.xml
> for testing purposes. It's not a bad idea and is something we might
> be able to add after we get the 3.1 release out the door.
[Marcin Kwapisz]
My Maven2 profile is as follows. <resource> directs to folder src/test/resources/Toplink (METAINF) where modified ejb-jar.xml and persistence.xml exist.
<profile>
<id>TestEJB_Toplink</id>
<activation>
<property>
<name>env</name>
<value>testtoplink</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>toplink.essentials</groupId>
<artifactId>toplink-essentials-agent</artifactId>
<version>2.1-53</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>toplink.essentials</groupId>
<artifactId>toplink-essentials</artifactId>
<version>2.1-53</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>zsk.samples</groupId>
<artifactId>ToplinkExternalContainer</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/test/resources/Toplink</directory>
</resource>
</resources>
</build>
</profile>
> This might be because the ejb-jar.xml is with the ejbs that are
> annotated.
[Marcin Kwapisz]
Correct me if I am wrong: when ejb-jar is empty OpenEJB process all class files (in classes and test-classes) and looks for annotated EJBs. When ejb-jar is modified, OpenEJB process that file and looks for annotated EJBs in test-classes only.
Regards
--
Marcin Kwapisz
Division of Computer Networks
Technical Univeristy of Lodz, Poland