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