INT-1223, INT-1226. The fix is temporary as we are considering refactoring of ARPMH and supporting classes (see INT-1227), however test cases are now in place to aid in refactoring efforts

This commit is contained in:
Oleg Zhurakousky
2010-07-03 12:56:42 +00:00
parent 5d154e11d7
commit 682e8166eb
9 changed files with 256 additions and 28 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.jms.config;
import java.io.File;
import org.junit.Before;
/**
* @author Oleg Zhurakousky
*
*/
public class ActiveMqTestUtils {
@Before
public static void prepare() {
System.out.println("####### Refreshing ActiveMq ########");
File activeMqTempDir = new File("activemq-data");
deleteDir(activeMqTempDir);
}
/*
*
*/
private static void deleteDir(File directory){
if (directory.exists()){
String[] children = directory.list();
if (children != null){
for (int i=0; i < children.length; i++) {
deleteDir(new File(directory, children[i]));
}
}
}
directory.delete();
}
}

View File

@@ -42,6 +42,7 @@ public class ExceptionHandlingSiConsumerTests {
@Test
public void nonSiProducer_siConsumer_sync_withReturn() throws Exception {
ActiveMqTestUtils.prepare();
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
JmsTemplate jmsTemplate = new JmsTemplate(applicationContext.getBean("connectionFactory", ConnectionFactory.class));
Destination request = applicationContext.getBean("requestQueue", Destination.class);
@@ -61,6 +62,7 @@ public class ExceptionHandlingSiConsumerTests {
}
@Test
public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception {
ActiveMqTestUtils.prepare();
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
JmsTemplate jmsTemplate = new JmsTemplate(applicationContext.getBean("connectionFactory", ConnectionFactory.class));
Destination request = applicationContext.getBean("requestQueue", Destination.class);
@@ -81,6 +83,7 @@ public class ExceptionHandlingSiConsumerTests {
@Test
public void nonSiProducer_siConsumer_sync_withOutboundGateway() throws Exception{
ActiveMqTestUtils.prepare();
final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class);
String reply = gateway.echo("echoWithExceptionChannel");
@@ -88,30 +91,6 @@ public class ExceptionHandlingSiConsumerTests {
applicationContext.close();
}
@Before
public void prepare() throws Exception {
System.out.println("####### Refreshing ActiveMq ########");
File activeMqTempDir = new File("activemq-data");
this.deleteDir(activeMqTempDir);
}
/*
*
*/
private void deleteDir(File directory){
if (directory.exists()){
String[] children = directory.list();
if (children != null){
for (int i=0; i < children.length; i++) {
deleteDir(new File(directory, children[i]));
}
}
}
directory.delete();
}
public static class SampleService{
public String echoWithException(String value){
throw new SampleException("echoWithException");

View File

@@ -29,6 +29,7 @@ import org.springframework.jms.support.converter.MessageConverter;
/**
* @author Jonas Partner
* @author Oleg Zhurakousky
*/
public class JmsOutboundGatewayParserTests {
@@ -54,5 +55,25 @@ public class JmsOutboundGatewayParserTests {
Object order = accessor.getPropertyValue("order");
assertEquals(99, order);
}
@Test
public void gatewayMaintainsReplyChannel() {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"gatewayMaintainsReplyChannel.xml", this.getClass());
SampleGateway gateway = context.getBean("gateway", SampleGateway.class);
String result = gateway.echo("hello");
assertEquals("HELLO", result);
}
public static interface SampleGateway{
public String echo(String value);
}
public static class SampleService{
public String echo(String value){
return value.toUpperCase();
}
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms">
<int:gateway id="gateway"
service-interface="org.springframework.integration.jms.config.JmsOutboundGatewayParserTests$SampleGateway"
default-request-channel="requests">
<int:method name="echo">
<int:header name="foo" value="bar"/>
</int:method>
</int:gateway>
<int:chain input-channel="requests">
<int-jms:outbound-gateway request-destination="requestQueue"
reply-destination="replyQueue"
connection-factory="connectionFactory"/>
</int:chain>
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="request.queue"/>
</bean>
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="reply.queue"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<int-jms:inbound-gateway request-channel="jmsInput" request-destination="requestQueue"/>
<int:channel id="jmsInput"/>
<int:service-activator input-channel="jmsInput">
<bean class="org.springframework.integration.jms.config.JmsOutboundGatewayParserTests$SampleService"/>
</int:service-activator>
</beans>