1 Reply Latest reply on Nov 10, 2017 11:48 AM by Justin Bertram

    Error while running junit for camel application connecting to hornetQ

    ravi narayanan Expert

      Hello,

      Iam trying to write junit test for a camel application which connects to hornet Q.The application is working fine in container.

       

      In the actual application iam using embeded hornetQ which comes with fuse 6.3,The connection factory is defined in standalone-full xml and iam using "java:/ConnectionFactory" in the JNDIObjectfactorybean.

       

      while running testcase Iam getting the error:

       

       

          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource [META-INF/spring/bean-declarations.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: scheme java not recognized

       

       

       

       

      Standalonefull xml messaging subsystem configuration:

       

       

                  <jms-connection-factories>

                      <connection-factory name="InVmConnectionFactory">

                          <connectors>

                              <connector-ref connector-name="in-vm"/>

                          </connectors>

                          <entries>

                              <entry name="java:/ConnectionFactory"/>

                          </entries>

                      </connection-factory>

                      <connection-factory name="RemoteConnectionFactory">

                          <connectors>

                              <connector-ref connector-name="netty"/>

                          </connectors>

                          <entries>

                              <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>

                          </entries>

                      </connection-factory>

                      <pooled-connection-factory name="hornetq-ra">

                          <transaction mode="xa"/>

                          <connectors>

                              <connector-ref connector-name="in-vm"/>

                          </connectors>

                          <entries>

                              <entry name="java:/JmsXA"/>

                          </entries>

                      </pooled-connection-factory>

                  </jms-connection-factories>

       

       

      Bean declarations for hornetQ JMS component:

       

       

          <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

          <property name="jndiName" value="java:/ConnectionFactory" />

          </bean>

        

          <bean id="hornetq" class="org.apache.camel.component.jms.JmsComponent">

          <property name="connectionFactory" ref="jmsConnectionFactory" />

          </bean>

       

       

       

       

      In order to mock the HornetQ server i have added the below hornerQ configuration in test resources as below.

       

       

      hornetq-configuration.xml :

       

       

           <configuration xmlns="urn:hornetq">

                       

          <paging-directory>target/data/paging</paging-directory>

          <bindings-directory>target/data/bindings</bindings-directory>

          <persistence-enabled>false</persistence-enabled>

          <journal-directory>target/data/journal</journal-directory>

          <journal-min-files>10</journal-min-files>

          <large-messages-directory>target/data/large-messages</large-messages-directory>

          <security-enabled>false</security-enabled>

        

          <connectors>

          <connector name="invm-connector">

          <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>

          </connector>

          </connectors>

        

          <acceptors>

          <acceptor name="invm-acceptor">

          <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>

          </acceptor>

          </acceptors>

       

          </configuration>

       

      hornetq-jms.xml :

            

          <configuration xmlns="urn:hornetq">

        

          <connection-factory name="ConnectionFactory">

          <connectors>

          <connector-ref connector-name="invm-connector" />

          </connectors>

        

          <entries>

          <entry name="java:/ConnectionFactory" />

          </entries>

          </connection-factory>

        

          <queue name="TEST.QUEUE">

          <entry name="TEST.QUEUE" />

          </queue>

        

          </configuration>

       

       

      Error details while running Junit:

       

       

       

       

       

          java.lang.IllegalStateException: Failed to load ApplicationContext

          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)

          at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)

          at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:160)

          at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:101)

          at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)

          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)

          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

          at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

          at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)

          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource [META-INF/spring/bean-declarations.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: scheme java not recognized

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)

          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:938)

          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

          at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:147)

          at org.apache.camel.test.spring.CamelSpringTestContextLoader.loadContext(CamelSpringTestContextLoader.java:84)

          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:69)

          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95)

          ... 25 more

          Caused by: javax.naming.NamingException: scheme java not recognized

          at org.apache.camel.util.jndi.JndiContext.lookup(JndiContext.java:218)

          at javax.naming.InitialContext.lookup(InitialContext.java:417)

          at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)

          at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)

          at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)

          at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)

          at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)

          at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)

          at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)

          at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1573)

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511)

          ... 38 more

       

       

      Am i mising something?

        • 1. Re: Error while running junit for camel application connecting to hornetQ
          Justin Bertram Master

          Am i mising something?

          Yes, I believe you are missing something.  The stack-trace you posted doesn't contain any HornetQ or JBoss Fuse code whatsoever which leads me to believe you've misconfigured something in Spring.  It seems to me that you should be providing some configuration details about the JNDI lookup so Spring knows what implementation to use (e.g. org.springframework.jndi.JndiTemplate).  These details will be different depending on your environment (e.g. HornetQ standalone vs. JBoss Fuse).