I have a servlet for which i am writing test case for , have it working already but at the end of the code some JMS calls are made which is throwing exception "javax.naming.NameNotFoundException" , i had this error for EJB beans as well and datasource , so i had them injected on @BeforeClass and they are working fine now i need same to done for JMS calls as follows.
my jms calls in servlet is as follows .
ctx=new InitialContext();
queueConnectionFactory=(QueueConnectionFactory) ctx.lookup("jms/queueConnectionFactory");
queue=(Queue) ctx.lookup("jms/reportQueue");
queueConnection=queueConnectionFactory.createQueueConnection();
queueSession=queueConnection.createQueueSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
queueSender=queueSession.createSender(queue);
message=queueSession.createObjectMessage(etEDocRequestParams);
queueSender.send(message);
But i don't know how JMS object can be inserted into Jndi without container. Please help.
My test @beforeclass is creating a fake InitialContext and it's working for getting DataSource and using EJBMOCK it's working for EJB as well. please see the code bellow.
public class BookingSaveTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("com.evermind.sql.DriverManagerDataSource");
ds.setJdbcUrl("jdbc:oracle:thin:@192.168.74.49:1521:xyz");
ds.setUser("devpxyz");
ds.setPassword("pass123");
ds.setMaxPoolSize(1);
ds.setMaxPoolSize(15);
ds.setAcquireIncrement(3);
ds.setMaxStatementsPerConnection(100);
//ds.setAutomaticTestTable("c3p0_test_table");
ds.setNumHelperThreads(20);
SimpleNamingContextBuilder builder = null;
builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
builder.bind("java:comp/env/jdbc/DB", ds);
//bellow this is mocking EJB container
MockContextFactory.setAsInitial();
// Create an instance of the MockContainer and pass the JNDI context that
// it will use to bind EJBs.
MockContainer mockContainer = new MockContainer( new InitialContext() );
SessionBeanDescriptor statefulSampleDescriptor =
new SessionBeanDescriptor( "PRQSessionBean",
PRQSessionHome.class, PRQSession.class, PRQSessionBean.class );
// Mark this bean as stateful. Stateless is the default.
statefulSampleDescriptor.setStateful( true );
mockContainer.deploy( statefulSampleDescriptor );
}
..
..
..
}