Added FileOutboundChannelAdapterParserTests.
This commit is contained in:
@@ -43,6 +43,9 @@
|
||||
Configures an outbound Channel Adapter that writes Message payloads to a File.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="channel" type="xsd:string"/>
|
||||
<xsd:attribute name="directory" type="xsd:string" use="required"/>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:file="http://www.springframework.org/schema/integration/file"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/file
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<file:outbound-channel-adapter id="simpleAdapter"
|
||||
channel="testChannel"
|
||||
directory="${java.io.tmpdir}"/>
|
||||
|
||||
<file:outbound-channel-adapter id="adapterWithCustomNameGenerator"
|
||||
channel="testChannel"
|
||||
filename-generator="customFileNameGenerator"
|
||||
directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customFileNameGenerator" class="org.springframework.integration.file.config.CustomFileNameGenerator"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user