diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/AdapterBusTests.java b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/AdapterBusTests.java new file mode 100644 index 0000000000..67ac4519f8 --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/AdapterBusTests.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; + +import org.junit.Test; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @author Mark Fisher + */ +public class AdapterBusTests { + + @Test + public void testAdapters() throws IOException, InterruptedException { + AbstractApplicationContext context = new ClassPathXmlApplicationContext("adapterBusTests.xml", this.getClass()); + TestSink sink = (TestSink) context.getBean("sink"); + assertNull(sink.get()); + context.start(); + String result = null; + int attempts = 0; + while (result == null && attempts++ < 10) { + Thread.sleep(5); + result = sink.get(); + } + assertNotNull(result); + } + +} diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/InboundChannelAdapterTests.java b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/InboundChannelAdapterTests.java new file mode 100644 index 0000000000..fa5dab78fa --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/InboundChannelAdapterTests.java @@ -0,0 +1,70 @@ +/* + * 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.endpoint; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.springframework.integration.MessageHandlingException; +import org.springframework.integration.endpoint.InboundMethodInvokingChannelAdapter; +import org.springframework.integration.message.Message; + +/** + * @author Mark Fisher + */ +public class InboundChannelAdapterTests { + + @Test + public void testValidMethod() { + InboundMethodInvokingChannelAdapter adapter = + new InboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSource()); + adapter.setMethod("validMethod"); + adapter.afterPropertiesSet(); + Message message = adapter.receive(); + assertEquals("valid", message.getPayload()); + } + + @Test(expected=MessageHandlingException.class) + public void testInvalidMethodWithArg() { + InboundMethodInvokingChannelAdapter adapter = + new InboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSource()); + adapter.setMethod("invalidMethodWithArg"); + adapter.receive(); + } + + @Test(expected=MessageHandlingException.class) + public void testInvalidMethodWithNoReturnValue() { + InboundMethodInvokingChannelAdapter adapter = + new InboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSource()); + adapter.setMethod("invalidMethodWithNoReturnValue"); + adapter.receive(); + } + + @Test(expected=MessageHandlingException.class) + public void testNoMatchingMethodName() { + InboundMethodInvokingChannelAdapter adapter = + new InboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSource()); + adapter.setMethod("noSuchMethod"); + adapter.receive(); + } + +} diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/OutboundChannelAdapterTests.java b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/OutboundChannelAdapterTests.java new file mode 100644 index 0000000000..bf3484d718 --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/OutboundChannelAdapterTests.java @@ -0,0 +1,73 @@ +/* + * 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.endpoint; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.springframework.integration.MessageHandlingException; +import org.springframework.integration.endpoint.OutboundMethodInvokingChannelAdapter; +import org.springframework.integration.message.DocumentMessage; + +/** + * @author Mark Fisher + */ +public class OutboundChannelAdapterTests { + + @Test + public void testValidMethod() { + OutboundMethodInvokingChannelAdapter adapter = + new OutboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSink()); + adapter.setMethod("validMethod"); + adapter.afterPropertiesSet(); + boolean result = adapter.send(new DocumentMessage(1, "test")); + assertTrue(result); + } + + @Test(expected=MessageHandlingException.class) + public void testInvalidMethodWithNoArgs() { + OutboundMethodInvokingChannelAdapter adapter = + new OutboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSink()); + adapter.setMethod("invalidMethodWithNoArgs"); + adapter.afterPropertiesSet(); + adapter.send(new DocumentMessage(1, "test")); + } + + @Test + public void testValidMethodWithIgnoredReturnValue() { + OutboundMethodInvokingChannelAdapter adapter = + new OutboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSink()); + adapter.setMethod("validMethodWithIgnoredReturnValue"); + adapter.afterPropertiesSet(); + boolean result = adapter.send(new DocumentMessage(1, "test")); + assertTrue(result); + } + + @Test(expected=MessageHandlingException.class) + public void testNoMatchingMethodName() { + OutboundMethodInvokingChannelAdapter adapter = + new OutboundMethodInvokingChannelAdapter(); + adapter.setObject(new TestSink()); + adapter.setMethod("noSuchMethod"); + adapter.send(new DocumentMessage(1, "test")); + } + +} diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSink.java b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSink.java new file mode 100644 index 0000000000..2d30faf37b --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSink.java @@ -0,0 +1,44 @@ +/* + * 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.endpoint; + +/** + * @author Mark Fisher + */ +public class TestSink { + + private String result; + + public void validMethod(String s) { + } + + public void invalidMethodWithNoArgs() { + } + + public String validMethodWithIgnoredReturnValue(String s) { + return "ignored"; + } + + public void store(String s) { + this.result = s; + } + + public String get() { + return this.result; + } + +} diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSource.java b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSource.java new file mode 100644 index 0000000000..f027592a88 --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/TestSource.java @@ -0,0 +1,50 @@ +/* + * 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.endpoint; + +/** + * @author Mark Fisher + */ +public class TestSource { + + private boolean fooCalled; + + public String validMethod() { + return "valid"; + } + + public String invalidMethodWithArg(String arg) { + return "invalid"; + } + + public void invalidMethodWithNoReturnValue() { + } + + public String foo() { + if (this.fooCalled) { + try { + Thread.sleep(5000); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + this.fooCalled = true; + return "bar"; + } + +} diff --git a/spring-eai-core/src/test/java/org/springframework/integration/endpoint/adapterBusTests.xml b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/adapterBusTests.xml new file mode 100644 index 0000000000..fddc241650 --- /dev/null +++ b/spring-eai-core/src/test/java/org/springframework/integration/endpoint/adapterBusTests.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +