Removing 'file' package contents from 'org.springframework.integration.adapter'. The new 'org.springframework.integration.file' module replaces it.
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultFileNameGeneratorTests {
|
||||
|
||||
@Test
|
||||
public void testWithFileNamePropertyProvided() {
|
||||
Message<String> message = MessageBuilder.withPayload("testing")
|
||||
.setHeader(FileNameGenerator.FILENAME_PROPERTY_KEY, "foo.bar").build();
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo.bar", filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutFileNamePropertyProvided() {
|
||||
Message<String> message = new GenericMessage<String>("testing");
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertTrue(filename.startsWith("" + message.getHeaders().getId()));
|
||||
assertTrue(filename.endsWith(".msg"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FileSourceTests {
|
||||
|
||||
private FileSource fileSource;
|
||||
|
||||
private static final String INPUT_DIR = System.getProperty("java.io.tmpdir") + "/"
|
||||
+ FileSourceTests.class.getCanonicalName();
|
||||
|
||||
@BeforeClass
|
||||
public static void createTmpDir() {
|
||||
new File(INPUT_DIR).mkdirs();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void refreshFileSource() {
|
||||
fileSource = new FileSource(new FileSystemResource(INPUT_DIR));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanOutTmp() {
|
||||
for (File file : new File(INPUT_DIR).listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void removeTmp() {
|
||||
if (!new File(INPUT_DIR).delete()) {
|
||||
throw new RuntimeException("failed to clean up directory [" + INPUT_DIR + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFile() {
|
||||
assertNull("There should be no message on the source", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedEmptyFile() throws Exception {
|
||||
new File(INPUT_DIR + "/test").createNewFile();
|
||||
assertNotNull("No file received after writing to input directory", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedWriter() throws Exception {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(INPUT_DIR + "/test")));
|
||||
writer.write("some stuff");
|
||||
writer.close();
|
||||
assertNotNull("No file received after writing to input directory", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* This test shows the how not to do it (i.e. without a proper external
|
||||
* trigger)
|
||||
*/
|
||||
public void testOpenWriter() throws Exception {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(INPUT_DIR + "/test")));
|
||||
writer.write("some stuff");
|
||||
// don't close the writer yet
|
||||
Message<File> received = fileSource.receive();
|
||||
assertNotNull("incomplete file was not received", received);
|
||||
fileSource.onSend(received);
|
||||
writer.write("some more stuff");
|
||||
writer.close();
|
||||
assertNotNull("something shoulda happened don't you think?", received);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RegexPatternFilenameFilterTests {
|
||||
|
||||
@Test
|
||||
public void match() {
|
||||
File file = new File("/some/path/test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.setPattern(Pattern.compile("[a-z]+\\.txt"));
|
||||
assertTrue(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noMatch() {
|
||||
File file = new File("/some/path/Test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.setPattern(Pattern.compile("[a-z]+\\.txt"));
|
||||
assertFalse(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void patternNotSet() {
|
||||
File file = new File("/some/path/test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.accept(file.getParentFile(), file.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternEditorInContext() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"regexPatternFilenameFilterTests.xml", this.getClass());
|
||||
FilenameFilter filter = (FilenameFilter) context.getBean("filter");
|
||||
File file = new File("/some/path/foo.txt");
|
||||
assertTrue(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPatternSyntax() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("invalidRegexPatternFilenameFilterTests.xml", this.getClass());
|
||||
throw new IllegalStateException("context creation should have failed");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals(BeanCreationException.class, e.getClass());
|
||||
Throwable cause1 = e.getCause();
|
||||
assertEquals(TypeMismatchException.class, cause1.getClass());
|
||||
Throwable cause2 = cause1.getCause();
|
||||
assertEquals(PatternSyntaxException.class, cause2.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFileFilter implements FileFilter {
|
||||
|
||||
public boolean accept(File pathname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFilenameFilter implements FilenameFilter {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.integration.adapter.file.FileNameGenerator;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class CustomNameGenerator implements FileNameGenerator{
|
||||
|
||||
public String generateFileName(Message<?> message) {
|
||||
return "file" + new Date().getTime();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileSource;
|
||||
import org.springframework.integration.adapter.file.RegexPatternFilenameFilter;
|
||||
import org.springframework.integration.adapter.file.TextFileMessageCreator;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileSourceDefaultType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceDefault");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof FileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceTextType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceText");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof TextFileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceBinaryType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceBinary");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof ByteArrayFileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceFileType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceFile");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof FileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomMessageCreator");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof CustomMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithTypeAndCustomMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceTypeAndCustom");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof CustomMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomFileFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFileFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FileFilter filter = (FileFilter) context.getBean("customFileFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("fileFilter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomFilenameFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFilenameFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FilenameFilter filter = (FilenameFilter) context.getBean("customFilenameFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("filenameFilter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithRegexPatternFilenameFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithRegexFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
RegexPatternFilenameFilter filter = (RegexPatternFilenameFilter) accessor.getPropertyValue("filenameFilter");
|
||||
assertFalse(filter.accept(null, "foo.htm"));
|
||||
assertTrue(filter.accept(null, "foo.txt"));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
public void testFileSourceWithFileFilterAndFilenameFilterNotAllowed() throws Throwable {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("fileSourceWithTooManyFilters.xml", this.getClass());
|
||||
fail();
|
||||
}
|
||||
catch (BeanDefinitionStoreException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithFileAndNotDirectory() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("fileSourceWithFileDirectory.xml", this.getClass());
|
||||
fail();
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertTrue(ex.getCause().getCause().getMessage().indexOf("is not a directory") > 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.DefaultFileNameGenerator;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
import org.springframework.integration.adapter.file.SimpleFileMessageMapper;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileTargetParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileTarget() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetParserTests.xml", this.getClass());
|
||||
FileTarget target = (FileTarget) context.getBean("target");
|
||||
DirectFieldAccessor targetFieldAccessor = new DirectFieldAccessor(target);
|
||||
SimpleFileMessageMapper messageMapper = (SimpleFileMessageMapper) targetFieldAccessor
|
||||
.getPropertyValue("messageMapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(messageMapper);
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), ((File) mapperAccessor.getPropertyValue("parentDirectory"))
|
||||
.getAbsolutePath());
|
||||
assertTrue(mapperAccessor.getPropertyValue("fileNameGenerator") instanceof DefaultFileNameGenerator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileTargetWithCustomFilenameGenerator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetParserTests.xml", this.getClass());
|
||||
FileTarget target = (FileTarget) context.getBean("targetWithCustomNameGenerator");
|
||||
DirectFieldAccessor targetFieldAccessor = new DirectFieldAccessor(target);
|
||||
SimpleFileMessageMapper messageMapper = (SimpleFileMessageMapper) targetFieldAccessor
|
||||
.getPropertyValue("messageMapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(messageMapper);
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), ((File) mapperAccessor.getPropertyValue("parentDirectory"))
|
||||
.getAbsolutePath());
|
||||
assertTrue(mapperAccessor.getPropertyValue("fileNameGenerator") instanceof CustomNameGenerator);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?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"
|
||||
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">
|
||||
|
||||
<si:file-source id="fileSourceDefault" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceText" type="text" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceBinary" type="binary" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceFile" type="file" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomMessageCreator" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFileFilter" file-filter="customFileFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFilenameFilter" filename-filter="customFilenameFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithRegexFilter" filename-pattern="fo+\.[tx]{3}" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceTypeAndCustom" type="text" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customMessageCreator" class="org.springframework.integration.adapter.file.config.CustomMessageCreator"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?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"
|
||||
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">
|
||||
|
||||
<si:file-source id="fileSourceDefault" directory="fileSourceWithFileDirectory.xml"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?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"
|
||||
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">
|
||||
|
||||
<si:file-source id="fileSource"
|
||||
directory="${java.io.tmpdir}"
|
||||
file-filter="customFileFilter"
|
||||
filename-filter="customFilenameFilter"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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"
|
||||
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">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:file-target id="target" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-target id="targetWithCustomNameGenerator" name-generator="customFileNameGenerator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customFileNameGenerator" class="org.springframework.integration.adapter.file.config.CustomNameGenerator"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.adapter.file.RegexPatternFilenameFilter">
|
||||
<property name="pattern" value="[fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.adapter.file.RegexPatternFilenameFilter">
|
||||
<property name="pattern" value="fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
@@ -22,9 +22,10 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.adapter.file.Backlog;
|
||||
import org.springframework.integration.adapter.file.FileSnapshot;
|
||||
import org.springframework.integration.adapter.ftp.Backlog;
|
||||
import org.springframework.integration.adapter.ftp.FileSnapshot;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -1,4 +1,20 @@
|
||||
package org.springframework.integration.adapter.file;
|
||||
/*
|
||||
* 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.adapter.ftp;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -9,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -13,26 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertSame;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*
|
||||
*/
|
||||
public class QueuedFTPClientPoolTest {
|
||||
|
||||
@@ -42,12 +43,14 @@ public class QueuedFTPClientPoolTest {
|
||||
|
||||
private Object[] allMocks = new Object[] { factoryMock };
|
||||
|
||||
|
||||
@Before
|
||||
public void initializeSubject() throws Exception {
|
||||
this.pool = new QueuedFTPClientPool(5);
|
||||
pool.setFactory(factoryMock);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void get() throws Exception {
|
||||
FTPClient expectedClient = new FTPClient();
|
||||
@@ -95,6 +98,7 @@ public class QueuedFTPClientPoolTest {
|
||||
verify(allMocks);
|
||||
}
|
||||
|
||||
|
||||
private FTPClient mockedFTPClient() throws Exception {
|
||||
FTPClient mock = createNiceMock(FTPClient.class);
|
||||
expect(mock.isConnected()).andReturn(true).anyTimes();
|
||||
@@ -102,4 +106,5 @@ public class QueuedFTPClientPoolTest {
|
||||
replay(mock);
|
||||
return mock;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
public class CollectionSplitter {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Splitter public List split(Message<? extends Collection> message) {
|
||||
return new ArrayList(message.getPayload());
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -30,5 +30,5 @@ public class CustomMessageCreator implements MessageCreator<File, String>{
|
||||
public Message<String> createMessage(File object) {
|
||||
return new GenericMessage<String> (object.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,20 +18,14 @@ package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.TextFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.config.CustomMessageCreator;
|
||||
import org.springframework.integration.adapter.ftp.FtpSource;
|
||||
import org.springframework.integration.message.DefaultMessageCreator;
|
||||
|
||||
|
||||
@@ -52,6 +52,6 @@
|
||||
message-creator="customMessageCreator"/>
|
||||
|
||||
<bean id="customMessageCreator"
|
||||
class="org.springframework.integration.adapter.file.config.CustomMessageCreator"/>
|
||||
class="org.springframework.integration.adapter.ftp.config.CustomMessageCreator"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user