Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,7 +16,7 @@
package org.springframework.integration.ftp;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -35,8 +35,8 @@ public class FtpMessageHistoryTests {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("ftp-message-history-context.xml",
this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("adapterFtp", SourcePollingChannelAdapter.class);
assertEquals("adapterFtp", adapter.getComponentName());
assertEquals("ftp:inbound-channel-adapter", adapter.getComponentType());
assertThat(adapter.getComponentName()).isEqualTo("adapterFtp");
assertThat(adapter.getComponentType()).isEqualTo("ftp:inbound-channel-adapter");
ac.close();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,15 +16,12 @@
package org.springframework.integration.ftp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.File;
import java.io.FileNotFoundException;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -48,25 +45,25 @@ public class FtpParserInboundTests {
@Test
public void testLocalFilesAutoCreationTrue() throws Exception {
assertTrue(!new File("target/foo").exists());
assertThat(!new File("target/foo").exists()).isTrue();
new ClassPathXmlApplicationContext("FtpParserInboundTests-context.xml", this.getClass()).close();
assertTrue(new File("target/foo").exists());
assertTrue(!new File("target/bar").exists());
assertThat(new File("target/foo").exists()).isTrue();
assertThat(!new File("target/bar").exists()).isTrue();
}
@Test
public void testLocalFilesAutoCreationFalse() throws Exception {
assertTrue(!new File("target/bar").exists());
assertThat(!new File("target/bar").exists()).isTrue();
try {
new ClassPathXmlApplicationContext("FtpParserInboundTests-fail-context.xml", this.getClass()).close();
fail("BeansException expected.");
}
catch (BeansException e) {
assertThat(e, Matchers.instanceOf(BeanCreationException.class));
assertThat(e).isInstanceOf(BeanCreationException.class);
Throwable cause = e.getCause();
assertThat(cause, Matchers.instanceOf(BeanInitializationException.class));
assertThat(cause).isInstanceOf(BeanInitializationException.class);
cause = cause.getCause();
assertThat(cause, Matchers.instanceOf(FileNotFoundException.class));
assertEquals("bar", cause.getMessage());
assertThat(cause).isInstanceOf(FileNotFoundException.class);
assertThat(cause.getMessage()).isEqualTo("bar");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,13 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -95,73 +89,73 @@ public class FtpInboundChannelAdapterParserTests {
@Test
public void testFtpInboundChannelAdapterComplete() throws Exception {
assertFalse(TestUtils.getPropertyValue(ftpInbound, "autoStartup", Boolean.class));
assertThat(TestUtils.getPropertyValue(ftpInbound, "autoStartup", Boolean.class)).isFalse();
PriorityBlockingQueue<?> blockingQueue =
TestUtils.getPropertyValue(ftpInbound, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
Comparator<?> comparator = blockingQueue.comparator();
assertNotNull(comparator);
assertEquals("ftpInbound", ftpInbound.getComponentName());
assertEquals("ftp:inbound-channel-adapter", ftpInbound.getComponentType());
assertEquals(context.getBean("ftpChannel"), TestUtils.getPropertyValue(ftpInbound, "outputChannel"));
assertThat(comparator).isNotNull();
assertThat(ftpInbound.getComponentName()).isEqualTo("ftpInbound");
assertThat(ftpInbound.getComponentType()).isEqualTo("ftp:inbound-channel-adapter");
assertThat(TestUtils.getPropertyValue(ftpInbound, "outputChannel")).isEqualTo(context.getBean("ftpChannel"));
FtpInboundFileSynchronizingMessageSource inbound =
(FtpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(ftpInbound, "source");
assertSame(dirScanner, TestUtils.getPropertyValue(inbound, "fileSource.scanner"));
assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner")).isSameAs(dirScanner);
FtpInboundFileSynchronizer fisync =
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
assertEquals("'foo/bar'", TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString());
assertNotNull(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression"));
assertTrue(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class));
assertEquals(".foo", TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class));
assertThat(TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString()).isEqualTo("'foo/bar'");
assertThat(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression")).isNotNull();
assertThat(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)).isEqualTo(".foo");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
assertNotNull(remoteFileSeparator);
assertEquals("", remoteFileSeparator);
assertThat(remoteFileSeparator).isNotNull();
assertThat(remoteFileSeparator).isEqualTo("");
FileListFilter<?> filter = TestUtils.getPropertyValue(fisync, "filter", FileListFilter.class);
assertNotNull(filter);
assertThat(filter, instanceOf(CompositeFileListFilter.class));
assertThat(filter).isNotNull();
assertThat(filter).isInstanceOf(CompositeFileListFilter.class);
Set<?> fileFilters = TestUtils.getPropertyValue(filter, "fileFilters", Set.class);
Iterator<?> filtersIterator = fileFilters.iterator();
assertThat(filtersIterator.next(), instanceOf(FtpSimplePatternFileListFilter.class));
assertThat(filtersIterator.next(), instanceOf(FtpPersistentAcceptOnceFileListFilter.class));
assertThat(filtersIterator.next()).isInstanceOf(FtpSimplePatternFileListFilter.class);
assertThat(filtersIterator.next()).isInstanceOf(FtpPersistentAcceptOnceFileListFilter.class);
Object sessionFactory = TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory");
assertTrue(DefaultFtpSessionFactory.class.isAssignableFrom(sessionFactory.getClass()));
assertThat(DefaultFtpSessionFactory.class.isAssignableFrom(sessionFactory.getClass())).isTrue();
FileListFilter<?> acceptAllFilter = context.getBean("acceptAllFilter", FileListFilter.class);
assertTrue(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class)
.contains(acceptAllFilter));
assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class)
.contains(acceptAllFilter)).isTrue();
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(AbstractInboundFileSynchronizer.class, method -> {
method.setAccessible(true);
genMethod.set(method);
}, method -> "generateLocalFileName".equals(method.getName()));
assertEquals("FOO.afoo", genMethod.get().invoke(fisync, "foo"));
assertEquals(42, inbound.getMaxFetchSize());
assertThat(genMethod.get().invoke(fisync, "foo")).isEqualTo("FOO.afoo");
assertThat(inbound.getMaxFetchSize()).isEqualTo(42);
}
@Test
public void cachingSessionFactory() throws Exception {
Object sessionFactory = TestUtils.getPropertyValue(simpleAdapterWithCachedSessions,
"source.synchronizer.remoteFileTemplate.sessionFactory");
assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
assertThat(sessionFactory.getClass()).isEqualTo(CachingSessionFactory.class);
FtpInboundFileSynchronizer fisync =
TestUtils.getPropertyValue(simpleAdapterWithCachedSessions, "source.synchronizer",
FtpInboundFileSynchronizer.class);
String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
assertNotNull(remoteFileSeparator);
assertEquals("/", remoteFileSeparator);
assertEquals("foo/bar", TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString());
assertEquals(Integer.MIN_VALUE,
TestUtils.getPropertyValue(simpleAdapterWithCachedSessions, "source.maxFetchSize"));
assertThat(remoteFileSeparator).isNotNull();
assertThat(remoteFileSeparator).isEqualTo("/");
assertThat(TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString()).isEqualTo("foo/bar");
assertThat(TestUtils.getPropertyValue(simpleAdapterWithCachedSessions, "source.maxFetchSize"))
.isEqualTo(Integer.MIN_VALUE);
}
@Test
public void testAutoChannel() {
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
}
public static class TestSessionFactoryBean implements FactoryBean<DefaultFtpSessionFactory> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,7 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
@@ -60,8 +60,8 @@ public class FtpInboundOutboundSanitySample {
Thread.sleep(3000);
fileA = new File("local-test-dir/b.test");
fileB = new File("local-test-dir/b.test");
assertTrue(fileA.exists());
assertTrue(fileB.exists());
assertThat(fileA.exists()).isTrue();
assertThat(fileB.exists()).isTrue();
context.close();
}
@@ -78,8 +78,8 @@ public class FtpInboundOutboundSanitySample {
Thread.sleep(3000);
fileA = new File("remote-target-dir/a.test");
fileB = new File("remote-target-dir/b.test");
assertTrue(fileA.exists());
assertTrue(fileB.exists());
assertThat(fileA.exists()).isTrue();
assertThat(fileB.exists()).isTrue();
ac.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,10 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Iterator;
import java.util.Set;
@@ -91,35 +88,38 @@ public class FtpOutboundChannelAdapterParserTests {
@Test
public void testFtpOutboundChannelAdapterComplete() throws Exception {
assertEquals(ftpChannel, TestUtils.getPropertyValue(ftpOutbound, "inputChannel"));
assertEquals("ftpOutbound", ftpOutbound.getComponentName());
assertThat(TestUtils.getPropertyValue(ftpOutbound, "inputChannel")).isEqualTo(ftpChannel);
assertThat(ftpOutbound.getComponentName()).isEqualTo("ftpOutbound");
FileTransferringMessageHandler<?> handler =
TestUtils.getPropertyValue(ftpOutbound, "handler", FileTransferringMessageHandler.class);
String remoteFileSeparator = (String) TestUtils.getPropertyValue(handler,
"remoteFileTemplate.remoteFileSeparator");
assertNotNull(remoteFileSeparator);
assertEquals(".foo", TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryFileSuffix", String.class));
assertEquals("", remoteFileSeparator);
assertEquals(this.fileNameGenerator, TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"));
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
assertNotNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor"));
assertNotNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
assertEquals(FtpRemoteFileTemplate.ExistsMode.NLST,
TestUtils.getPropertyValue(handler, "remoteFileTemplate.existsMode"));
assertThat(remoteFileSeparator).isNotNull();
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryFileSuffix", String.class))
.isEqualTo(".foo");
assertThat(remoteFileSeparator).isEqualTo("");
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"))
.isEqualTo(this.fileNameGenerator);
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")).isEqualTo("UTF-8");
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor")).isNotNull();
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"))
.isNotNull();
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.existsMode"))
.isEqualTo(FtpRemoteFileTemplate.ExistsMode.NLST);
Object sfProperty = TestUtils.getPropertyValue(handler, "remoteFileTemplate.sessionFactory");
assertEquals(DefaultFtpSessionFactory.class, sfProperty.getClass());
assertThat(sfProperty.getClass()).isEqualTo(DefaultFtpSessionFactory.class);
DefaultFtpSessionFactory sessionFactory = (DefaultFtpSessionFactory) sfProperty;
assertEquals("localhost", TestUtils.getPropertyValue(sessionFactory, "host"));
assertEquals(22, TestUtils.getPropertyValue(sessionFactory, "port"));
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
assertThat(TestUtils.getPropertyValue(sessionFactory, "host")).isEqualTo("localhost");
assertThat(TestUtils.getPropertyValue(sessionFactory, "port")).isEqualTo(22);
assertThat(TestUtils.getPropertyValue(handler, "order")).isEqualTo(23);
//verify subscription order
Object dispatcher = TestUtils.getPropertyValue(ftpChannel, "dispatcher");
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils.getPropertyValue(dispatcher, "handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(TestUtils.getPropertyValue(this.ftpOutbound2, "handler"), iterator.next());
assertSame(handler, iterator.next());
assertEquals(FileExistsMode.APPEND, TestUtils.getPropertyValue(ftpOutbound, "handler.mode"));
assertThat(iterator.next()).isSameAs(TestUtils.getPropertyValue(this.ftpOutbound2, "handler"));
assertThat(iterator.next()).isSameAs(handler);
assertThat(TestUtils.getPropertyValue(ftpOutbound, "handler.mode")).isEqualTo(FileExistsMode.APPEND);
}
@Test(expected = BeanCreationException.class)
@@ -130,24 +130,25 @@ public class FtpOutboundChannelAdapterParserTests {
@Test
public void cachingByDefault() {
Object sfProperty = TestUtils.getPropertyValue(simpleAdapter, "handler.remoteFileTemplate.sessionFactory");
assertEquals(CachingSessionFactory.class, sfProperty.getClass());
assertThat(sfProperty.getClass()).isEqualTo(CachingSessionFactory.class);
Object innerSfProperty = TestUtils.getPropertyValue(sfProperty, "sessionFactory");
assertEquals(DefaultFtpSessionFactory.class, innerSfProperty.getClass());
assertEquals(FileExistsMode.REPLACE, TestUtils.getPropertyValue(simpleAdapter, "handler.mode"));
assertThat(innerSfProperty.getClass()).isEqualTo(DefaultFtpSessionFactory.class);
assertThat(TestUtils.getPropertyValue(simpleAdapter, "handler.mode")).isEqualTo(FileExistsMode.REPLACE);
}
@Test
public void adviceChain() {
MessageHandler handler = TestUtils.getPropertyValue(advisedAdapter, "handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertThat(adviceCalled).isEqualTo(1);
}
@Test
public void testTemporaryFileSuffix() {
FileTransferringMessageHandler<?> handler =
(FileTransferringMessageHandler<?>) TestUtils.getPropertyValue(ftpOutbound3, "handler");
assertFalse(TestUtils.getPropertyValue(handler, "remoteFileTemplate.useTemporaryFileName", Boolean.class));
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.useTemporaryFileName", Boolean.class))
.isFalse();
}
@Test
@@ -156,17 +157,17 @@ public class FtpOutboundChannelAdapterParserTests {
TestUtils.getPropertyValue(withBeanExpressions, "handler", FileTransferringMessageHandler.class);
ExpressionEvaluatingMessageProcessor<?> dirExpProc = TestUtils.getPropertyValue(handler,
"remoteFileTemplate.directoryExpressionProcessor", ExpressionEvaluatingMessageProcessor.class);
assertNotNull(dirExpProc);
assertThat(dirExpProc).isNotNull();
Message<String> message = MessageBuilder.withPayload("qux").build();
assertEquals("foo", dirExpProc.processMessage(message));
assertThat(dirExpProc.processMessage(message)).isEqualTo("foo");
ExpressionEvaluatingMessageProcessor<?> tempDirExpProc = TestUtils.getPropertyValue(handler,
"remoteFileTemplate.temporaryDirectoryExpressionProcessor", ExpressionEvaluatingMessageProcessor.class);
assertNotNull(tempDirExpProc);
assertEquals("bar", tempDirExpProc.processMessage(message));
assertThat(tempDirExpProc).isNotNull();
assertThat(tempDirExpProc.processMessage(message)).isEqualTo("bar");
DefaultFileNameGenerator generator = TestUtils.getPropertyValue(handler,
"remoteFileTemplate.fileNameGenerator", DefaultFileNameGenerator.class);
assertNotNull(generator);
assertEquals("baz", generator.generateFileName(message));
assertThat(generator).isNotNull();
assertThat(generator.generateFileName(message)).isEqualTo("baz");
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,18 +16,12 @@
package org.springframework.integration.ftp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -92,85 +86,88 @@ public class FtpOutboundGatewayParserTests {
public void testGateway1() {
FtpOutboundGateway gateway = TestUtils.getPropertyValue(gateway1,
"handler", FtpOutboundGateway.class);
assertEquals("X", TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator"));
assertNotNull(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"));
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals("local-test-dir", TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"));
assertFalse(TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory", Boolean.class));
assertNotNull(TestUtils.getPropertyValue(gateway, "filter"));
assertEquals(Command.LS, TestUtils.getPropertyValue(gateway, "command"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator")).isEqualTo("X");
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"))
.isEqualTo("local-test-dir");
assertThat(TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(gateway, "filter")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "command")).isEqualTo(Command.LS);
@SuppressWarnings("unchecked")
Set<Option> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains(Option.NAME_ONLY));
assertTrue(options.contains(Option.NOSORT));
assertThat(options.contains(Option.NAME_ONLY)).isTrue();
assertThat(options.contains(Option.NOSORT)).isTrue();
Long sendTimeout = TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout", Long.class);
assertEquals(Long.valueOf(777), sendTimeout);
assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter"),
Matchers.instanceOf(ExpressionFileListFilter.class));
assertEquals(FileExistsMode.APPEND, TestUtils.getPropertyValue(gateway, "fileExistsMode"));
assertThat(sendTimeout).isEqualTo(Long.valueOf(777));
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter")).isInstanceOf(ExpressionFileListFilter.class);
assertThat(TestUtils.getPropertyValue(gateway, "fileExistsMode")).isEqualTo(FileExistsMode.APPEND);
}
@Test
public void testGateway2() throws Exception {
FtpOutboundGateway gateway = TestUtils.getPropertyValue(gateway2,
"handler", FtpOutboundGateway.class);
assertEquals("X", TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator"));
assertNotNull(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"),
Matchers.instanceOf(CachingSessionFactory.class));
assertEquals(FtpRemoteFileTemplate.ExistsMode.NLST,
TestUtils.getPropertyValue(gateway, "remoteFileTemplate.existsMode"));
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals("local-test-dir", TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"));
assertFalse(TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory", Boolean.class));
assertEquals(Command.GET, TestUtils.getPropertyValue(gateway, "command"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator")).isEqualTo("X");
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"))
.isInstanceOf(CachingSessionFactory.class);
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.existsMode"))
.isEqualTo(FtpRemoteFileTemplate.ExistsMode.NLST);
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"))
.isEqualTo("local-test-dir");
assertThat(TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(gateway, "command")).isEqualTo(Command.GET);
@SuppressWarnings("unchecked")
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
assertTrue(options.contains(Option.PRESERVE_TIMESTAMP));
assertThat(options.contains(Option.PRESERVE_TIMESTAMP)).isTrue();
gateway.handleMessage(new GenericMessage<String>("foo"));
assertFalse(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
assertEquals(1, adviceCalled);
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isFalse();
assertThat(adviceCalled).isEqualTo(1);
//INT-3129
assertNotNull(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression"));
assertThat(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression")).isNotNull();
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(FtpOutboundGateway.class, method -> {
method.setAccessible(true);
genMethod.set(method);
}, method -> "generateLocalFileName".equals(method.getName()));
assertEquals("FOO.afoo", genMethod.get().invoke(gateway, new GenericMessage<String>(""), "foo"));
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter"), Matchers.instanceOf(SimplePatternFileListFilter.class));
assertThat(genMethod.get().invoke(gateway, new GenericMessage<String>(""), "foo")).isEqualTo("FOO.afoo");
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter")).isInstanceOf(SimplePatternFileListFilter.class);
}
@Test
public void testGatewayMv() {
FtpOutboundGateway gateway = TestUtils.getPropertyValue(gateway3,
"handler", FtpOutboundGateway.class);
assertNotNull(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"));
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals(Command.MV, TestUtils.getPropertyValue(gateway, "command"));
assertEquals("'foo'", TestUtils.getPropertyValue(gateway, "renameProcessor.expression.expression"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "command")).isEqualTo(Command.MV);
assertThat(TestUtils.getPropertyValue(gateway, "renameProcessor.expression.expression")).isEqualTo("'foo'");
}
@Test
public void testGatewayMPut() {
FtpOutboundGateway gateway = TestUtils.getPropertyValue(gateway4,
"handler", FtpOutboundGateway.class);
assertNotNull(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"));
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
assertEquals(Command.MPUT, TestUtils.getPropertyValue(gateway, "command"));
assertEquals("'foo'", TestUtils.getPropertyValue(gateway, "renameProcessor.expression.expression"));
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter"), Matchers.instanceOf(RegexPatternFileListFilter.class));
assertSame(generator, TestUtils.getPropertyValue(gateway, "remoteFileTemplate.fileNameGenerator"));
assertEquals("/foo",
TestUtils.getPropertyValue(gateway, "remoteFileTemplate.directoryExpressionProcessor.expression", Expression.class)
.getExpressionString());
assertEquals("/bar",
TestUtils.getPropertyValue(gateway, "remoteFileTemplate.temporaryDirectoryExpressionProcessor.expression", Expression.class)
.getExpressionString());
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isNotNull();
assertThat(TestUtils.getPropertyValue(gateway, "command")).isEqualTo(Command.MPUT);
assertThat(TestUtils.getPropertyValue(gateway, "renameProcessor.expression.expression")).isEqualTo("'foo'");
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter")).isInstanceOf(RegexPatternFileListFilter.class);
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.fileNameGenerator")).isSameAs(generator);
assertThat(TestUtils
.getPropertyValue(gateway, "remoteFileTemplate.directoryExpressionProcessor.expression",
Expression.class)
.getExpressionString()).isEqualTo("/foo");
assertThat(TestUtils
.getPropertyValue(gateway, "remoteFileTemplate.temporaryDirectoryExpressionProcessor.expression",
Expression.class)
.getExpressionString()).isEqualTo("/bar");
}
@Test
@@ -179,8 +176,8 @@ public class FtpOutboundGatewayParserTests {
"handler", FtpOutboundGateway.class);
ExpressionEvaluatingMessageProcessor<?> processor = TestUtils.getPropertyValue(gateway, "fileNameProcessor",
ExpressionEvaluatingMessageProcessor.class);
assertNotNull(processor);
assertEquals("foo", processor.processMessage(MessageBuilder.withPayload("bar").build()));
assertThat(processor).isNotNull();
assertThat(processor.processMessage(MessageBuilder.withPayload("bar").build())).isEqualTo("foo");
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2019 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.
@@ -16,13 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -69,27 +63,27 @@ public class FtpStreamingInboundChannelAdapterParserTests {
@Test
public void testFtpInboundChannelAdapterComplete() throws Exception {
assertFalse(TestUtils.getPropertyValue(this.ftpInbound, "autoStartup", Boolean.class));
assertEquals("ftpInbound", this.ftpInbound.getComponentName());
assertEquals("ftp:inbound-streaming-channel-adapter", this.ftpInbound.getComponentType());
assertSame(this.ftpChannel, TestUtils.getPropertyValue(this.ftpInbound, "outputChannel"));
assertThat(TestUtils.getPropertyValue(this.ftpInbound, "autoStartup", Boolean.class)).isFalse();
assertThat(this.ftpInbound.getComponentName()).isEqualTo("ftpInbound");
assertThat(this.ftpInbound.getComponentType()).isEqualTo("ftp:inbound-streaming-channel-adapter");
assertThat(TestUtils.getPropertyValue(this.ftpInbound, "outputChannel")).isSameAs(this.ftpChannel);
FtpStreamingMessageSource source = TestUtils.getPropertyValue(ftpInbound, "source",
FtpStreamingMessageSource.class);
assertNotNull(TestUtils.getPropertyValue(source, "comparator"));
assertThat(TestUtils.getPropertyValue(source, "remoteFileSeparator", String.class), equalTo("X"));
assertThat(TestUtils.getPropertyValue(source, "comparator")).isNotNull();
assertThat(TestUtils.getPropertyValue(source, "remoteFileSeparator", String.class)).isEqualTo("X");
FileListFilter<?> filter = TestUtils.getPropertyValue(source, "filter", FileListFilter.class);
assertNotNull(filter);
assertThat(filter, instanceOf(CompositeFileListFilter.class));
assertThat(filter).isNotNull();
assertThat(filter).isInstanceOf(CompositeFileListFilter.class);
Set<?> fileFilters = TestUtils.getPropertyValue(filter, "fileFilters", Set.class);
Iterator<?> filtersIterator = fileFilters.iterator();
assertThat(filtersIterator.next(), instanceOf(FtpSimplePatternFileListFilter.class));
assertThat(filtersIterator.next(), instanceOf(FtpPersistentAcceptOnceFileListFilter.class));
assertThat(filtersIterator.next()).isInstanceOf(FtpSimplePatternFileListFilter.class);
assertThat(filtersIterator.next()).isInstanceOf(FtpPersistentAcceptOnceFileListFilter.class);
assertSame(this.csf, TestUtils.getPropertyValue(source, "remoteFileTemplate.sessionFactory"));
assertEquals(31, TestUtils.getPropertyValue(source, "maxFetchSize"));
assertThat(TestUtils.getPropertyValue(source, "remoteFileTemplate.sessionFactory")).isSameAs(this.csf);
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize")).isEqualTo(31);
}
public static class TestSessionFactoryBean implements FactoryBean<DefaultFtpSessionFactory> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,8 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,16 +50,16 @@ public class FtpsInboundChannelAdapterParserTests {
@Test
public void testFtpsInboundChannelAdapterComplete() {
assertEquals("ftpInbound", ftpInbound.getComponentName());
assertEquals("ftp:inbound-channel-adapter", ftpInbound.getComponentType());
assertNotNull(TestUtils.getPropertyValue(ftpInbound, "pollingTask"));
assertEquals(this.ftpChannel, TestUtils.getPropertyValue(ftpInbound, "outputChannel"));
assertThat(ftpInbound.getComponentName()).isEqualTo("ftpInbound");
assertThat(ftpInbound.getComponentType()).isEqualTo("ftp:inbound-channel-adapter");
assertThat(TestUtils.getPropertyValue(ftpInbound, "pollingTask")).isNotNull();
assertThat(TestUtils.getPropertyValue(ftpInbound, "outputChannel")).isEqualTo(this.ftpChannel);
FtpInboundFileSynchronizingMessageSource inbound =
(FtpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(ftpInbound, "source");
FtpInboundFileSynchronizer fisync =
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
assertNotNull(TestUtils.getPropertyValue(fisync, "filter"));
assertThat(TestUtils.getPropertyValue(fisync, "filter")).isNotNull();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,8 +16,7 @@
package org.springframework.integration.ftp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,15 +54,16 @@ public class FtpsOutboundChannelAdapterParserTests {
@Test
public void testFtpsOutboundChannelAdapterComplete() throws Exception {
assertTrue(ftpOutbound instanceof EventDrivenConsumer);
assertEquals(this.ftpChannel, TestUtils.getPropertyValue(ftpOutbound, "inputChannel"));
assertEquals("ftpOutbound", ftpOutbound.getComponentName());
assertThat(ftpOutbound instanceof EventDrivenConsumer).isTrue();
assertThat(TestUtils.getPropertyValue(ftpOutbound, "inputChannel")).isEqualTo(this.ftpChannel);
assertThat(ftpOutbound.getComponentName()).isEqualTo("ftpOutbound");
FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(ftpOutbound, "handler", FileTransferringMessageHandler.class);
assertEquals(this.fileNameGenerator, TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"));
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"))
.isEqualTo(this.fileNameGenerator);
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")).isEqualTo("UTF-8");
DefaultFtpsSessionFactory sf = TestUtils.getPropertyValue(handler, "remoteFileTemplate.sessionFactory", DefaultFtpsSessionFactory.class);
assertEquals("localhost", TestUtils.getPropertyValue(sf, "host"));
assertEquals(22, TestUtils.getPropertyValue(sf, "port"));
assertThat(TestUtils.getPropertyValue(sf, "host")).isEqualTo("localhost");
assertThat(TestUtils.getPropertyValue(sf, "port")).isEqualTo(22);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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.
@@ -16,14 +16,7 @@
package org.springframework.integration.ftp.dsl;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.isOneOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -36,7 +29,6 @@ import java.util.List;
import java.util.regex.Matcher;
import org.apache.commons.net.ftp.FTPFile;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -105,20 +97,20 @@ public class FtpTests extends FtpTestSupport {
.get();
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
Message<?> message = out.receive(10_000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload = message.getPayload();
assertThat(payload, instanceOf(File.class));
assertThat(payload).isInstanceOf(File.class);
File file = (File) payload;
assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
assertThat(file.getAbsolutePath(), containsString("localTarget"));
assertThat(file.getName()).isIn(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a");
assertThat(file.getAbsolutePath()).contains("localTarget");
message = out.receive(10_000);
assertNotNull(message);
assertThat(message).isNotNull();
file = (File) message.getPayload();
assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
assertThat(file.getAbsolutePath(), containsString("localTarget"));
assertThat(file.getName()).isIn(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a");
assertThat(file.getAbsolutePath()).contains("localTarget");
assertNull(out.receive(10));
assertThat(out.receive(10)).isNull();
File remoteFile = new File(this.sourceRemoteDirectory, " " + prefix() + "Source1.txt");
@@ -128,21 +120,21 @@ public class FtpTests extends FtpTestSupport {
remoteFile.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
message = out.receive(10_000);
assertNotNull(message);
assertThat(message).isNotNull();
payload = message.getPayload();
assertThat(payload, instanceOf(File.class));
assertThat(payload).isInstanceOf(File.class);
file = (File) payload;
assertEquals(" FTPSOURCE1.TXT.a", file.getName());
assertEquals("New content", FileCopyUtils.copyToString(new FileReader(file)));
assertThat(file.getName()).isEqualTo(" FTPSOURCE1.TXT.a");
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEqualTo("New content");
MessageSource<?> source = context.getBean(FtpInboundFileSynchronizingMessageSource.class);
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize"), equalTo(10));
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize")).isEqualTo(10);
assertNotNull(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source"));
assertThat(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source")).isNotNull();
registration.destroy();
assertNull(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source"));
assertThat(this.integrationManagementConfigurer.getSourceMetrics("ftpInboundAdapter.source")).isNull();
}
@Test
@@ -158,19 +150,19 @@ public class FtpTests extends FtpTestSupport {
.get();
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
Message<?> message = out.receive(10_000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(InputStream.class);
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isIn(" ftpSource1.txt", "ftpSource2.txt");
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
message = out.receive(10_000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(InputStream.class);
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isIn(" ftpSource1.txt", "ftpSource2.txt");
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
MessageSource<?> source = context.getBean(FtpStreamingMessageSource.class);
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize"), equalTo(11));
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize")).isEqualTo(11);
registration.destroy();
}
@@ -191,8 +183,8 @@ public class FtpTests extends FtpTestSupport {
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(sessionFactory());
FTPFile[] files = template.execute(session ->
session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
assertEquals(1, files.length);
assertEquals(3, files[0].getSize());
assertThat(files.length).isEqualTo(1);
assertThat(files[0].getSize()).isEqualTo(3);
registration.destroy();
}
@@ -214,17 +206,16 @@ public class FtpTests extends FtpTestSupport {
String dir = "ftpSource/";
registration.getInputChannel().send(new GenericMessage<>(dir + "*"));
Message<?> result = out.receive(10_000);
assertNotNull(result);
assertThat(result).isNotNull();
List<File> localFiles = (List<File>) result.getPayload();
// should have filtered ftpSource2.txt
assertEquals("unexpected local files " + localFiles, 2, localFiles.size());
assertThat(localFiles.size()).as("unexpected local files " + localFiles).isEqualTo(2);
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
Matchers.containsString(dir));
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/")).contains(dir);
}
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
Matchers.containsString(dir + "subFtpSource"));
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir + "subFtpSource");
registration.destroy();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2019 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.
@@ -16,9 +16,7 @@
package org.springframework.integration.ftp.filters;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.List;
@@ -53,16 +51,16 @@ public class FtpFileListFilterTests extends FtpTestSupport {
FtpSystemMarkerFilePresentFileListFilter filter = new FtpSystemMarkerFilePresentFileListFilter(
new FtpSimplePatternFileListFilter("*.txt"));
FTPFile[] files = template.list("ftpSource");
assertThat(files.length, greaterThan(0));
assertThat(files.length).isGreaterThan(0);
List<FTPFile> filtered = filter.filterFiles(files);
assertThat(filtered.size(), equalTo(0));
assertThat(filtered.size()).isEqualTo(0);
File remoteDir = getSourceRemoteDirectory();
File marker = new File(remoteDir, "ftpSource2.txt.complete");
marker.createNewFile();
files = template.list("ftpSource");
filtered = filter.filterFiles(files);
assertThat(filtered.size(), equalTo(1));
assertThat(filtered.get(0).getName(), equalTo("ftpSource2.txt"));
assertThat(filtered.size()).isEqualTo(1);
assertThat(filtered.get(0).getName()).isEqualTo("ftpSource2.txt");
marker.delete();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2019 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.
@@ -16,8 +16,7 @@
package org.springframework.integration.ftp.filters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Calendar;
@@ -50,16 +49,16 @@ public class FtpPersistentAcceptOnceFileListFilterTests {
ftpFile3.setTimestamp(Calendar.getInstance());
FTPFile[] files = new FTPFile[] {ftpFile1, ftpFile2, ftpFile3};
List<FTPFile> passed = filter.filterFiles(files);
assertTrue(Arrays.equals(files, passed.toArray()));
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
List<FTPFile> now = filter.filterFiles(files);
assertEquals(0, now.size());
assertThat(now.size()).isEqualTo(0);
filter.rollback(passed.get(1), passed);
now = filter.filterFiles(files);
assertEquals(2, now.size());
assertEquals("bar", now.get(0).getName());
assertEquals("baz", now.get(1).getName());
assertThat(now.size()).isEqualTo(2);
assertThat(now.get(0).getName()).isEqualTo("bar");
assertThat(now.get(1).getName()).isEqualTo("baz");
now = filter.filterFiles(files);
assertEquals(0, now.size());
assertThat(now.size()).isEqualTo(0);
filter.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,12 +16,7 @@
package org.springframework.integration.ftp.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -37,7 +32,6 @@ import java.util.List;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -81,7 +75,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTests {
@Test
public void testCopyFileToLocalDir() throws Exception {
File localDirectory = new File("test");
assertFalse(localDirectory.exists());
assertThat(localDirectory.exists()).isFalse();
TestFtpSessionFactory ftpSessionFactory = new TestFtpSessionFactory();
ftpSessionFactory.setUsername("kermit");
@@ -125,27 +119,27 @@ public class FtpInboundRemoteFileSystemSynchronizerTests {
ms.start();
Message<File> atestFile = ms.receive();
assertNotNull(atestFile);
assertEquals("A.TEST.a", atestFile.getPayload().getName());
assertThat(atestFile).isNotNull();
assertThat(atestFile.getPayload().getName()).isEqualTo("A.TEST.a");
// The test remote files are created with the current timestamp + 1 day.
assertThat(atestFile.getPayload().lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
assertThat(atestFile.getPayload().lastModified()).isGreaterThan(System.currentTimeMillis());
assertEquals("A.TEST.a", atestFile.getHeaders().get(FileHeaders.FILENAME));
assertThat(atestFile.getHeaders().get(FileHeaders.FILENAME)).isEqualTo("A.TEST.a");
Message<File> btestFile = ms.receive();
assertNotNull(btestFile);
assertEquals("B.TEST.a", btestFile.getPayload().getName());
assertThat(btestFile).isNotNull();
assertThat(btestFile.getPayload().getName()).isEqualTo("B.TEST.a");
// The test remote files are created with the current timestamp + 1 day.
assertThat(atestFile.getPayload().lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
assertThat(atestFile.getPayload().lastModified()).isGreaterThan(System.currentTimeMillis());
Message<File> nothing = ms.receive();
assertNull(nothing);
assertThat(nothing).isNull();
// two times because on the third receive (above) the internal queue will be empty, so it will attempt
verify(synchronizer, times(2)).synchronizeToLocalDirectory(localDirectory, Integer.MIN_VALUE);
assertTrue(new File("test/subdir/A.TEST.a").exists());
assertTrue(new File("test/subdir/B.TEST.a").exists());
assertThat(new File("test/subdir/A.TEST.a").exists()).isTrue();
assertThat(new File("test/subdir/B.TEST.a").exists()).isTrue();
TestUtils.getPropertyValue(localAcceptOnceFilter, "seenSet", Collection.class).clear();
@@ -153,7 +147,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTests {
new File("test/subdir/B.TEST.a").delete();
// the remote filter should prevent a re-fetch
nothing = ms.receive();
assertNull(nothing);
assertThat(nothing).isNull();
ms.stop();
verify(synchronizer).close();
@@ -179,7 +173,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTests {
File[] files = localDirectory.listFiles();
assertEquals(3, files.length);
assertThat(files.length).isEqualTo(3);
for (File f : files) {
f.delete();
@@ -187,7 +181,7 @@ public class FtpInboundRemoteFileSystemSynchronizerTests {
synchronizer.synchronizeToLocalDirectory(localDirectory);
assertEquals(0, localDirectory.list().length);
assertThat(localDirectory.list().length).isEqualTo(0);
}
private static void recursiveDelete(File file) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 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.
@@ -16,9 +16,7 @@
package org.springframework.integration.ftp.inbound;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,8 +46,8 @@ public class FtpMessageSourceTests extends FtpTestSupport {
public void testMaxFetch() throws Exception {
FtpInboundFileSynchronizingMessageSource messageSource = buildSource();
Message<?> received = messageSource.receive();
assertNotNull(received);
assertThat(received.getHeaders().get(FileHeaders.FILENAME), equalTo(" ftpSource1.txt"));
assertThat(received).isNotNull();
assertThat(received.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(" ftpSource1.txt");
}
private FtpInboundFileSynchronizingMessageSource buildSource() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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.
@@ -16,11 +16,7 @@
package org.springframework.integration.ftp.inbound;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.Closeable;
import java.io.InputStream;
@@ -92,27 +88,27 @@ public class FtpStreamingMessageSourceTests extends FtpTestSupport {
public void testAllContents() {
this.adapter.start();
Message<byte[]> received = (Message<byte[]>) this.data.receive(10000);
assertNotNull(received);
assertThat(new String(received.getPayload()), equalTo("source1"));
assertThat(received).isNotNull();
assertThat(new String(received.getPayload())).isEqualTo("source1");
String fileInfo = (String) received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO);
assertThat(fileInfo, containsString("remoteDirectory\":\"ftpSource"));
assertThat(fileInfo, containsString("permissions\":\"-rw-------"));
assertThat(fileInfo, containsString("size\":7"));
assertThat(fileInfo, containsString("directory\":false"));
assertThat(fileInfo, containsString("filename\":\" ftpSource1.txt"));
assertThat(fileInfo, containsString("modified\":"));
assertThat(fileInfo, containsString("link\":false"));
assertThat(fileInfo).contains("remoteDirectory\":\"ftpSource");
assertThat(fileInfo).contains("permissions\":\"-rw-------");
assertThat(fileInfo).contains("size\":7");
assertThat(fileInfo).contains("directory\":false");
assertThat(fileInfo).contains("filename\":\" ftpSource1.txt");
assertThat(fileInfo).contains("modified\":");
assertThat(fileInfo).contains("link\":false");
received = (Message<byte[]>) this.data.receive(10000);
assertNotNull(received);
assertThat(new String(received.getPayload()), equalTo("source2"));
assertThat(received).isNotNull();
assertThat(new String(received.getPayload())).isEqualTo("source2");
fileInfo = (String) received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO);
assertThat(fileInfo, containsString("remoteDirectory\":\"ftpSource"));
assertThat(fileInfo, containsString("permissions\":\"-rw-------"));
assertThat(fileInfo, containsString("size\":7"));
assertThat(fileInfo, containsString("directory\":false"));
assertThat(fileInfo, containsString("filename\":\"ftpSource2.txt"));
assertThat(fileInfo, containsString("modified\":"));
assertThat(fileInfo, containsString("link\":false"));
assertThat(fileInfo).contains("remoteDirectory\":\"ftpSource");
assertThat(fileInfo).contains("permissions\":\"-rw-------");
assertThat(fileInfo).contains("size\":7");
assertThat(fileInfo).contains("directory\":false");
assertThat(fileInfo).contains("filename\":\"ftpSource2.txt");
assertThat(fileInfo).contains("modified\":");
assertThat(fileInfo).contains("link\":false");
this.adapter.stop();
this.source.setFileInfoJson(false);
@@ -120,10 +116,10 @@ public class FtpStreamingMessageSourceTests extends FtpTestSupport {
this.metadataMap.clear();
this.adapter.start();
received = (Message<byte[]>) this.data.receive(10000);
assertNotNull(received);
assertThat(received).isNotNull();
this.adapter.stop();
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO), instanceOf(FtpFileInfo.class));
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO)).isInstanceOf(FtpFileInfo.class);
}
@Test
@@ -132,8 +128,8 @@ public class FtpStreamingMessageSourceTests extends FtpTestSupport {
messageSource.setFilter(new AcceptAllFileListFilter<>());
messageSource.afterPropertiesSet();
Message<InputStream> received = messageSource.receive();
assertNotNull(received);
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE), equalTo(" ftpSource1.txt"));
assertThat(received).isNotNull();
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo(" ftpSource1.txt");
Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(received);
if (closeableResource != null) {
@@ -147,8 +143,8 @@ public class FtpStreamingMessageSourceTests extends FtpTestSupport {
messageSource.setFilter(null);
messageSource.afterPropertiesSet();
Message<InputStream> received = messageSource.receive();
assertNotNull(received);
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE), equalTo(" ftpSource1.txt"));
assertThat(received).isNotNull();
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo(" ftpSource1.txt");
Closeable closeableResource = StaticMessageHeaderAccessor.getCloseableResource(received);
if (closeableResource != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,7 +16,7 @@
package org.springframework.integration.ftp.outbound;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Ignore;
import org.junit.Test;
@@ -37,7 +37,7 @@ public class BigMGetTests extends org.springframework.integration.file.BigMGetTe
@Test
@Ignore // needs directories and server (FTP and SFTP)
public void doTest() throws Exception {
assertEquals(FILES, this.mgetManyFiles().getPayload().size());
assertThat(this.mgetManyFiles().getPayload().size()).isEqualTo(FILES);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,10 +16,7 @@
package org.springframework.integration.ftp.outbound;
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 static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -90,16 +87,16 @@ public class FtpOutboundTests {
if (file.exists()) {
file.delete();
}
assertFalse(file.exists());
assertThat(file.exists()).isFalse();
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(message -> "handlerContent.test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<String>("String data"));
assertTrue(file.exists());
assertThat(file.exists()).isTrue();
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("String data", new String(inFile));
assertThat(new String(inFile)).isEqualTo("String data");
file.delete();
}
@@ -109,23 +106,23 @@ public class FtpOutboundTests {
if (file.exists()) {
file.delete();
}
assertFalse(file.exists());
assertThat(file.exists()).isFalse();
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(message -> "handlerContent.test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<byte[]>("byte[] data".getBytes()));
assertTrue(file.exists());
assertThat(file.exists()).isTrue();
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("byte[] data", new String(inFile));
assertThat(new String(inFile)).isEqualTo("byte[] data");
file.delete();
}
@Test
public void testHandleFileMessage() throws Exception {
File targetDir = new File("remote-target-dir");
assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());
assertThat(targetDir.exists()).as("target directory does not exist: " + targetDir.getName()).isTrue();
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName()));
@@ -140,13 +137,13 @@ public class FtpOutboundTests {
destFile.deleteOnExit();
handler.handleMessage(new GenericMessage<File>(srcFile));
assertTrue("destination file was not created", destFile.exists());
assertThat(destFile.exists()).as("destination file was not created").isTrue();
}
@Test
public void testHandleMissingFileMessage() throws Exception {
File targetDir = new File("remote-target-dir");
assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());
assertThat(targetDir.exists()).as("target directory does not exist: " + targetDir.getName()).isTrue();
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName()));
@@ -168,14 +165,14 @@ public class FtpOutboundTests {
RemoteFileTemplate.class);
new DirectFieldAccessor(template).setPropertyValue("logger", logger);
handler.handleMessage(new GenericMessage<File>(srcFile));
assertNotNull(logged.get());
assertEquals("File " + srcFile.toString() + " does not exist", logged.get());
assertThat(logged.get()).isNotNull();
assertThat(logged.get()).isEqualTo("File " + srcFile.toString() + " does not exist");
}
@Test //INT-2275
public void testFtpOutboundChannelAdapterInsideChain() throws Exception {
File targetDir = new File("remote-target-dir");
assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());
assertThat(targetDir.exists()).as("target directory does not exist: " + targetDir.getName()).isTrue();
File srcFile = File.createTempFile("testHandleFileMessage", ".tmp");
srcFile.deleteOnExit();
@@ -189,7 +186,7 @@ public class FtpOutboundTests {
MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class);
channel.send(new GenericMessage<File>(srcFile));
assertTrue("destination file was not created", destFile.exists());
assertThat(destFile.exists()).as("destination file was not created").isTrue();
context.close();
}
@@ -206,13 +203,13 @@ public class FtpOutboundTests {
Message<?> result = output.receive();
Object payload = result.getPayload();
assertTrue(payload instanceof List<?>);
assertThat(payload instanceof List<?>).isTrue();
@SuppressWarnings("unchecked")
List<? extends FileInfo<?>> remoteFiles = (List<? extends FileInfo<?>>) payload;
assertEquals(3, remoteFiles.size());
assertThat(remoteFiles.size()).isEqualTo(3);
List<String> files = Arrays.asList(new File("remote-test-dir").list());
for (FileInfo<?> remoteFile : remoteFiles) {
assertTrue(files.contains(remoteFile.getFilename()));
assertThat(files.contains(remoteFile.getFilename())).isTrue();
}
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2019 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.
@@ -16,21 +16,8 @@
package org.springframework.integration.ftp.outbound;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.isOneOf;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -52,7 +39,6 @@ import java.util.regex.Matcher;
import org.apache.commons.io.FileUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -173,19 +159,19 @@ public class FtpServerOutboundTests extends FtpTestSupport {
long modified = setModifiedOnSource1();
this.inboundGet.send(new GenericMessage<Object>(dir + " ftpSource1.txt"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
File localFile = (File) result.getPayload();
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir.toUpperCase()));
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir.toUpperCase());
assertPreserved(modified, localFile);
dir = "ftpSource/subFtpSource/";
this.inboundGet.send(new GenericMessage<Object>(dir + "subFtpSource1.txt"));
result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
localFile = (File) result.getPayload();
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir.toUpperCase()));
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir.toUpperCase());
}
@Test
@@ -194,11 +180,11 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.getGw.setOption(Option.DELETE);
this.inboundGet.send(new GenericMessage<Object>(dir + "ftpSource2.txt"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
File localFile = (File) result.getPayload();
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir.toUpperCase()));
assertThat(new File(getSourceRemoteDirectory(), "ftpSource2.txt").exists(), equalTo(false));
assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir.toUpperCase());
assertThat(new File(getSourceRemoteDirectory(), "ftpSource2.txt").exists()).isFalse();
}
@Test
@@ -209,10 +195,10 @@ public class FtpServerOutboundTests extends FtpTestSupport {
}
catch (Exception e) {
Throwable cause = e.getCause();
assertNotNull(cause);
assertThat(cause).isNotNull();
cause = cause.getCause();
assertThat(cause, Matchers.instanceOf(IllegalArgumentException.class));
assertThat(cause.getMessage(), Matchers.startsWith("Failed to make local directory"));
assertThat(cause).isInstanceOf(IllegalArgumentException.class);
assertThat(cause.getMessage()).startsWith("Failed to make local directory");
}
}
@@ -223,36 +209,36 @@ public class FtpServerOutboundTests extends FtpTestSupport {
long modified = setModifiedOnSource1();
this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
List<File> localFiles = (List<File>) result.getPayload();
assertThat(localFiles.size(), Matchers.greaterThan(0));
assertThat(localFiles.size()).isGreaterThan(0);
boolean assertedModified = false;
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir));
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/")).contains(dir);
if (file.getPath().contains("localTarget1")) {
assertedModified = assertPreserved(modified, file);
}
}
assertTrue(assertedModified);
assertThat(assertedModified).isTrue();
dir = "ftpSource/subFtpSource/";
this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt"));
result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
localFiles = (List<File>) result.getPayload();
assertThat(localFiles.size(), Matchers.greaterThan(0));
assertThat(localFiles.size()).isGreaterThan(0);
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir));
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/")).contains(dir);
}
this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt"));
result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
localFiles = (List<File>) result.getPayload();
assertThat(localFiles.size(), equalTo(0));
assertThat(localFiles.size()).isEqualTo(0);
}
@Test
@@ -264,14 +250,14 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.inboundMGet.send(new GenericMessage<Object>(""));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
List<File> localFiles = (List<File>) result.getPayload();
assertThat(localFiles.size(), Matchers.greaterThan(0));
assertThat(localFiles.size()).isGreaterThan(0);
for (File file : localFiles) {
assertThat(file.getName(), isOneOf(" localTarget1.txt", "localTarget2.txt"));
assertThat(file.getName(), not(containsString("null")));
assertThat(file.getName()).isIn(" localTarget1.txt", "localTarget2.txt");
assertThat(file.getName()).doesNotContain("null");
}
}
@@ -284,21 +270,20 @@ public class FtpServerOutboundTests extends FtpTestSupport {
secondRemote.setLastModified(System.currentTimeMillis() - 1_000_000);
this.inboundMGetRecursive.send(new GenericMessage<Object>("*"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
List<File> localFiles = (List<File>) result.getPayload();
assertEquals(3, localFiles.size());
assertThat(localFiles.size()).isEqualTo(3);
boolean assertedModified = false;
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir));
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/")).contains(dir);
if (file.getPath().contains("localTarget1")) {
assertedModified = assertPreserved(modified, file);
}
}
assertTrue(assertedModified);
assertThat(localFiles.get(2).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir + "subFtpSource"));
assertThat(assertedModified).isTrue();
assertThat(localFiles.get(2).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir + "subFtpSource");
File secondTarget = new File(getTargetLocalDirectory() + File.separator + "ftpSource", "localTarget2.txt");
ByteArrayOutputStream remoteContents = new ByteArrayOutputStream();
@@ -306,7 +291,7 @@ public class FtpServerOutboundTests extends FtpTestSupport {
FileUtils.copyFile(secondRemote, remoteContents);
FileUtils.copyFile(secondTarget, localContents);
String localAsString = new String(localContents.toByteArray());
assertEquals(new String(remoteContents.toByteArray()), localAsString);
assertThat(localAsString).isEqualTo(new String(remoteContents.toByteArray()));
long oldLastModified = secondRemote.lastModified();
FileUtils.copyInputStreamToFile(new ByteArrayInputStream("junk".getBytes()), secondRemote);
long newLastModified = secondRemote.lastModified();
@@ -315,13 +300,13 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.output.receive(0);
localContents = new ByteArrayOutputStream();
FileUtils.copyFile(secondTarget, localContents);
assertEquals(localAsString, new String(localContents.toByteArray()));
assertThat(new String(localContents.toByteArray())).isEqualTo(localAsString);
secondRemote.setLastModified(newLastModified);
this.inboundMGetRecursive.send(new GenericMessage<Object>("*"));
this.output.receive(0);
localContents = new ByteArrayOutputStream();
FileUtils.copyFile(secondTarget, localContents);
assertEquals("junk", new String(localContents.toByteArray()));
assertThat(new String(localContents.toByteArray())).isEqualTo("junk");
// restore the remote file contents
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(localAsString.getBytes()), secondRemote);
}
@@ -330,14 +315,14 @@ public class FtpServerOutboundTests extends FtpTestSupport {
File firstRemote = new File(getSourceRemoteDirectory(), " ftpSource1.txt");
firstRemote.setLastModified(System.currentTimeMillis() - 1_000_000);
long modified = firstRemote.lastModified();
assertTrue(modified > 0);
assertThat(modified > 0).isTrue();
return modified;
}
private boolean assertPreserved(long modified, File file) {
// ftp only has 1 minute resolution
assertTrue("lastModified wrong by " + (modified - file.lastModified()),
Math.abs(file.lastModified() - modified) < 61_000);
assertThat(Math.abs(file.lastModified() - modified) < 61_000)
.as("lastModified wrong by " + (modified - file.lastModified())).isTrue();
return true;
}
@@ -347,17 +332,16 @@ public class FtpServerOutboundTests extends FtpTestSupport {
String dir = "ftpSource/";
this.inboundMGetRecursiveFiltered.send(new GenericMessage<Object>(dir + "*"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertThat(result).isNotNull();
List<File> localFiles = (List<File>) result.getPayload();
// should have filtered ftpSource2.txt
assertEquals(2, localFiles.size());
assertThat(localFiles.size()).isEqualTo(2);
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir));
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/")).contains(dir);
}
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
containsString(dir + "subFtpSource"));
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
.contains(dir + "subFtpSource");
}
@@ -366,13 +350,13 @@ public class FtpServerOutboundTests extends FtpTestSupport {
Session<?> session = this.ftpSessionFactory.getSession();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileCopyUtils.copy(session.readRaw("ftpSource/ ftpSource1.txt"), baos);
assertTrue(session.finalizeRaw());
assertEquals("source1", new String(baos.toByteArray()));
assertThat(session.finalizeRaw()).isTrue();
assertThat(new String(baos.toByteArray())).isEqualTo("source1");
baos = new ByteArrayOutputStream();
FileCopyUtils.copy(session.readRaw("ftpSource/ftpSource2.txt"), baos);
assertTrue(session.finalizeRaw());
assertEquals("source2", new String(baos.toByteArray()));
assertThat(session.finalizeRaw()).isTrue();
assertThat(new String(baos.toByteArray())).isEqualTo("source2");
session.close();
}
@@ -384,14 +368,14 @@ public class FtpServerOutboundTests extends FtpTestSupport {
template.setBeanFactory(mock(BeanFactory.class));
template.afterPropertiesSet();
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
assertTrue(template.get(new GenericMessage<String>("ftpSource/ ftpSource1.txt"),
(InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos1)));
assertEquals("source1", new String(baos1.toByteArray()));
assertThat(template.get(new GenericMessage<String>("ftpSource/ ftpSource1.txt"),
(InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos1))).isTrue();
assertThat(new String(baos1.toByteArray())).isEqualTo("source1");
final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
assertTrue(template.get(new GenericMessage<String>("ftpSource/ftpSource2.txt"),
(InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos2)));
assertEquals("source2", new String(baos2.toByteArray()));
assertThat(template.get(new GenericMessage<String>("ftpSource/ftpSource2.txt"),
(InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos2))).isTrue();
assertThat(new String(baos2.toByteArray())).isEqualTo("source2");
}
@Test
@@ -399,16 +383,13 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.inboundMPut.send(new GenericMessage<File>(getSourceLocalDirectory()));
@SuppressWarnings("unchecked")
Message<List<String>> out = (Message<List<String>>) this.output.receive(1000);
assertNotNull(out);
assertEquals(2, out.getPayload().size());
assertThat(out.getPayload().get(0),
not(equalTo(out.getPayload().get(1))));
assertThat(
out.getPayload().get(0),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt")));
assertThat(
out.getPayload().get(1),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt")));
assertThat(out).isNotNull();
assertThat(out.getPayload().size()).isEqualTo(2);
assertThat(out.getPayload().get(0)).isNotEqualTo(out.getPayload().get(1));
assertThat(out.getPayload().get(0))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt");
assertThat(out.getPayload().get(1))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt");
}
@Test
@@ -416,22 +397,18 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.inboundMPutRecursive.send(new GenericMessage<File>(getSourceLocalDirectory()));
@SuppressWarnings("unchecked")
Message<List<String>> out = (Message<List<String>>) this.output.receive(1000);
assertNotNull(out);
assertEquals(3, out.getPayload().size());
assertThat(out.getPayload().get(0),
not(equalTo(out.getPayload().get(1))));
assertThat(
out.getPayload().get(0),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"),
equalTo("ftpTarget/subLocalSource/subLocalSource1.txt")));
assertThat(
out.getPayload().get(1),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"),
equalTo("ftpTarget/subLocalSource/subLocalSource1.txt")));
assertThat(
out.getPayload().get(2),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"),
equalTo("ftpTarget/subLocalSource/subLocalSource1.txt")));
assertThat(out).isNotNull();
assertThat(out.getPayload()).hasSize(3);
assertThat(out.getPayload().get(0)).isNotEqualTo(out.getPayload().get(1));
assertThat(out.getPayload().get(0))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt",
"ftpTarget/subLocalSource/subLocalSource1.txt");
assertThat(out.getPayload().get(1))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt",
"ftpTarget/subLocalSource/subLocalSource1.txt");
assertThat(out.getPayload().get(2))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt",
"ftpTarget/subLocalSource/subLocalSource1.txt");
}
@Test
@@ -439,24 +416,21 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.inboundMPutRecursiveFiltered.send(new GenericMessage<File>(getSourceLocalDirectory()));
@SuppressWarnings("unchecked")
Message<List<String>> out = (Message<List<String>>) this.output.receive(1000);
assertNotNull(out);
assertEquals(2, out.getPayload().size());
assertThat(out.getPayload().get(0),
not(equalTo(out.getPayload().get(1))));
assertThat(
out.getPayload().get(0),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"),
equalTo("ftpTarget/subLocalSource/subLocalSource1.txt")));
assertThat(
out.getPayload().get(1),
anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"),
equalTo("ftpTarget/subLocalSource/subLocalSource1.txt")));
assertThat(out).isNotNull();
assertThat(out.getPayload()).hasSize(2);
assertThat(out.getPayload().get(0)).isNotEqualTo(out.getPayload().get(1));
assertThat(out.getPayload().get(0))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt",
"ftpTarget/subLocalSource/subLocalSource1.txt");
assertThat(out.getPayload().get(1))
.isIn("ftpTarget/localSource1.txt", "ftpTarget/localSource2.txt",
"ftpTarget/subLocalSource/subLocalSource1.txt");
}
@Test
public void testInt3412FileMode() {
FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(ftpSessionFactory);
assertFalse(template.exists("ftpTarget/appending.txt"));
assertThat(template.exists("ftpTarget/appending.txt")).isFalse();
Message<String> m = MessageBuilder.withPayload("foo")
.setHeader(FileHeaders.FILENAME, "appending.txt")
.build();
@@ -472,7 +446,7 @@ public class FtpServerOutboundTests extends FtpTestSupport {
fail("Expected exception");
}
catch (MessagingException e) {
assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
assertThat(e.getCause().getCause().getMessage()).contains("The destination file already exists");
}
}
@@ -482,27 +456,29 @@ public class FtpServerOutboundTests extends FtpTestSupport {
String dir = "ftpSource/";
this.inboundGetStream.send(new GenericMessage<Object>(dir + " ftpSource1.txt"));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
assertEquals("source1", result.getPayload());
assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
assertEquals(" ftpSource1.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("source1");
assertThat(result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("ftpSource/");
assertThat(result.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo(" ftpSource1.txt");
Session<?> session = (Session<?>) result.getHeaders().get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE);
// Returned to cache
assertTrue(session.isOpen());
assertThat(session.isOpen()).isTrue();
// Raw reading is finished
assertFalse(TestUtils.getPropertyValue(session, "targetSession.readingRaw", AtomicBoolean.class).get());
assertThat(TestUtils.getPropertyValue(session, "targetSession.readingRaw", AtomicBoolean.class).get())
.isFalse();
// Check that we can use the same session from cache to read another remote InputStream
this.inboundGetStream.send(new GenericMessage<Object>(dir + "ftpSource2.txt"));
result = this.output.receive(1000);
assertNotNull(result);
assertEquals("source2", result.getPayload());
assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
assertEquals("ftpSource2.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));
assertSame(TestUtils.getPropertyValue(session, "targetSession"),
TestUtils.getPropertyValue(result.getHeaders().get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE),
"targetSession"));
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("source2");
assertThat(result.getHeaders())
.containsEntry(FileHeaders.REMOTE_DIRECTORY, "ftpSource/")
.containsEntry(FileHeaders.REMOTE_FILE, "ftpSource2.txt");
assertThat(TestUtils
.getPropertyValue(result.getHeaders().get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE),
"targetSession")).isSameAs(TestUtils.getPropertyValue(session, "targetSession"));
}
@Test
@@ -523,10 +499,10 @@ public class FtpServerOutboundTests extends FtpTestSupport {
fail("expected exception");
}
catch (PartialSuccessException e) {
assertEquals(2, e.getDerivedInput().size());
assertEquals(1, e.getPartialResults().size());
assertThat(e.getCause().getMessage(),
containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory."));
assertThat(e.getDerivedInput()).hasSize(2);
assertThat(e.getPartialResults()).hasSize(1);
assertThat(e.getCause().getMessage())
.contains("/ftpSource/subFtpSource/bogus.txt: No such file or directory.");
}
}
@@ -550,10 +526,10 @@ public class FtpServerOutboundTests extends FtpTestSupport {
fail("expected exception");
}
catch (PartialSuccessException e) {
assertEquals(4, e.getDerivedInput().size());
assertEquals(2, e.getPartialResults().size());
assertThat(e.getCause().getMessage(),
containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory."));
assertThat(e.getDerivedInput()).hasSize(4);
assertThat(e.getPartialResults()).hasSize(2);
assertThat(e.getCause().getMessage())
.contains("/ftpSource/subFtpSource/bogus.txt: No such file or directory.");
}
}
@@ -568,19 +544,18 @@ public class FtpServerOutboundTests extends FtpTestSupport {
fail("expected exception");
}
catch (PartialSuccessException e) {
assertEquals(3, e.getDerivedInput().size());
assertEquals(1, e.getPartialResults().size());
assertEquals("ftpTarget/localSource1.txt", e.getPartialResults().iterator().next());
assertThat(e.getCause().getMessage(),
containsString("Failed to send localSource2"));
assertThat(e.getDerivedInput()).hasSize(3);
assertThat(e.getPartialResults()).hasSize(1);
assertThat(e.getPartialResults().iterator().next()).isEqualTo("ftpTarget/localSource1.txt");
assertThat(e.getCause().getMessage()).contains("Failed to send localSource2");
}
}
@Test
public void testMputRecursivePartial() throws Exception {
Session<FTPFile> session = spyOnSession();
File sourceLocalSubDirectory = new File(getSourceLocalDirectory(), "subLocalSource");
assertTrue(sourceLocalSubDirectory.isDirectory());
File sourceLocalSubDirectory = new File(getSourceLocalDirectory(), "subLocalSource");
assertThat(sourceLocalSubDirectory.isDirectory()).isTrue();
File extra = new File(sourceLocalSubDirectory, "subLocalSource2.txt");
FileOutputStream writer = new FileOutputStream(extra);
writer.write("foo".getBytes());
@@ -593,13 +568,13 @@ public class FtpServerOutboundTests extends FtpTestSupport {
fail("expected exception");
}
catch (PartialSuccessException e) {
assertEquals(3, e.getDerivedInput().size());
assertEquals(2, e.getPartialResults().size());
assertThat(e.getCause(), Matchers.instanceOf(PartialSuccessException.class));
assertThat(e.getDerivedInput()).hasSize(3);
assertThat(e.getPartialResults()).hasSize(2);
assertThat(e.getCause()).isInstanceOf(PartialSuccessException.class);
PartialSuccessException cause = (PartialSuccessException) e.getCause();
assertEquals(2, cause.getDerivedInput().size());
assertEquals(1, cause.getPartialResults().size());
assertThat(cause.getCause().getMessage(), containsString("Failed to send subLocalSource2"));
assertThat(cause.getDerivedInput()).hasSize(2);
assertThat(cause.getPartialResults()).hasSize(1);
assertThat(cause.getCause().getMessage()).contains("Failed to send subLocalSource2");
}
extra.delete();
}
@@ -610,7 +585,7 @@ public class FtpServerOutboundTests extends FtpTestSupport {
@SuppressWarnings("unchecked")
BlockingQueue<Session<FTPFile>> cache = TestUtils.getPropertyValue(ftpSessionFactory, "pool.available",
BlockingQueue.class);
assertNotNull(cache.poll());
assertThat(cache.poll()).isNotNull();
cache.offer(session);
@SuppressWarnings("unchecked")
Set<Session<FTPFile>> allocated = TestUtils.getPropertyValue(ftpSessionFactory, "pool.allocated",
@@ -622,16 +597,16 @@ public class FtpServerOutboundTests extends FtpTestSupport {
private void assertLength6(FtpRemoteFileTemplate template) {
FTPFile[] files = template.execute(session -> session.list("ftpTarget/appending.txt"));
assertEquals(1, files.length);
assertEquals(6, files[0].getSize());
assertThat(files).hasSize(1);
assertThat(files[0].getSize()).isEqualTo(6);
}
@Test
public void testMessageSessionCallback() {
this.inboundCallback.send(new GenericMessage<String>("foo"));
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals("FOO", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("FOO");
}
@Test
@@ -643,16 +618,16 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.inboundLs.send(new GenericMessage<String>("foo"));
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(List.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(List.class);
List<String> files = (List<String>) receive.getPayload();
assertEquals(2, files.size());
assertThat(files, containsInAnyOrder(" ftpSource1.txt", "ftpSource2.txt"));
assertThat(files.size()).isEqualTo(2);
assertThat(files).contains(" ftpSource1.txt", "ftpSource2.txt");
FTPFile[] ftpFiles = ftpSessionFactory.getSession().list(null);
for (FTPFile ftpFile : ftpFiles) {
if (!ftpFile.isDirectory()) {
assertTrue(files.contains(ftpFile.getName()));
assertThat(files.contains(ftpFile.getName())).isTrue();
}
}
}
@@ -662,16 +637,16 @@ public class FtpServerOutboundTests extends FtpTestSupport {
public void testNlstAndWorkingDirExpression() throws IOException {
this.inboundNlst.send(new GenericMessage<>("foo"));
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(List.class));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isInstanceOf(List.class);
List<String> files = (List<String>) receive.getPayload();
assertEquals(3, files.size());
assertThat(files, containsInAnyOrder("subFtpSource", " ftpSource1.txt", "ftpSource2.txt"));
assertThat(files.size()).isEqualTo(3);
assertThat(files).contains("subFtpSource", " ftpSource1.txt", "ftpSource2.txt");
FTPFile[] ftpFiles = ftpSessionFactory.getSession().list(null);
for (FTPFile ftpFile : ftpFiles) {
if (!ftpFile.isDirectory()) {
assertTrue(files.contains(ftpFile.getName()));
assertThat(files.contains(ftpFile.getName())).isTrue();
}
}
}
@@ -684,16 +659,16 @@ public class FtpServerOutboundTests extends FtpTestSupport {
this.ftpInbound.start();
Message<?> message = this.output.receive(10000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(File.class));
assertEquals(" ftpSource1.txt", ((File) message.getPayload()).getName());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
assertThat(((File) message.getPayload()).getName()).isEqualTo(" ftpSource1.txt");
message = this.output.receive(10000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(File.class));
assertEquals("ftpSource2.txt", ((File) message.getPayload()).getName());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
assertThat(((File) message.getPayload()).getName()).isEqualTo("ftpSource2.txt");
assertNull(this.output.receive(10));
assertThat(this.output.receive(10)).isNull();
this.ftpInbound.stop();
}

View File

@@ -16,10 +16,8 @@
package org.springframework.integration.ftp.session;
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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -79,24 +77,24 @@ public class FtpRemoteFileTemplateTests extends FtpTestSupport {
});
template.append(new GenericMessage<>("foo"));
template.append(new GenericMessage<>("bar"));
assertTrue(template.exists("foo/foobar.txt"));
assertThat(template.exists("foo/foobar.txt")).isTrue();
template.executeWithClient((ClientCallbackWithoutResult<FTPClient>) client -> {
try {
FTPFile[] files = client.listFiles("foo/foobar.txt");
assertEquals(6, files[0].getSize());
assertThat(files[0].getSize()).isEqualTo(6);
}
catch (IOException e) {
throw new RuntimeException(e);
}
});
template.execute((SessionCallbackWithoutResult<FTPFile>) session -> {
assertTrue(session.remove("foo/foobar.txt"));
assertTrue(session.rmdir("foo/bar/"));
assertThat(session.remove("foo/foobar.txt")).isTrue();
assertThat(session.rmdir("foo/bar/")).isTrue();
FTPFile[] files = session.list("foo/");
assertEquals(0, files.length);
assertTrue(session.rmdir("foo/"));
assertThat(files.length).isEqualTo(0);
assertThat(session.rmdir("foo/")).isTrue();
});
assertFalse(template.getSession().exists("foo"));
assertThat(template.getSession().exists("foo")).isFalse();
}
@Test
@@ -116,10 +114,10 @@ public class FtpRemoteFileTemplateTests extends FtpTestSupport {
fail("exception expected");
}
catch (MessagingException e) {
assertEquals("bar", e.getCause().getMessage());
assertThat(e.getCause().getMessage()).isEqualTo("bar");
}
File newFile = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
assertTrue(file.renameTo(newFile));
assertThat(file.renameTo(newFile)).isTrue();
file.delete();
newFile.delete();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -16,8 +16,8 @@
package org.springframework.integration.ftp.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -30,7 +30,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.net.ftp.FTPClient;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -77,17 +76,15 @@ public class SessionFactoryTests {
public void testWithControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
sessionFactory.setControlEncoding("UTF-8");
Assert.assertEquals("Expected controlEncoding value of 'UTF-8'",
"UTF-8",
TestUtils.getPropertyValue(sessionFactory, "controlEncoding"));
assertThat(TestUtils.getPropertyValue(sessionFactory, "controlEncoding"))
.as("Expected controlEncoding value of 'UTF-8'").isEqualTo("UTF-8");
}
@Test
public void testWithoutControlEncoding() {
DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
Assert.assertEquals("Expected controlEncoding value of 'ISO-8859-1'",
"ISO-8859-1",
TestUtils.getPropertyValue(sessionFactory, "controlEncoding"));
assertThat(TestUtils.getPropertyValue(sessionFactory, "controlEncoding"))
.as("Expected controlEncoding value of 'ISO-8859-1'").isEqualTo("ISO-8859-1");
}
@Test(expected = IllegalArgumentException.class)
@@ -114,13 +111,11 @@ public class SessionFactoryTests {
sessionFactory.setClientMode(clientMode);
if (!(clientMode == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE ||
clientMode == FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE)) {
fail();
fail("IllegalArgumentException expected");
}
}
catch (IllegalArgumentException e) {
// success
} catch (Throwable e) {
fail();
}
}
}
@@ -144,7 +139,8 @@ public class SessionFactoryTests {
Session secondSession = cachingFactory.getSession();
secondSession.close();
Session nonStaleSession = cachingFactory.getSession();
assertEquals(TestUtils.getPropertyValue(firstSession, "targetSession"), TestUtils.getPropertyValue(nonStaleSession, "targetSession"));
assertThat(TestUtils.getPropertyValue(nonStaleSession, "targetSession"))
.isEqualTo(TestUtils.getPropertyValue(firstSession, "targetSession"));
}
@Test
@@ -159,7 +155,8 @@ public class SessionFactoryTests {
s1.close();
Session s2 = cachingFactory.getSession();
s2.close();
assertEquals(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s2, "targetSession"));
assertThat(TestUtils.getPropertyValue(s2, "targetSession"))
.isEqualTo(TestUtils.getPropertyValue(s1, "targetSession"));
Mockito.verify(sessionFactory, Mockito.times(2)).getSession();
}
@@ -206,6 +203,6 @@ public class SessionFactoryTests {
executor.shutdown();
executor.awaitTermination(10000, TimeUnit.SECONDS);
assertEquals(0, failures.get());
assertThat(failures.get()).isEqualTo(0);
}
}