INT-188: changed type of directory property to File instead of Resource
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.integration.file;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.aggregator.Resequencer;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
@@ -55,212 +53,202 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
* <p/>
|
||||
* FileReadingMessageSource is fully thread-safe under concurrent
|
||||
* <code>receive()</code> invocations and message delivery callbacks.
|
||||
*
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FileReadingMessageSource implements MessageSource<File>,
|
||||
InitializingBean {
|
||||
InitializingBean {
|
||||
|
||||
private static final int INTERNAL_QUEUE_CAPACITY = 5;
|
||||
private static final int INTERNAL_QUEUE_CAPACITY = 5;
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(FileReadingMessageSource.class);
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(FileReadingMessageSource.class);
|
||||
|
||||
private volatile File inputDirectory;
|
||||
private volatile File directory;
|
||||
|
||||
private volatile boolean autoCreateDirectory = true;
|
||||
private volatile boolean autoCreateDirectory = true;
|
||||
|
||||
/**
|
||||
* {@link PriorityBlockingQueue#iterator()} throws
|
||||
* {@link java.util.ConcurrentModificationException} in Java 5. There is no
|
||||
* locking around the queue, so there is also no iteration.
|
||||
*/
|
||||
private final Queue<File> toBeReceived;
|
||||
/**
|
||||
* {@link PriorityBlockingQueue#iterator()} throws
|
||||
* {@link java.util.ConcurrentModificationException} in Java 5. There is no
|
||||
* locking around the queue, so there is also no iteration.
|
||||
*/
|
||||
private final Queue<File> toBeReceived;
|
||||
|
||||
private volatile FileListFilter filter = new AcceptOnceFileListFilter();
|
||||
private volatile FileListFilter filter = new AcceptOnceFileListFilter();
|
||||
|
||||
private volatile FileLocker locker = new NoopFileLocker();
|
||||
private volatile FileLocker locker = new NoopFileLocker();
|
||||
|
||||
private boolean scanEachPoll = false;
|
||||
private boolean scanEachPoll = false;
|
||||
|
||||
/**
|
||||
* Creates a FileReadingMessageSource with a naturally ordered queue.
|
||||
*/
|
||||
public FileReadingMessageSource() {
|
||||
toBeReceived = new PriorityBlockingQueue<File>(INTERNAL_QUEUE_CAPACITY);
|
||||
}
|
||||
/**
|
||||
* Creates a FileReadingMessageSource with a naturally ordered queue.
|
||||
*/
|
||||
public FileReadingMessageSource() {
|
||||
toBeReceived = new PriorityBlockingQueue<File>(INTERNAL_QUEUE_CAPACITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FileReadingMessageSource with a {@link PriorityBlockingQueue}
|
||||
* ordered with the passed in {@link Comparator}
|
||||
* <p/>
|
||||
* No guarantees about file delivery order can be made under concurrent
|
||||
* access.
|
||||
*/
|
||||
public FileReadingMessageSource(Comparator<File> receptionOrderComparator) {
|
||||
toBeReceived = new PriorityBlockingQueue<File>(INTERNAL_QUEUE_CAPACITY,
|
||||
receptionOrderComparator);
|
||||
}
|
||||
/**
|
||||
* Creates a FileReadingMessageSource with a {@link PriorityBlockingQueue}
|
||||
* ordered with the passed in {@link Comparator}
|
||||
* <p/>
|
||||
* No guarantees about file delivery order can be made under concurrent
|
||||
* access.
|
||||
*/
|
||||
public FileReadingMessageSource(Comparator<File> receptionOrderComparator) {
|
||||
toBeReceived = new PriorityBlockingQueue<File>(INTERNAL_QUEUE_CAPACITY,
|
||||
receptionOrderComparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the input directory.
|
||||
*/
|
||||
public void setInputDirectory(Resource inputDirectory) {
|
||||
Assert.notNull(inputDirectory, "inputDirectory must not be null");
|
||||
try {
|
||||
this.inputDirectory = inputDirectory.getFile();
|
||||
} catch (IOException ioe) {
|
||||
try {
|
||||
// fallback to the URI
|
||||
this.inputDirectory = new File(inputDirectory.getURI());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unexpected IOException when looking for source directory: "
|
||||
+ inputDirectory, ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Specify the input directory.
|
||||
*/
|
||||
public void setDirectory(File directory) {
|
||||
Assert.notNull(directory, "directory must not be null");
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to create the source directory automatically if it does
|
||||
* not yet exist upon initialization. By default, this value is
|
||||
* <emphasis>true</emphasis>. If set to <emphasis>false</emphasis> and the
|
||||
* source directory does not exist, an Exception will be thrown upon
|
||||
* initialization.
|
||||
*/
|
||||
public void setAutoCreateDirectory(boolean autoCreateDirectory) {
|
||||
this.autoCreateDirectory = autoCreateDirectory;
|
||||
}
|
||||
/**
|
||||
* Specify whether to create the source directory automatically if it does
|
||||
* not yet exist upon initialization. By default, this value is
|
||||
* <emphasis>true</emphasis>. If set to <emphasis>false</emphasis> and the
|
||||
* source directory does not exist, an Exception will be thrown upon
|
||||
* initialization.
|
||||
*/
|
||||
public void setAutoCreateDirectory(boolean autoCreateDirectory) {
|
||||
this.autoCreateDirectory = autoCreateDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link FileListFilter}. By default a
|
||||
* {@link AcceptOnceFileListFilter} with no bounds is used. In most cases a
|
||||
* customized {@link FileListFilter} will be needed to deal with
|
||||
* modification and duplication concerns. If multiple filters are required a
|
||||
* {@link CompositeFileListFilter} can be used to group them together.
|
||||
* <p/>
|
||||
* <b>The supplied filter must be thread safe.</b>.
|
||||
*/
|
||||
public void setFilter(FileListFilter filter) {
|
||||
Assert.notNull(filter, "'filter' must not be null");
|
||||
this.filter = filter;
|
||||
if (filter instanceof FileLocker && locker instanceof NoopFileLocker) {
|
||||
this.locker = (FileLocker) filter;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets a {@link FileListFilter}. By default a
|
||||
* {@link AcceptOnceFileListFilter} with no bounds is used. In most cases a
|
||||
* customized {@link FileListFilter} will be needed to deal with
|
||||
* modification and duplication concerns. If multiple filters are required a
|
||||
* {@link CompositeFileListFilter} can be used to group them together.
|
||||
* <p/>
|
||||
* <b>The supplied filter must be thread safe.</b>.
|
||||
*/
|
||||
public void setFilter(FileListFilter filter) {
|
||||
Assert.notNull(filter, "'filter' must not be null");
|
||||
this.filter = filter;
|
||||
if (filter instanceof FileLocker && locker instanceof NoopFileLocker) {
|
||||
this.locker = (FileLocker) filter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Sets a
|
||||
* {@link org.springframework.integration.file.locking.FileLocker} to be
|
||||
* used instead of the default NoopFileLocker. Note that the locker is not
|
||||
* queried by this FileReadingMessageSource: integration with a
|
||||
* FileListFilter is an external concern.
|
||||
* <p/>
|
||||
* <b>The supplied FileLocker must be thread safe</b>
|
||||
*/
|
||||
public void setLocker(FileLocker locker) {
|
||||
Assert.notNull(locker, "'fileLocker' must not be null.");
|
||||
this.locker = locker;
|
||||
}
|
||||
/**
|
||||
* Optional. Sets a
|
||||
* {@link org.springframework.integration.file.locking.FileLocker} to be
|
||||
* used instead of the default NoopFileLocker. Note that the locker is not
|
||||
* queried by this FileReadingMessageSource: integration with a
|
||||
* FileListFilter is an external concern.
|
||||
* <p/>
|
||||
* <b>The supplied FileLocker must be thread safe</b>
|
||||
*/
|
||||
public void setLocker(FileLocker locker) {
|
||||
Assert.notNull(locker, "'fileLocker' must not be null.");
|
||||
this.locker = locker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Set this flag if you want to make sure the internal queue is
|
||||
* refreshed with the latest content of the input directory on each poll.
|
||||
* <p/>
|
||||
* By default this implementation will empty its queue before looking at the
|
||||
* directory again. In cases where order is relevant it is important to
|
||||
* consider the effects of setting this flag. The internal
|
||||
* {@link PriorityBlockingQueue} that this class is keeping will more likely
|
||||
* be out of sync with the filesystem if this flag is set to
|
||||
* <code>false</code>, but it will change more often (causing reordering) if
|
||||
* it is set to <code>true</code>.
|
||||
*/
|
||||
public void setScanEachPoll(boolean scanEachPoll) {
|
||||
this.scanEachPoll = scanEachPoll;
|
||||
}
|
||||
/**
|
||||
* Optional. Set this flag if you want to make sure the internal queue is
|
||||
* refreshed with the latest content of the input directory on each poll.
|
||||
* <p/>
|
||||
* By default this implementation will empty its queue before looking at the
|
||||
* directory again. In cases where order is relevant it is important to
|
||||
* consider the effects of setting this flag. The internal
|
||||
* {@link PriorityBlockingQueue} that this class is keeping will more likely
|
||||
* be out of sync with the filesystem if this flag is set to
|
||||
* <code>false</code>, but it will change more often (causing reordering) if
|
||||
* it is set to <code>true</code>.
|
||||
*/
|
||||
public void setScanEachPoll(boolean scanEachPoll) {
|
||||
this.scanEachPoll = scanEachPoll;
|
||||
}
|
||||
|
||||
public final void afterPropertiesSet() {
|
||||
if (!this.inputDirectory.exists() && this.autoCreateDirectory) {
|
||||
this.inputDirectory.mkdirs();
|
||||
}
|
||||
Assert.isTrue(this.inputDirectory.exists(), "Source directory ["
|
||||
+ inputDirectory + "] does not exist.");
|
||||
Assert.isTrue(this.inputDirectory.isDirectory(), "Source path ["
|
||||
+ this.inputDirectory + "] does not point to a directory.");
|
||||
Assert.isTrue(this.inputDirectory.canRead(), "Source directory ["
|
||||
+ this.inputDirectory + "] is not readable.");
|
||||
}
|
||||
public final void afterPropertiesSet() {
|
||||
Assert.notNull(directory, "'directory' must not be set before initialization");
|
||||
if (!this.directory.exists() && this.autoCreateDirectory) {
|
||||
this.directory.mkdirs();
|
||||
}
|
||||
Assert.isTrue(this.directory.exists(), "Source directory ["
|
||||
+ directory + "] does not exist.");
|
||||
Assert.isTrue(this.directory.isDirectory(), "Source path ["
|
||||
+ this.directory + "] does not point to a directory.");
|
||||
Assert.isTrue(this.directory.canRead(), "Source directory ["
|
||||
+ this.directory + "] is not readable.");
|
||||
}
|
||||
|
||||
public Message<File> receive() throws MessagingException {
|
||||
Message<File> message = null;
|
||||
// rescan only if needed or explicitly configured
|
||||
if (scanEachPoll || toBeReceived.isEmpty()) {
|
||||
scanInputDirectory();
|
||||
}
|
||||
File file = toBeReceived.poll();
|
||||
// file == null means the queue was empty
|
||||
// we can't rely on isEmpty for concurrency reasons
|
||||
while (file != null && !locker.lock(file)) {
|
||||
file = toBeReceived.poll();
|
||||
}
|
||||
if (file != null) {
|
||||
message = MessageBuilder.withPayload(file).build();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Created message: [" + message + "]");
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
public Message<File> receive() throws MessagingException {
|
||||
Message<File> message = null;
|
||||
// rescan only if needed or explicitly configured
|
||||
if (scanEachPoll || toBeReceived.isEmpty()) {
|
||||
scanInputDirectory();
|
||||
}
|
||||
File file = toBeReceived.poll();
|
||||
// file == null means the queue was empty
|
||||
// we can't rely on isEmpty for concurrency reasons
|
||||
while (file != null && !locker.lock(file)) {
|
||||
file = toBeReceived.poll();
|
||||
}
|
||||
if (file != null) {
|
||||
message = MessageBuilder.withPayload(file).build();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Created message: [" + message + "]");
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private void scanInputDirectory() {
|
||||
File[] fileArray = inputDirectory.listFiles();
|
||||
if (fileArray == null) {
|
||||
throw new MessagingException("The path [" + this.inputDirectory
|
||||
+ "] does not denote a properly accessible directory.");
|
||||
}
|
||||
List<File> filteredFiles = this.filter.filterFiles(fileArray);
|
||||
Set<File> freshFiles = new HashSet<File>(filteredFiles);
|
||||
if (!freshFiles.isEmpty()) {
|
||||
toBeReceived.addAll(freshFiles);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Added to queue: " + freshFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void scanInputDirectory() {
|
||||
File[] fileArray = directory.listFiles();
|
||||
if (fileArray == null) {
|
||||
throw new MessagingException("The path [" + this.directory
|
||||
+ "] does not denote a properly accessible directory.");
|
||||
}
|
||||
List<File> filteredFiles = this.filter.filterFiles(fileArray);
|
||||
Set<File> freshFiles = new HashSet<File>(filteredFiles);
|
||||
if (!freshFiles.isEmpty()) {
|
||||
toBeReceived.addAll(freshFiles);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Added to queue: " + freshFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the failed message back to the 'toBeReceived' queue.
|
||||
*/
|
||||
public void onFailure(Message<File> failedMessage, Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to send: " + failedMessage);
|
||||
}
|
||||
toBeReceived.offer(failedMessage.getPayload());
|
||||
}
|
||||
/**
|
||||
* Adds the failed message back to the 'toBeReceived' queue.
|
||||
*/
|
||||
public void onFailure(Message<File> failedMessage, Throwable t) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to send: " + failedMessage);
|
||||
}
|
||||
toBeReceived.offer(failedMessage.getPayload());
|
||||
}
|
||||
|
||||
/**
|
||||
* The message is just logged. It was already removed from the queue during
|
||||
* the call to <code>receive()</code>
|
||||
*/
|
||||
public void onSend(Message<File> sentMessage) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Sent: " + sentMessage);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The message is just logged. It was already removed from the queue during
|
||||
* the call to <code>receive()</code>
|
||||
*/
|
||||
public void onSend(Message<File> sentMessage) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Sent: " + sentMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of FileLocker that doesn't provide any protection against
|
||||
* duplicate listing.
|
||||
*/
|
||||
class NoopFileLocker implements FileLocker {
|
||||
/**
|
||||
* Implementation of FileLocker that doesn't provide any protection against
|
||||
* duplicate listing.
|
||||
*/
|
||||
class NoopFileLocker implements FileLocker {
|
||||
|
||||
public boolean lock(File fileToLock) {
|
||||
return true;
|
||||
}
|
||||
public boolean lock(File fileToLock) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void unlock(File fileToUnlock) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
public void unlock(File fileToUnlock) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,18 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceEditor;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.integration.file.FileListFilter;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @since 1.0.3
|
||||
*/
|
||||
public class FileReadingMessageSourceFactoryBean implements FactoryBean, ResourceLoaderAware {
|
||||
@@ -38,7 +36,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean, Resourc
|
||||
|
||||
private volatile ResourceLoader resourceLoader;
|
||||
|
||||
private volatile String directory;
|
||||
private volatile File directory;
|
||||
|
||||
private volatile FileListFilter filter;
|
||||
|
||||
@@ -55,11 +53,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean, Resourc
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
public void setDirectory(String directory) {
|
||||
Assert.hasText(directory, "directory must not be empty");
|
||||
if (directory.indexOf(':') == -1) {
|
||||
directory = "file:" + directory;
|
||||
}
|
||||
public void setDirectory(File directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
@@ -101,9 +95,7 @@ public class FileReadingMessageSourceFactoryBean implements FactoryBean, Resourc
|
||||
}
|
||||
this.source = (this.comparator != null) ?
|
||||
new FileReadingMessageSource(this.comparator) : new FileReadingMessageSource();
|
||||
ResourceEditor editor = new ResourceEditor(this.resourceLoader);
|
||||
editor.setAsText(this.directory);
|
||||
this.source.setInputDirectory((Resource) editor.getValue());
|
||||
this.source.setDirectory(this.directory);
|
||||
if (this.filter != null) {
|
||||
this.source.setFilter(this.filter);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/integration"
|
||||
schemaLocation="http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"/>
|
||||
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.3
|
||||
@@ -39,7 +38,6 @@ public class AutoCreateDirectoryTests {
|
||||
|
||||
private static final String OUTBOUND_PATH = BASE_PATH + File.separator + "outbound";
|
||||
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void clearDirectories() {
|
||||
@@ -60,7 +58,7 @@ public class AutoCreateDirectoryTests {
|
||||
@Test
|
||||
public void autoCreateForInboundEnabledByDefault() {
|
||||
FileReadingMessageSource source = new FileReadingMessageSource();
|
||||
source.setInputDirectory(new FileSystemResource(INBOUND_PATH));
|
||||
source.setDirectory(new File(INBOUND_PATH));
|
||||
source.afterPropertiesSet();
|
||||
assertTrue(new File(INBOUND_PATH).exists());
|
||||
}
|
||||
@@ -68,7 +66,7 @@ public class AutoCreateDirectoryTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void autoCreateForInboundDisabled() {
|
||||
FileReadingMessageSource source = new FileReadingMessageSource();
|
||||
source.setInputDirectory(new FileSystemResource(INBOUND_PATH));
|
||||
source.setDirectory(new File(INBOUND_PATH));
|
||||
source.setAutoCreateDirectory(false);
|
||||
source.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<!-- under test -->
|
||||
<bean id="pollableFileSource" class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${java.io.tmpdir}/FileReadingMessageSourceIntegrationTests"
|
||||
p:directory="file:${java.io.tmpdir}/FileReadingMessageSourceIntegrationTests"
|
||||
p:filter-ref="compositeFilter"/>
|
||||
|
||||
<!-- customized filter -->
|
||||
|
||||
@@ -16,21 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.core.Message;
|
||||
@@ -38,6 +25,11 @@ import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@@ -82,7 +74,7 @@ public class FileReadingMessageSourceIntegrationTests {
|
||||
@Test
|
||||
public void configured() throws Exception {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollableFileSource);
|
||||
assertEquals(inputDir, accessor.getPropertyValue("inputDirectory"));
|
||||
assertEquals(inputDir, accessor.getPropertyValue("directory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.mockito.runners.MockitoJUnit44Runner;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.file.locking.FileLocker;
|
||||
|
||||
@@ -31,12 +28,15 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@RunWith(MockitoJUnit44Runner.class)
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FileReadingMessageSourceTests {
|
||||
|
||||
private FileReadingMessageSource source;
|
||||
@@ -44,9 +44,6 @@ public class FileReadingMessageSourceTests {
|
||||
@Mock
|
||||
private File inputDirectoryMock;
|
||||
|
||||
@Mock
|
||||
private Resource inputDirectoryResourceMock;
|
||||
|
||||
@Mock
|
||||
private File fileMock;
|
||||
|
||||
@@ -57,8 +54,7 @@ public class FileReadingMessageSourceTests {
|
||||
private Comparator<File> comparator;
|
||||
|
||||
public void prepResource() throws Exception {
|
||||
when(inputDirectoryResourceMock.exists()).thenReturn(true);
|
||||
when(inputDirectoryResourceMock.getFile()).thenReturn(inputDirectoryMock);
|
||||
when(inputDirectoryMock.exists()).thenReturn(true);
|
||||
when(inputDirectoryMock.canRead()).thenReturn(true);
|
||||
when(locker.lock(isA(File.class))).thenReturn(true);
|
||||
}
|
||||
@@ -67,7 +63,7 @@ public class FileReadingMessageSourceTests {
|
||||
public void initialize() throws Exception {
|
||||
prepResource();
|
||||
this.source = new FileReadingMessageSource(comparator);
|
||||
source.setInputDirectory(inputDirectoryResourceMock);
|
||||
source.setDirectory(inputDirectoryMock);
|
||||
source.setLocker(locker);
|
||||
}
|
||||
|
||||
@@ -131,8 +127,6 @@ public class FileReadingMessageSourceTests {
|
||||
verify(locker).lock(fileMock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void orderedReception() throws Exception {
|
||||
File file1 = mock(File.class);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
|
||||
|
||||
<inbound-channel-adapter id="inputDirPoller"
|
||||
directory="file:${java.io.tmpdir}"
|
||||
directory="${java.io.tmpdir}"
|
||||
filter="filter"
|
||||
comparator="testComparator"
|
||||
auto-startup="false">
|
||||
|
||||
@@ -16,18 +16,9 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -37,6 +28,12 @@ import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
@@ -69,8 +66,8 @@ public class FileInboundChannelAdapterParserTests {
|
||||
@Test
|
||||
public void inputDirectory() {
|
||||
File expected = new File(System.getProperty("java.io.tmpdir"));
|
||||
File actual = (File) accessor.getPropertyValue("inputDirectory");
|
||||
assertEquals("'inputDirectory' should be set", expected, actual);
|
||||
File actual = (File) accessor.getPropertyValue("directory");
|
||||
assertEquals("'directory' should be set", expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,14 +16,9 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -31,6 +26,10 @@ import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@@ -51,8 +50,8 @@ public class FileInboundChannelAdapterWithClasspathInPropertiesTests {
|
||||
@Test
|
||||
public void inputDirectory() throws Exception {
|
||||
File expected = new ClassPathResource("").getFile();
|
||||
File actual = (File) accessor.getPropertyValue("inputDirectory");
|
||||
assertEquals("'inputDirectory' should be set", expected, actual);
|
||||
File actual = (File) accessor.getPropertyValue("directory");
|
||||
assertEquals("'directory' should be set", expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,32 +16,24 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.file.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.FileListFilter;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.PatternMatchingFileListFilter;
|
||||
import org.springframework.integration.file.*;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@@ -79,7 +71,7 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
@Test
|
||||
public void inputDirectory() {
|
||||
File expected = new File(System.getProperty("java.io.tmpdir"));
|
||||
File actual = (File) accessor.getPropertyValue("inputDirectory");
|
||||
File actual = (File) accessor.getPropertyValue("directory");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
<!-- under test -->
|
||||
<bean id="fileSource1" class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${java.io.tmpdir}/FileLockingWithMultipleSourcesIntegrationTests"
|
||||
p:directory="file:${java.io.tmpdir}/FileLockingWithMultipleSourcesIntegrationTests"
|
||||
p:filter-ref="filter"/>
|
||||
<bean id="fileSource2" class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${java.io.tmpdir}/FileLockingWithMultipleSourcesIntegrationTests"
|
||||
p:directory="file:${java.io.tmpdir}/FileLockingWithMultipleSourcesIntegrationTests"
|
||||
p:filter-ref="filter"/>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user