From b7756e881d5f42f4ecbd608ca462dd1240df6e87 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 22 Sep 2008 05:17:30 +0000 Subject: [PATCH] Removing 'file' package contents from 'org.springframework.integration.adapter'. The new 'org.springframework.integration.file' module replaces it. --- .../file/AbstractFileMessageCreator.java | 82 --------- .../file/ByteArrayFileMessageCreator.java | 47 ----- .../file/DefaultFileNameGenerator.java | 36 ---- .../adapter/file/FileMessageCreator.java | 43 ----- .../adapter/file/FileNameGenerator.java | 33 ---- .../integration/adapter/file/FileSource.java | 160 ----------------- .../integration/adapter/file/FileTarget.java | 45 ----- .../file/RegexPatternFilenameFilter.java | 46 ----- .../adapter/file/SimpleFileMessageMapper.java | 79 --------- .../adapter/file/TextFileMessageCreator.java | 48 ----- .../adapter/file/config/FileSourceParser.java | 128 -------------- .../adapter/file/config/FileTargetParser.java | 72 -------- .../AbstractDirectorySource.java | 3 +- .../adapter/{file => ftp}/Backlog.java | 2 +- .../adapter/{file => ftp}/FileSnapshot.java | 2 +- .../integration/adapter/ftp/FtpSource.java | 6 +- .../config/AbstractDirectorySourceParser.java | 2 +- .../adapter/ftp/config/FtpSourceParser.java | 7 +- .../META-INF/spring-integration.parsers | 2 - .../file/DefaultFileNameGeneratorTests.java | 51 ------ .../adapter/file/FileSourceTests.java | 103 ----------- .../file/RegexPatternFilenameFilterTests.java | 86 --------- .../adapter/file/config/CustomFileFilter.java | 31 ---- .../file/config/CustomFilenameFilter.java | 31 ---- .../file/config/CustomNameGenerator.java | 33 ---- .../file/config/FileSourceParserTests.java | 164 ------------------ .../file/config/FileTargetParserTests.java | 64 ------- .../file/config/fileSourceParserTests.xml | 37 ---- .../config/fileSourceWithFileDirectory.xml | 15 -- .../config/fileSourceWithTooManyFilters.xml | 24 --- .../file/config/fileTargetParserTests.xml | 25 --- ...invalidRegexPatternFilenameFilterTests.xml | 11 -- .../file/regexPatternFilenameFilterTests.xml | 11 -- .../adapter/{file => ftp}/BacklogTests.java | 7 +- .../{file => ftp}/ConcurrentBacklogTests.java | 19 +- .../adapter/ftp/QueuedFTPClientPoolTest.java | 15 +- .../ftp/config/CollectionSplitter.java | 16 -- .../config/CustomMessageCreator.java | 4 +- .../ftp/config/FtpSourceParserTests.java | 8 +- .../ftp/config/ftpSourceParserTests.xml | 2 +- 40 files changed, 49 insertions(+), 1551 deletions(-) delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractFileMessageCreator.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMessageCreator.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java delete mode 100755 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileMessageCreator.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileTarget.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilter.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/SimpleFileMessageMapper.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/TextFileMessageCreator.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java delete mode 100644 org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileTargetParser.java rename org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/{file => ftp}/AbstractDirectorySource.java (98%) rename org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/{file => ftp}/Backlog.java (99%) rename org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/{file => ftp}/FileSnapshot.java (98%) rename org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/{file => ftp}/config/AbstractDirectorySourceParser.java (96%) delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/FileSourceTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilterTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFileFilter.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFilenameFilter.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomNameGenerator.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileTargetParserTests.java delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithTooManyFilters.xml delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileTargetParserTests.xml delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/invalidRegexPatternFilenameFilterTests.xml delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/regexPatternFilenameFilterTests.xml rename org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/{file => ftp}/BacklogTests.java (96%) rename org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/{file => ftp}/ConcurrentBacklogTests.java (89%) delete mode 100644 org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CollectionSplitter.java rename org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/{file => ftp}/config/CustomMessageCreator.java (94%) diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractFileMessageCreator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractFileMessageCreator.java deleted file mode 100644 index cf59170678..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractFileMessageCreator.java +++ /dev/null @@ -1,82 +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 java.io.File; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageCreator; -import org.springframework.integration.message.MessagingException; - -/** - * Base class providing common behavior for file-based message creators. The - * subclasses will redefine the {@code readMessagePayload()} method. This class - * allows to choose between keeping the file after message creation and removing - * it, by setting the appropriate value in the constructor. The desired - * behaviour depends on the nature of the created message (i.e. messages with a - * {@link String} payload can safely remove the file after creation, but - * messages with a {@link File} payload cannot do that) or of the collaborator - * that uses the class instance (e.g. if the file is a locally created copy, it - * can be always discarded). - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public abstract class AbstractFileMessageCreator implements MessageCreator { - - protected Log logger = LogFactory.getLog(this.getClass()); - - private final boolean deleteFileAfterCreation; - - - /** - * @param deleteFileAfterCreation Indicates whether the file should be - * deleted after the message has been created. - */ - public AbstractFileMessageCreator(boolean deleteFileAfterCreation) { - this.deleteFileAfterCreation = deleteFileAfterCreation; - } - - - public final Message createMessage(File file) { - try { - T payload = this.readMessagePayload(file); - if (payload == null) { - return null; - } - Message message = new GenericMessage(payload); - if (this.deleteFileAfterCreation) { - file.delete(); - } - return message; - } - catch (Exception e) { - String description = "failure occurred mapping file to message"; - if (logger.isWarnEnabled()) { - logger.warn(description, e); - } - throw new MessagingException(description, e); - } - } - - protected abstract T readMessagePayload(File file) throws Exception; - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMessageCreator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMessageCreator.java deleted file mode 100644 index df278d2153..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/ByteArrayFileMessageCreator.java +++ /dev/null @@ -1,47 +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 java.io.File; - -import org.springframework.util.FileCopyUtils; - -/** - * A {@link org.springframework.integration.message.MessageCreator} - * implementation for messages with a byte array payload. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class ByteArrayFileMessageCreator extends AbstractFileMessageCreator { - - /** - * Specifies whether the file should be removed after the message has been created. - * See {@link AbstractFileMessageCreator} - * @param deleteFilesAfterMessageCreation - */ - public ByteArrayFileMessageCreator(boolean deleteFilesAfterMessageCreation) { - super(deleteFilesAfterMessageCreation); - } - - - @Override - protected byte[] readMessagePayload(File file) throws Exception { - return FileCopyUtils.copyToByteArray(file); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java deleted file mode 100644 index f447089c31..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/DefaultFileNameGenerator.java +++ /dev/null @@ -1,36 +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 org.springframework.integration.message.Message; -import org.springframework.util.StringUtils; - -/** - * Default implementation of the filename generator strategy. Concatenates the - * message id and the current timestamp. - * - * @author Mark Fisher - */ -public class DefaultFileNameGenerator implements FileNameGenerator { - - public String generateFileName(Message message) { - String filenameProperty = message.getHeaders().get(FILENAME_PROPERTY_KEY, String.class); - return StringUtils.hasText(filenameProperty) ? - filenameProperty : message.getHeaders().getId() + ".msg"; - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileMessageCreator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileMessageCreator.java deleted file mode 100755 index b0ea68515a..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileMessageCreator.java +++ /dev/null @@ -1,43 +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 java.io.File; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageCreator; - -/** - * A {@link MessageCreator} that creates {@link Message} instances with the - * absolute path to the {@link File} as payload. - * - * @author Marius Bogoevici - */ -public class FileMessageCreator extends AbstractFileMessageCreator { - - public FileMessageCreator() { - // The file should never be removed, as just the reference to it is - // passed to the message - super(false); - } - - @Override - protected File readMessagePayload(File file) throws Exception { - return file; - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java deleted file mode 100644 index 9040245994..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileNameGenerator.java +++ /dev/null @@ -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; - -import org.springframework.integration.message.Message; - -/** - * Strategy interface for generating a file name from a message. - * - * @author Mark Fisher - */ -public interface FileNameGenerator { - - String FILENAME_PROPERTY_KEY = "filename"; - - - String generateFileName(Message message); - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java deleted file mode 100644 index 2d55de504a..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java +++ /dev/null @@ -1,160 +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 java.io.File; -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.Comparator; -import java.util.List; - -import org.springframework.core.io.Resource; -import org.springframework.integration.ConfigurationException; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageBuilder; -import org.springframework.integration.message.MessageCreator; -import org.springframework.integration.message.MessageDeliveryAware; -import org.springframework.integration.message.MessagingException; -import org.springframework.util.Assert; - -/** - * A messaging source that polls a directory to retrieve files. - * - * @deprecated Replaced by org.springframework.integration.file.PollableFileSource. - * - * @author Mark Fisher - * @author Marius Bogoevici - * @author Iwein Fuld - */ -public class FileSource extends AbstractDirectorySource implements MessageDeliveryAware { - - private final File directory; - - private volatile FileFilter fileFilter; - - private volatile FilenameFilter filenameFilter; - - /** - * Creates a default FileSource on the specified directory - * @param directory - */ - public FileSource(Resource directory) { - this(directory, new FileMessageCreator(), null); - } - - public FileSource(Resource directory, Comparator comparator) { - this(directory, new FileMessageCreator(), comparator); - } - - public FileSource(Resource directory, MessageCreator messageCreator) { - this(directory, messageCreator, null); - } - - /** - * Creates a FileSource with the specified strategies. - * @param directory - * @param messageCreator the MessageCreator used to convert Files into - * Messages - * @param comparator the comparator is used to order the backlog. If - * null natural order is used. - */ - public FileSource(Resource directory, MessageCreator messageCreator, Comparator comparator) { - super(messageCreator, comparator); - Assert.notNull(directory, "The directory must not be null"); - try { - this.directory = directory.getFile(); - if (!this.directory.isDirectory()) { - throw new ConfigurationException("The FileSource can't be instantiated because " - + this.directory.getAbsolutePath() + " is not a directory."); - } - } - catch (IOException e) { - throw new ConfigurationException("The FileSource can't be instantiated", e); - } - } - - @Override - protected Message buildNextMessage() throws IOException { - File file = retrieveNextPayload(); - Message message = this.getMessageCreator().createMessage(file); - message = MessageBuilder.fromMessage(message) - .setHeader(FileNameGenerator.FILENAME_PROPERTY_KEY, file.getName()).setHeader(FILE_INFO_PROPERTY, - getBacklog().getProcessingBuffer().get(0)).build(); - return message; - } - - /** - * Sets a FilenameFilter to be used with the - * {@link File#listFiles()} command. Note that either a - * FileFilter or a FilenameFilter is used to filter the list of files. - * Calling this setter overwrites the FileNameFilter if it was set before. - * @param fileFilter - */ - public void setFileFilter(FileFilter fileFilter) { - Assert.notNull(fileFilter); - this.filenameFilter = null; - this.fileFilter = fileFilter; - } - - /** - * Sets a FilenameFilter to be used with the - * {@link File#listFiles()} command. Note that either a - * FileFilter or a FilenameFilter is used to filter the list of files. - * Calling this setter overwrites the FileFilter if it was set before. - * @param filenameFilter - */ - public void setFilenameFilter(FilenameFilter filenameFilter) { - Assert.notNull(filenameFilter); - this.fileFilter = null; - this.filenameFilter = filenameFilter; - } - - @Override - protected void populateSnapshot(List snapshot) throws IOException { - File[] files; - if (this.fileFilter != null) { - files = this.directory.listFiles(this.fileFilter); - } - else if (this.filenameFilter != null) { - files = this.directory.listFiles(this.filenameFilter); - } - else { - files = this.directory.listFiles(); - } - if (files == null) { - throw new MessagingException("Problem occurred while polling for files. " + "Is '" - + directory.getAbsolutePath() + "' a directory?"); - } - for (File file : files) { - FileSnapshot fileInfo = new FileSnapshot(file); - snapshot.add(fileInfo); - } - } - - @Override - protected File retrieveNextPayload() throws IOException { - List selectedForProcessing = this.getBacklog().selectForProcessing(1); - if (!selectedForProcessing.isEmpty()) { - return selectedForProcessing.get(0).getFile(); - } - else { - return null; - } - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileTarget.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileTarget.java deleted file mode 100644 index 25b33fd402..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileTarget.java +++ /dev/null @@ -1,45 +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 java.io.File; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageConsumer; -import org.springframework.integration.message.MessageMapper; - -/** - * A message target for writing files. The actual file writing occurs in the - * message mapper. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class FileTarget implements MessageConsumer { - - private MessageMapper messageMapper; - - - public FileTarget(MessageMapper messageMapper) { - this.messageMapper = messageMapper; - } - - public void onMessage(Message message) { - this.messageMapper.mapMessage(message); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilter.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilter.java deleted file mode 100644 index 74a197cace..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilter.java +++ /dev/null @@ -1,46 +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 java.io.File; -import java.io.FilenameFilter; -import java.util.regex.Pattern; - -import org.springframework.util.Assert; - -/** - * A {@link FilenameFilter} implementation for matching against - * a regular expression {@link Pattern}. - * - * @author Mark Fisher - */ -public class RegexPatternFilenameFilter implements FilenameFilter { - - private volatile Pattern pattern; - - - public void setPattern(Pattern pattern) { - this.pattern = pattern; - } - - - public boolean accept(File dir, String name) { - Assert.notNull(pattern, "pattern must not be null"); - return (name != null) && this.pattern.matcher(name).matches(); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/SimpleFileMessageMapper.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/SimpleFileMessageMapper.java deleted file mode 100644 index 6e1cf40d0e..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/SimpleFileMessageMapper.java +++ /dev/null @@ -1,79 +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 java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageHandlingException; -import org.springframework.integration.message.MessageMapper; -import org.springframework.util.FileCopyUtils; - -/** - * A default {@link MessageMapper} for {@link FileTarget}, converting payloads of the - * {@link File}, {@code byte[]} and {@link String} types to files. The name of the newly - * created file is defined by the {@link FileNameGenerator} instance configured with it. - * By default, it uses a {@link DefaultFileNameGenerator}. - * - * @author Marius Bogoevici - */ -public class SimpleFileMessageMapper implements MessageMapper { - - private volatile FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator(); - - private final File parentDirectory; - - - public SimpleFileMessageMapper(String parentDirectoryPath) { - this(new File(parentDirectoryPath)); - } - - public SimpleFileMessageMapper(File parentDirectory) { - this.parentDirectory = parentDirectory; - } - - - public void setFileNameGenerator(FileNameGenerator fileNameGenerator) { - this.fileNameGenerator = fileNameGenerator; - } - - public File mapMessage(Message message) { - try { - File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message)); - this.writeToFile(file, message.getPayload()); - return file; - } - catch (Exception e) { - throw new MessageHandlingException(message, "failure occurred mapping file to message", e); - } - } - - public void writeToFile(File file, Object payload) throws IOException { - if (payload instanceof byte[]) { - FileCopyUtils.copy((byte[]) payload, file); - } - else if (payload instanceof String) { - FileCopyUtils.copy((String) payload, new FileWriter(file)); - } - else if (payload instanceof File) { - FileCopyUtils.copy((File) payload, file); - } - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/TextFileMessageCreator.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/TextFileMessageCreator.java deleted file mode 100644 index 01875edfdd..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/TextFileMessageCreator.java +++ /dev/null @@ -1,48 +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 java.io.File; -import java.io.FileReader; - -import org.springframework.util.FileCopyUtils; - -/** - * A {@link org.springframework.integration.message.MessageCreator} - * implementation for creating messages with a String payload from a File. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class TextFileMessageCreator extends AbstractFileMessageCreator { - - /** - * Specifies whether the file should be removed after the message has been created. - * See {@link AbstractFileMessageCreator} - * @param deleteFilesAfterMessageCreation - */ - public TextFileMessageCreator(boolean deleteFilesAfterMessageCreation) { - super(deleteFilesAfterMessageCreation); - } - - - @Override - protected String readMessagePayload(File file) throws Exception { - return FileCopyUtils.copyToString(new FileReader(file)); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java deleted file mode 100644 index a6ed70fd59..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileSourceParser.java +++ /dev/null @@ -1,128 +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.net.MalformedURLException; -import java.net.URL; -import java.util.regex.Pattern; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.core.io.ResourceLoader; -import org.springframework.integration.ConfigurationException; -import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator; -import org.springframework.integration.adapter.file.FileSource; -import org.springframework.integration.adapter.file.RegexPatternFilenameFilter; -import org.springframework.integration.adapter.file.TextFileMessageCreator; -import org.springframework.util.StringUtils; -import org.w3c.dom.Element; - -/** - * Parser for the <file-source/> element. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class FileSourceParser extends AbstractDirectorySourceParser { - - public static final String TYPE_ATTRIBUTE = "type"; - - public static final String DIRECTORY_ATTRIBUTE = "directory"; - - public static final String FILE_FILTER_ATTRIBUTE = "file-filter"; - - public static final String FILENAME_FILTER_ATTRIBUTE = "filename-filter"; - - public static final String FILENAME_PATTERN_ATTRIBUTE = "filename-pattern"; - - @Override - protected Class getBeanClass(Element element) { - return FileSource.class; - } - - @Override - protected boolean isEligibleAttribute(String attributeName) { - return !DIRECTORY_ATTRIBUTE.equals(attributeName) && !FILE_FILTER_ATTRIBUTE.equals(attributeName) - && !FILENAME_FILTER_ATTRIBUTE.equals(attributeName) - && !FILENAME_PATTERN_ATTRIBUTE.equals(attributeName) && !TYPE_ATTRIBUTE.equals(attributeName) - && super.isEligibleAttribute(attributeName); - } - - @Override - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { - String directoryLocation = element.getAttribute(DIRECTORY_ATTRIBUTE); - if (!directoryLocation.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) && !isUrl(directoryLocation)) { - directoryLocation = "file:" + directoryLocation; - } - beanDefinition.addConstructorArgValue(directoryLocation); - String fileFilter = element.getAttribute(FILE_FILTER_ATTRIBUTE); - String filenameFilter = element.getAttribute(FILENAME_FILTER_ATTRIBUTE); - String filenamePattern = element.getAttribute(FILENAME_PATTERN_ATTRIBUTE); - this.verifyAtMostOneAttributeSpecified(fileFilter, filenameFilter, filenamePattern); - if (StringUtils.hasText(fileFilter)) { - beanDefinition.addPropertyReference("fileFilter", fileFilter); - } - else if (StringUtils.hasText(filenameFilter)) { - beanDefinition.addPropertyReference("filenameFilter", filenameFilter); - } - else if (StringUtils.hasLength(filenamePattern)) { - RegexPatternFilenameFilter regexFilter = new RegexPatternFilenameFilter(); - regexFilter.setPattern(Pattern.compile(filenamePattern)); - beanDefinition.addPropertyValue("filenameFilter", regexFilter); - } - super.postProcess(beanDefinition, element); - processTypeAttribute(beanDefinition, element); - } - - private void processTypeAttribute(BeanDefinitionBuilder beanDefinition, Element element) { - if (beanDefinition.getRawBeanDefinition().getConstructorArgumentValues().getArgumentCount() == 2) { - // message-creator already defined, ignore type property - } - else { - String type = element.getAttribute(TYPE_ATTRIBUTE); - if ("text".equals(type)) { - beanDefinition.addConstructorArgValue(new TextFileMessageCreator(false)); - } - else if ("binary".equals(type)) { - beanDefinition.addConstructorArgValue(new ByteArrayFileMessageCreator(false)); - } - } - } - - private boolean isUrl(String directoryLocation) { - try { - new URL(directoryLocation); - return true; - } - catch (MalformedURLException e) { - return false; - } - } - - private void verifyAtMostOneAttributeSpecified(String... attributes) { - boolean attributeSpecified = false; - for (String attribute : attributes) { - if (StringUtils.hasText(attribute)) { - if (attributeSpecified) { - throw new ConfigurationException("FileSource supports at most one of '" + FILE_FILTER_ATTRIBUTE - + "', '" + FILENAME_FILTER_ATTRIBUTE + "', and '" + FILENAME_PATTERN_ATTRIBUTE + "'."); - } - attributeSpecified = true; - } - } - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileTargetParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileTargetParser.java deleted file mode 100644 index 31dd299b7c..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/FileTargetParser.java +++ /dev/null @@ -1,72 +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 org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.adapter.file.FileTarget; -import org.springframework.integration.adapter.file.SimpleFileMessageMapper; -import org.springframework.util.StringUtils; -import org.w3c.dom.Element; - -/** - * Parser for the <file-target/> element. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class FileTargetParser extends AbstractSimpleBeanDefinitionParser { - - private static final String NAME_GENERATOR_PROPERTY = "fileNameGenerator"; - - public static final String DIRECTORY_ATTRIBUTE = "directory"; - - public static final String FILE_NAME_GENERATOR_ATTRIBUTE = "name-generator"; - - - @Override - protected Class getBeanClass(Element element) { - return FileTarget.class; - } - - @Override - protected boolean isEligibleAttribute(String attributeName) { - return !(DIRECTORY_ATTRIBUTE.equals(attributeName) || FILE_NAME_GENERATOR_ATTRIBUTE.equals(attributeName)) - && super.isEligibleAttribute(attributeName); - } - - @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - super.doParse(element, parserContext, builder); - BeanDefinition messageMapperDefinition = new RootBeanDefinition(SimpleFileMessageMapper.class); - messageMapperDefinition.getConstructorArgumentValues().addGenericArgumentValue( - element.getAttribute(DIRECTORY_ATTRIBUTE)); - if (StringUtils.hasText(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE))) { - messageMapperDefinition.getPropertyValues().addPropertyValue(NAME_GENERATOR_PROPERTY, - new RuntimeBeanReference(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE))); - } - String mapperBeanName = parserContext.getReaderContext().generateBeanName(messageMapperDefinition); - parserContext.getRegistry().registerBeanDefinition( - mapperBeanName, messageMapperDefinition); - builder.addConstructorArgReference(mapperBeanName); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java similarity index 98% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java index 5137eeffe8..740c467d0e 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/AbstractDirectorySource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.file; +package org.springframework.integration.adapter.ftp; import java.io.IOException; import java.util.ArrayList; @@ -23,6 +23,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageCreator; import org.springframework.integration.message.MessageDeliveryAware; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java similarity index 99% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java index 5882b76230..640cc617c4 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/Backlog.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java @@ -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.Collection; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSnapshot.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java similarity index 98% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSnapshot.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java index 7c0254949a..ae63a7a75d 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSnapshot.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.file; +package org.springframework.integration.adapter.ftp; import java.io.File; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java index 8da443f246..830e314d9b 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java @@ -24,9 +24,7 @@ import java.util.List; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; -import org.springframework.integration.adapter.file.AbstractDirectorySource; -import org.springframework.integration.adapter.file.Backlog; -import org.springframework.integration.adapter.file.FileSnapshot; + import org.springframework.integration.message.DefaultMessageCreator; import org.springframework.integration.message.MessageCreator; import org.springframework.util.Assert; @@ -46,6 +44,7 @@ public class FtpSource extends AbstractDirectorySource> { private final FTPClientPool clientPool; + public FtpSource(FTPClientPool clientPool) { this(new DefaultMessageCreator>(), clientPool); } @@ -55,6 +54,7 @@ public class FtpSource extends AbstractDirectorySource> { this.clientPool = clientPool; } + public void setMaxFilesPerMessage(int maxFilesPerMessage) { Assert.isTrue(maxFilesPerMessage > 0, "'maxFilesPerMessage' must be greater than 0"); this.maxFilesPerMessage = maxFilesPerMessage; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java similarity index 96% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java index ecd1139a1d..14932564bf 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/config/AbstractDirectorySourceParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.file.config; +package org.springframework.integration.adapter.ftp.config; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java index 9deab2c69a..f6d6e12df7 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java @@ -16,11 +16,11 @@ package org.springframework.integration.adapter.ftp.config; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.integration.adapter.file.config.AbstractDirectorySourceParser; import org.springframework.integration.adapter.ftp.FtpSource; import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; -import org.w3c.dom.Element; /** * Parser for the <ftp-source/> element. @@ -30,6 +30,7 @@ import org.w3c.dom.Element; * @author Iwein Fuld */ public class FtpSourceParser extends AbstractDirectorySourceParser { + private static final String POOL_ATTRIBUTE_USER = "username"; private static final String POOL_ATTRIBUTE_PASS = "password"; @@ -40,6 +41,7 @@ public class FtpSourceParser extends AbstractDirectorySourceParser { private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory"; + @Override protected Class getBeanClass(Element element) { return FtpSource.class; @@ -71,4 +73,5 @@ public class FtpSourceParser extends AbstractDirectorySourceParser { queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); beanDefinition.addConstructorArgValue(queuedFTPClientPool); } + } diff --git a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers index 1d6b1f206b..a1baa7fd88 100644 --- a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers +++ b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers @@ -1,5 +1,3 @@ -file-source=org.springframework.integration.adapter.file.config.FileSourceParser -file-target=org.springframework.integration.adapter.file.config.FileTargetParser ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java deleted file mode 100644 index 7482523471..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/DefaultFileNameGeneratorTests.java +++ /dev/null @@ -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 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 message = new GenericMessage("testing"); - FileNameGenerator generator = new DefaultFileNameGenerator(); - String filename = generator.generateFileName(message); - assertTrue(filename.startsWith("" + message.getHeaders().getId())); - assertTrue(filename.endsWith(".msg")); - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/FileSourceTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/FileSourceTests.java deleted file mode 100644 index bef2bcc598..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/FileSourceTests.java +++ /dev/null @@ -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 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); - } -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilterTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilterTests.java deleted file mode 100644 index 96be95ea8b..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/RegexPatternFilenameFilterTests.java +++ /dev/null @@ -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()); - } - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFileFilter.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFileFilter.java deleted file mode 100644 index 792e3da4c6..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFileFilter.java +++ /dev/null @@ -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; - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFilenameFilter.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFilenameFilter.java deleted file mode 100644 index 8885d32fa9..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomFilenameFilter.java +++ /dev/null @@ -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; - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomNameGenerator.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomNameGenerator.java deleted file mode 100644 index bc16b93d19..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomNameGenerator.java +++ /dev/null @@ -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(); - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java deleted file mode 100644 index be3b4e6698..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileSourceParserTests.java +++ /dev/null @@ -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); - } - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileTargetParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileTargetParserTests.java deleted file mode 100644 index eae2493ca0..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/FileTargetParserTests.java +++ /dev/null @@ -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); - } - -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml deleted file mode 100644 index cc924149ed..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml deleted file mode 100644 index 1319e65f7a..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithTooManyFilters.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithTooManyFilters.xml deleted file mode 100644 index 28ffbb394a..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithTooManyFilters.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileTargetParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileTargetParserTests.xml deleted file mode 100644 index 59ab012d15..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileTargetParserTests.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/invalidRegexPatternFilenameFilterTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/invalidRegexPatternFilenameFilterTests.xml deleted file mode 100644 index e1d08e0313..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/invalidRegexPatternFilenameFilterTests.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/regexPatternFilenameFilterTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/regexPatternFilenameFilterTests.xml deleted file mode 100644 index d4025bb9b2..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/regexPatternFilenameFilterTests.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/BacklogTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java similarity index 96% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/BacklogTests.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java index c606f1d390..fbbdf2b5f7 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/BacklogTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java @@ -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 diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/ConcurrentBacklogTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java similarity index 89% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/ConcurrentBacklogTests.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java index eaa31acbca..a5d8c2895d 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/ConcurrentBacklogTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java @@ -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") diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java index 98420dc17b..e7fe9096af 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java @@ -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; } + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CollectionSplitter.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CollectionSplitter.java deleted file mode 100644 index f93efef741..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CollectionSplitter.java +++ /dev/null @@ -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 message) { - return new ArrayList(message.getPayload()); - } -} diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomMessageCreator.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java similarity index 94% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomMessageCreator.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java index 773d2f42a6..9648cdb809 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/CustomMessageCreator.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java @@ -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{ public Message createMessage(File object) { return new GenericMessage (object.getAbsolutePath()); } - + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java index 7f03bffa0e..d5aab2e68a 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java @@ -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; diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml index 10929fb06d..c8f2bcdb58 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml @@ -52,6 +52,6 @@ message-creator="customMessageCreator"/> + class="org.springframework.integration.adapter.ftp.config.CustomMessageCreator"/>