Hi David, thank you very much for your response. I tried the example, but did not quite succeed. I had to change:
* remove the static modifier * remove MessagingClientBean -> What is this? * add ejb-jar.xml in META-INF dir under src-Path of JUNIT: <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0"> <enterprise-beans> <session> <ejb-name>MyTestBean </ejb-name> <ejb-class>myPath.MyTest.MyTestBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar> * start testcase with VM-arguments: -javaagent:${workspace_loc:MyProject}/openejb/lib/openejb-javaagent-3.0.jar -Dopenejb.home=${workspace_loc:MyProject}/openejb But my test (after reading my main EJB-Project with included openejb-jar.xml) stops with: 008-08-28 10:50:39,591 - WARN - Jar not loaded. /home/user/workspace/MyProject/bin. Unable to load bean class: myPath.MyTest.MyTestBean: myPath.MyTest.MyTestBean org.apache.openejb.OpenEJBException: Unable to load bean class: myPath. MyTest.MyTestBean: myPath.MyTest.MyTestBean Mit freundlichen Grüßen / Kind regards Josef Eisele Direkt: +49 (0) 6131 / 914-180 David Blevins <[EMAIL PROTECTED]> 27.08.2008 18:28 Bitte antworten an users@openejb.apache.org An users@openejb.apache.org Kopie Thema Re: Unit-Testing with JMS using embedded openjpa Hi Josef, Swear I sent this yesterday, but here it is :) On Aug 26, 2008, at 7:01 AM, [EMAIL PROTECTED] wrote: > testing my first JMS-experiences in Geronimo 2.1.1, I thought why > not test > it with the openjpa embedded container. We have a lot of stateless > session > beans which work wonderful in the embedded container openejb 3.0, > but for > the injection of the JMS-ConnectionFactory in my test-cases I need a > hint. > > The Testclass should write a Textmessage in a JMS-Queue: > > public class MyTest { > > @Resource > private ConnectionFactory factory; > @Resource > private Queue receivingQueue; > ... > @Test > public void sendMessage() throws Exception{ > Connection connection = null; > MessageProducer messageProducer = null; > Session sess = null; > connection = factory.createConnection(); > sess = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > TextMessage msg = sess.createTextMessage("Hallo > World!!" > ); > messageProducer = sess.createProducer(receivingQueue); > messageProducer.send(msg); > > System.out.println("(client) Test Request Send"); > } > [...] > > My Problem is that factory and receivingQueue are always null, there > is no > Resource-Injection. I tried also: > > @Resource(name="MyConnectionFactoryName") > private ConnectionFactory factory; > We don't yet support injection for the test case itself. One way to do it would be to use an inner class ejb inside the TestCase, such as: public static class MyTest { @Test public void testHelloMessage() throws Exception { Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); InitialContext context = new InitialContext(props); MyTestLocal testBean = (MessagingClientBean.MyTest.MyTestLocal) context.lookup("MyTestBeanLocal"); testBean.sendMessage("Hallo World!!"); } @Stateless public static class MyTestBean implements MyTestLocal { @Resource private ConnectionFactory factory; @Resource private Queue receivingQueue; public void sendMessage(String message) throws Exception { Connection connection = null; MessageProducer messageProducer = null; Session sess = null; connection = factory.createConnection(); sess = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage msg = sess.createTextMessage(message); messageProducer = sess.createProducer(receivingQueue); messageProducer.send(msg); System.out.println("(client) Test Request Send"); } } public static interface MyTestLocal { public void sendMessage(String message) throws Exception; } } Then just add an META-INF/ejb-jar.xml to your test classes dir. (in maven it's src/test/resources/META-INF/ejb-jar.xml) If you're looking to test MDBs we have a basic example for that here which might be useful: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/simple-mdb/ -David BGS Beratungsgesellschaft Software Systemplanung AG Niederlassung Rhein/Main Robert-Koch-Straße 41 55129 Mainz Fon: +49 (0) 6131 / 914-0 Fax: +49 (0) 6131 / 914-400 www.bgs-ag.de Geschäftssitz Mainz Registergericht Amtsgericht Mainz HRB 62 50 Aufsichtsratsvorsitzender Klaus Hellwig Vorstand Hanspeter Gau Hermann Kiefer Nils Manegold