Added tests for RmiSourceAdapterParser and RmiTargetAdapterParser. Also, the <rmi-source/> element now accepts 'send-timeout' and 'receive-timeout' attributes.

This commit is contained in:
Mark Fisher
2008-03-07 20:37:28 +00:00
parent 5191432a8f
commit d723fc6e24
6 changed files with 169 additions and 0 deletions

View File

@@ -102,6 +102,8 @@
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
<xsd:attribute name="send-timeout" type="xsd:long"/>
<xsd:attribute name="receive-timeout" type="xsd:long"/>
<xsd:attribute name="channel" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -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));
}
}
}

View File

@@ -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"));
}
}

View File

@@ -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));
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus/>
<channel id="testChannel"/>
<rmi-source id="adapterWithDefaults" channel="testChannel"/>
<rmi-source id="adapterWithCustomProperties" channel="testChannel"
expect-reply="false" send-timeout="123" receive-timeout="456"/>
</beans:beans>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus/>
<channel id="localChannel"/>
<rmi-target id="adapter" local-channel="localChannel" remote-channel="testChannel" host="localhost"/>
</beans:beans>