From 2aebfbd6ed510f87e857d01ef03b28b3480d6174 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 22 Sep 2008 04:20:54 +0000 Subject: [PATCH] Added FileOutboundChannelAdapterParserTests. --- .../config/spring-integration-file-1.0.xsd | 3 + .../file/config/CustomFileNameGenerator.java | 33 ++++++++ ...boundChannelAdapterParserTests-context.xml | 33 ++++++++ ...FileOutboundChannelAdapterParserTests.java | 75 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/CustomFileNameGenerator.java create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests-context.xml create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd index dc487c5b16..01f79379c6 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd @@ -43,6 +43,9 @@ Configures an outbound Channel Adapter that writes Message payloads to a File. + + + diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/CustomFileNameGenerator.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/CustomFileNameGenerator.java new file mode 100644 index 0000000000..30ed98fa83 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/CustomFileNameGenerator.java @@ -0,0 +1,33 @@ +/* + * Copyright 2002-2008 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.file.config; + +import java.util.Date; + +import org.springframework.integration.file.FileNameGenerator; +import org.springframework.integration.message.Message; + +/** + * @author Marius Bogoevici + */ +public class CustomFileNameGenerator implements FileNameGenerator { + + public String generateFileName(Message message) { + return "file" + new Date().getTime(); + } + +} diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests-context.xml b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..208f1f5a36 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests-context.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java new file mode 100644 index 0000000000..2fb35dd2b9 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java @@ -0,0 +1,75 @@ +/* + * Copyright 2002-2008 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.file.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; + +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.integration.endpoint.OutboundChannelAdapter; +import org.springframework.integration.file.DefaultFileNameGenerator; +import org.springframework.integration.file.FileWritingMessageConsumer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @author Marius Bogoevici + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class FileOutboundChannelAdapterParserTests { + + @Autowired + @Qualifier("simpleAdapter") + OutboundChannelAdapter simpleAdapter; + + @Autowired + @Qualifier("adapterWithCustomNameGenerator") + OutboundChannelAdapter adapterWithCustomNameGenerator; + + + @Test + public void simpleAdapter() { + DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(simpleAdapter); + FileWritingMessageConsumer consumer = (FileWritingMessageConsumer) + adapterAccessor.getPropertyValue("consumer"); + DirectFieldAccessor consumerAccessor = new DirectFieldAccessor(consumer); + assertEquals(System.getProperty("java.io.tmpdir"), + ((File) consumerAccessor.getPropertyValue("parentDirectory")).getAbsolutePath()); + assertTrue(consumerAccessor.getPropertyValue("fileNameGenerator") instanceof DefaultFileNameGenerator); + } + + @Test + public void adapterWithCustomFileNameGenerator() { + DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapterWithCustomNameGenerator); + FileWritingMessageConsumer consumer = (FileWritingMessageConsumer) + adapterAccessor.getPropertyValue("consumer"); + DirectFieldAccessor consumerAccessor = new DirectFieldAccessor(consumer); + assertEquals(System.getProperty("java.io.tmpdir"), + ((File) consumerAccessor.getPropertyValue("parentDirectory")).getAbsolutePath()); + assertTrue(consumerAccessor.getPropertyValue("fileNameGenerator") instanceof CustomFileNameGenerator); + } + +}