I am facing big problem instantiating weblogic Initial context while running jUnit tests. Application uses Spring / hibernate / weblogic. In application code, methods uses JMS proxy to send messages to JMS, Queues are setup on weblogic.
My problem is while JUnit tests currently I need to keep weblogic server running on local machine just to initialize WeblogicInitialContext which is used in JMS proxies. My junit test don't need to send anything to server, NO JMS , NO datasources. All are handeled by spring unit test framework. I want to decouple/ get rid of Weblogic for my junit tests. Please suggest. Here is my code:
This is my test application context XML:
<beans xmlns="http://www.springframework.org/schema/beans"
...
>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<util:properties id="webLogicInitialContext">
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://localhost:7001</prop>
<prop key="java.naming.security.principal">admin</prop>
<prop key="java.naming.security.credentials">password</prop>
</util:properties>
<jee:jndi-lookup id="responseProxyConnectionFactory"
jndi-name="jms/ConnectionFactory" environment-ref="webLogicInitialContext"/>
<bean id="responseProxyJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory"
ref="responseProxyConnectionFactory" />
</bean>
</beans>
This is One Java class methods :
public class Order {
public void addOrder(OrderRequest addOrderRequest) {
PurchaseOrder newOrder = orderHelper.createOrder(addOrderRequest);
orderDaoHibernate.addOrder(newOrder);
responseProxy.send(newOrder);
}
}
My Test :
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( {TransactionalTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class })
@ContextConfiguration(locations={"/test-application-context.xml"})
@TransactionConfiguration(defaultRollback=true)
public class TestOrder {
@Test
@Transactional
public void testMyOrder(){
Order ord = new Order();
OrderRequest req = new OrderRequest();
....
ord.addOrder(req);
}
}
If I run this test the Spring framework try to load the WeblogicInitialContext , and if local weblogic not running it throws exceptions.
I don't want to send any JMS message when I call this method from Junit. How can I create dummy WeblogicInitialContext.
Please help.
Some part of Exception;
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'responseProxyConnectionFactory': Invocation of init method failed; nested exception is javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://localhost:7001: Destination unreachable; nested exception is: