From 6e1ca5edfcec27a3c6e54fd7a4d42a4d08572371 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 2 Jan 2008 18:44:36 +0000 Subject: [PATCH] Added tests for DefaultTargetAdapter. --- .../adapter/DefaultTargetAdapterTests.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/adapter/DefaultTargetAdapterTests.java diff --git a/spring-integration-core/src/test/java/org/springframework/integration/adapter/DefaultTargetAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/adapter/DefaultTargetAdapterTests.java new file mode 100644 index 0000000000..0b23e0d42a --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/adapter/DefaultTargetAdapterTests.java @@ -0,0 +1,81 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; + +import org.springframework.integration.bus.MessageBus; +import org.springframework.integration.channel.PointToPointChannel; +import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.message.Message; + +/** + * @author Mark Fisher + */ +public class DefaultTargetAdapterTests { + + @Test + public void test() throws Exception { + SynchronousQueue queue = new SynchronousQueue(); + TestBean testBean = new TestBean(queue); + MethodInvokingTarget target = new MethodInvokingTarget(); + target.setObject(testBean); + target.setMethod("foo"); + target.afterPropertiesSet(); + DefaultTargetAdapter adapter = new DefaultTargetAdapter(target); + PointToPointChannel channel = new PointToPointChannel(); + adapter.setChannel(channel); + Message message = new GenericMessage("123", "testing"); + channel.send(message); + assertNull(queue.poll()); + MessageBus bus = new MessageBus(); + bus.registerChannel("channel", channel); + bus.registerTargetAdapter("targetAdapter", adapter); + bus.start(); + String result = queue.poll(20, TimeUnit.MILLISECONDS); + assertNotNull(result); + assertEquals("testing", result); + } + + + public static class TestBean { + + private BlockingQueue queue; + + public TestBean(BlockingQueue queue) { + this.queue = queue; + } + + public void foo(String s) { + try { + this.queue.put(s); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + +}