Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock JmsTemplate for integration testing

Need to mock JmsTemplate for integration testing in my application.

In my appcontext.xml

<bean id="core_connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="core_jndiTemplate" />
        </property>
        <property name="jndiName">
            <value>ConnectionFactory</value>
        </property>
    </bean>

    <bean id="core_jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="core_connectionFactory" />
        <property name="defaultDestination" ref="core_destination" />
    </bean>


    <bean id="core_destination" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate">
            <ref bean="core_jndiTemplate" />
        </property>
        <property name="jndiName">
            <value>queue/CoreQueue</value>
        </property>
    </bean>

need to mock the jmstemplete in my testcontext.xml. Thanks in advance.

like image 945
sp_user123 Avatar asked Dec 19 '22 12:12

sp_user123


1 Answers

Or in Spring 4 flavour ;)

@Bean
public JmsTemplate jmsTemplate() {
    return Mockito.mock(JmsTemplate.class);
}

Exactly as @Stephane said, but without xml.
But still I would recommend you use an embedded broker for your integration tests. As it would allow you to check what exactly is coming to the queue.

like image 184
G. Demecki Avatar answered Jan 02 '23 01:01

G. Demecki