title: How to create mock/ dummy Initial context for Junit tests out of container
body: <p>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.</p>
  
  <p>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:</p>
  
  <p>This is my test application context XML:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  ...
  &gt;
  
  &lt;bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;util:properties id="webLogicInitialContext"&gt;
      &lt;prop key="java.naming.factory.initial"&gt;weblogic.jndi.WLInitialContextFactory&lt;/prop&gt;
      &lt;prop key="java.naming.provider.url"&gt;t3://localhost:7001&lt;/prop&gt;
      &lt;prop key="java.naming.security.principal"&gt;admin&lt;/prop&gt;
      &lt;prop key="java.naming.security.credentials"&gt;password&lt;/prop&gt;
  &lt;/util:properties&gt;
  
  &lt;jee:jndi-lookup id="responseProxyConnectionFactory"
      jndi-name="jms/ConnectionFactory" environment-ref="webLogicInitialContext"/&gt;
  
  &lt;bean id="responseProxyJmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory"
          ref="responseProxyConnectionFactory" /&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is One  Java class methods :</p>
  
  <pre><code>public class Order {
      public void addOrder(OrderRequest addOrderRequest) {
          PurchaseOrder newOrder = orderHelper.createOrder(addOrderRequest);
          orderDaoHibernate.addOrder(newOrder);
          responseProxy.send(newOrder);
  
      }
  }
  </code></pre>
  
  <p>My Test :</p>
  
  <pre><code>@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);
      }
  
  }
  </code></pre>
  
  <p>If I run this test the Spring framework try to load the WeblogicInitialContext , and if local weblogic not running it throws exceptions.</p>
  
  <p>I don't want to send any JMS message when I call this method from Junit.
  How can I create dummy WeblogicInitialContext.</p>
  
  <p>Please help.</p>
  
  <p>Some part of Exception;</p>
  
  <pre><code>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: 
  </code></pre>