From 1ed45c6c9a82736504dee11ec35c00112d9104d0 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 15 Jun 2009 13:27:20 +0000 Subject: [PATCH] INT-667 --- .../AbstractFilePayloadTransformerParser.java | 9 ++- ...ToStringTransformerParserTests-context.xml | 27 +++++++++ .../FileToStringTransformerParserTests.java | 56 +++++++++++++++++++ ...eToStringTransformerParserTests.properties | 1 + 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests-context.xml create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java create mode 100644 org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/fileToStringTransformerParserTests.properties diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/AbstractFilePayloadTransformerParser.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/AbstractFilePayloadTransformerParser.java index 4bb9c24cca..2d495b7e08 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/AbstractFilePayloadTransformerParser.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/AbstractFilePayloadTransformerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -21,6 +21,7 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractTransformerParser; +import org.springframework.util.StringUtils; /** * Base class for File payload transformer parsers. @@ -31,8 +32,10 @@ public abstract class AbstractFilePayloadTransformerParser extends AbstractTrans @Override protected final void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - boolean deleteFiles = "true".equals(element.getAttribute("delete-files").toLowerCase()); - builder.addPropertyValue("deleteFiles", deleteFiles); + String deleteFiles = element.getAttribute("delete-files"); + if (StringUtils.hasText(deleteFiles)) { + builder.addPropertyValue("deleteFiles", deleteFiles); + } this.postProcessTransformer(element, parserContext, builder); } diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests-context.xml b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests-context.xml new file mode 100644 index 0000000000..db8c21de6a --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests-context.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java new file mode 100644 index 0000000000..3109e4f091 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2009 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 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.EventDrivenConsumer; +import org.springframework.integration.file.transformer.FileToStringTransformer; +import org.springframework.integration.transformer.MessageTransformingHandler; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class FileToStringTransformerParserTests { + + @Autowired + @Qualifier("transformer") + EventDrivenConsumer endpoint; + + @Test + public void checkDeleteFilesValue() { + DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint); + MessageTransformingHandler handler = (MessageTransformingHandler) + endpointAccessor.getPropertyValue("handler"); + DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); + FileToStringTransformer transformer = (FileToStringTransformer) + handlerAccessor.getPropertyValue("transformer"); + DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer); + assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles")); + } + +} diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/fileToStringTransformerParserTests.properties b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/fileToStringTransformerParserTests.properties new file mode 100644 index 0000000000..260783750d --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/fileToStringTransformerParserTests.properties @@ -0,0 +1 @@ +files.delete=true \ No newline at end of file