diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java index efebb19abd..8a9b33e7c6 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * 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. @@ -16,24 +16,27 @@ package org.springframework.integration.file.config; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.integration.core.MessageChannel; -import org.springframework.integration.file.CompositeFileListFilter; -import org.springframework.integration.file.DefaultDirectoryScanner; -import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Comparator; import java.util.concurrent.PriorityBlockingQueue; -import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.channel.AbstractMessageChannel; +import org.springframework.integration.file.CompositeFileListFilter; +import org.springframework.integration.file.DefaultDirectoryScanner; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Iwein Fuld @@ -51,19 +54,20 @@ public class FileInboundChannelAdapterParserTests { private DirectFieldAccessor accessor; - @Before + @Before public void init() { accessor = new DirectFieldAccessor(source); } + @Test public void channelName() throws Exception { - MessageChannel channel = (MessageChannel) context.getBean("inputDirPoller"); - assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getName()); + AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class); + assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getName()); } @Test - public void inputDirectory() { + public void inputDirectory() { File expected = new File(System.getProperty("java.io.tmpdir")); File actual = (File) accessor.getPropertyValue("directory"); assertEquals("'directory' should be set", expected, actual); @@ -71,11 +75,11 @@ public class FileInboundChannelAdapterParserTests { @Test public void filter() throws Exception { - DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner"); - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner); - assertTrue("'filter' should be set", scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter); + DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner"); + DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner); + assertTrue("'filter' should be set", + scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter); } - @Test public void comparator() throws Exception { @@ -87,6 +91,7 @@ public class FileInboundChannelAdapterParserTests { assertSame("comparator reference not set, ", expected, actual); } + static class TestComparator implements Comparator { public int compare(File f1, File f2) { diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java index 4ae5042cea..4e411c9428 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * 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. @@ -16,23 +16,31 @@ package org.springframework.integration.file.config; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.ApplicationContext; -import org.springframework.integration.core.MessageChannel; -import org.springframework.integration.endpoint.AbstractEndpoint; -import org.springframework.integration.file.*; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Set; import java.util.regex.Pattern; -import static org.junit.Assert.*; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.channel.AbstractMessageChannel; +import org.springframework.integration.endpoint.AbstractEndpoint; +import org.springframework.integration.file.AcceptOnceFileListFilter; +import org.springframework.integration.file.CompositeFileListFilter; +import org.springframework.integration.file.FileListFilter; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.PatternMatchingFileListFilter; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher @@ -57,9 +65,10 @@ public class FileInboundChannelAdapterWithPatternParserTests { this.accessor = new DirectFieldAccessor(source); } + @Test public void channelName() { - MessageChannel channel = (MessageChannel) context.getBean("adapterWithPattern"); + AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class); assertEquals("adapterWithPattern", channel.getName()); } diff --git a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java index c5bcb4c43c..6bf140e77d 100644 --- a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.MessagePublishingErrorHandler; import org.springframework.integration.context.IntegrationContextUtils; @@ -128,12 +129,12 @@ public abstract class TestUtils { } public void registerChannel(String channelName, MessageChannel channel) { - if (channel.getName() != null) { + if (channel instanceof AbstractMessageChannel && ((AbstractMessageChannel) channel).getName() != null) { if (channelName == null) { - Assert.notNull(channel.getName(), "channel name must not be null"); - channelName = channel.getName(); - } else { - Assert.isTrue(channel.getName().equals(channelName), + channelName = ((AbstractMessageChannel) channel).getName(); + } + else { + Assert.isTrue(((AbstractMessageChannel) channel).getName().equals(channelName), "channel name has already been set with a conflicting value"); } } @@ -151,6 +152,7 @@ public abstract class TestUtils { } } + @SuppressWarnings("unchecked") public static MessageHandler handlerExpecting(final Matcher messageMatcher) { return new MessageHandler() { public void handleMessage(Message message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException {