From d723fc6e24eeda421710b567b9d78cd3ed8d1600 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 7 Mar 2008 20:37:28 +0000 Subject: [PATCH] Added tests for RmiSourceAdapterParser and RmiTargetAdapterParser. Also, the element now accepts 'send-timeout' and 'receive-timeout' attributes. --- .../spring-integration-adapters-1.0.xsd | 2 + .../rmi/config/RmiSourceAdapterParser.java | 8 +++ .../config/RmiSourceAdapterParserTests.java | 60 +++++++++++++++++ .../config/RmiTargetAdapterParserTests.java | 64 +++++++++++++++++++ .../config/rmiSourceAdapterParserTests.xml | 19 ++++++ .../config/rmiTargetAdapterParserTests.xml | 16 +++++ 6 files changed, 169 insertions(+) create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml create mode 100644 spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiTargetAdapterParserTests.xml diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd index 4de40072fb..179272e680 100644 --- a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd +++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd @@ -102,6 +102,8 @@ + + diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java index b151f7b86a..efd45a9c3f 100644 --- a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java +++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java @@ -50,6 +50,14 @@ public class RmiSourceAdapterParser extends AbstractSingleBeanDefinitionParser { } builder.addPropertyReference("channel", channelRef); builder.addPropertyValue("expectReply", element.getAttribute("expect-reply").equals("true")); + String sendTimeout = element.getAttribute("send-timeout"); + if (StringUtils.hasText(sendTimeout)) { + builder.addPropertyValue("sendTimeout", Long.parseLong(sendTimeout)); + } + String receiveTimeout = element.getAttribute("receive-timeout"); + if (StringUtils.hasText(receiveTimeout)) { + builder.addPropertyValue("receiveTimeout", Long.parseLong(receiveTimeout)); + } } } diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java new file mode 100644 index 0000000000..56d6e82159 --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2002-2007 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.adapter.rmi.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.adapter.rmi.RmiSourceAdapter; +import org.springframework.integration.channel.MessageChannel; + +/** + * @author Mark Fisher + */ +public class RmiSourceAdapterParserTests { + + @Test + public void testAdapterWithDefaults() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "rmiSourceAdapterParserTests.xml", this.getClass()); + MessageChannel channel = (MessageChannel) context.getBean("testChannel"); + RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithDefaults"); + DirectFieldAccessor accessor = new DirectFieldAccessor(adapter); + assertEquals(channel, accessor.getPropertyValue("channel")); + assertEquals(true, accessor.getPropertyValue("expectReply")); + assertEquals(-1L, accessor.getPropertyValue("sendTimeout")); + assertEquals(-1L, accessor.getPropertyValue("receiveTimeout")); + } + + @Test + public void testAdapterWithCustomProperties() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "rmiSourceAdapterParserTests.xml", this.getClass()); + MessageChannel channel = (MessageChannel) context.getBean("testChannel"); + RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithCustomProperties"); + DirectFieldAccessor accessor = new DirectFieldAccessor(adapter); + assertEquals(channel, accessor.getPropertyValue("channel")); + assertEquals(false, accessor.getPropertyValue("expectReply")); + assertEquals(123L, accessor.getPropertyValue("sendTimeout")); + assertEquals(456L, accessor.getPropertyValue("receiveTimeout")); + } + +} diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java new file mode 100644 index 0000000000..0eca33abee --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2002-2007 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.adapter.rmi.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.rmi.RemoteException; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.adapter.rmi.RmiSourceAdapter; +import org.springframework.integration.adapter.rmi.RmiTargetAdapter; +import org.springframework.integration.channel.SimpleChannel; +import org.springframework.integration.endpoint.DefaultMessageEndpoint; +import org.springframework.integration.message.StringMessage; + +/** + * @author Mark Fisher + */ +public class RmiTargetAdapterParserTests { + + private final SimpleChannel testChannel = new SimpleChannel(); + + + @Before + public void exportRemoteHandler() throws RemoteException { + testChannel.setBeanName("testChannel"); + RmiSourceAdapter sourceAdapter = new RmiSourceAdapter(); + sourceAdapter.setChannel(testChannel); + sourceAdapter.setExpectReply(false); + sourceAdapter.afterPropertiesSet(); + } + + @Test + public void testRmiTargetAdapter() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "rmiTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("adapter"); + assertNotNull(endpoint); + assertEquals(RmiTargetAdapter.class, endpoint.getHandler().getClass()); + RmiTargetAdapter adapter = (RmiTargetAdapter) endpoint.getHandler(); + adapter.handle(new StringMessage("test")); + assertNotNull(testChannel.receive(500)); + } + +} diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml new file mode 100644 index 0000000000..f0d373c7b9 --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiTargetAdapterParserTests.xml b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiTargetAdapterParserTests.xml new file mode 100644 index 0000000000..f398538d20 --- /dev/null +++ b/spring-integration-adapters/src/test/java/org/springframework/integration/adapter/rmi/config/rmiTargetAdapterParserTests.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file