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:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.sftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -47,16 +46,16 @@ public class InboundChannelAdapterParserCachingTests {
|
||||
@Test
|
||||
public void cachingAdapter() {
|
||||
Object sessionFactory = TestUtils.getPropertyValue(cachingAdapter, "source.synchronizer.remoteFileTemplate.sessionFactory");
|
||||
assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
|
||||
assertThat(sessionFactory.getClass()).isEqualTo(CachingSessionFactory.class);
|
||||
Properties sessionConfig = TestUtils.getPropertyValue(sessionFactory, "sessionFactory.sessionConfig", Properties.class);
|
||||
assertNotNull(sessionConfig);
|
||||
assertEquals("no", sessionConfig.getProperty("StrictHostKeyChecking"));
|
||||
assertThat(sessionConfig).isNotNull();
|
||||
assertThat(sessionConfig.getProperty("StrictHostKeyChecking")).isEqualTo("no");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonCachingAdapter() {
|
||||
Object sessionFactory = TestUtils.getPropertyValue(nonCachingAdapter, "source.synchronizer.remoteFileTemplate.sessionFactory");
|
||||
assertEquals(DefaultSftpSessionFactory.class, sessionFactory.getClass());
|
||||
assertThat(sessionFactory.getClass()).isEqualTo(DefaultSftpSessionFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,13 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.config;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
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.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -64,7 +58,7 @@ public class InboundChannelAdapterParserTests {
|
||||
new ClassPathXmlApplicationContext("SftpInboundAutostartup-context.xml", this.getClass());
|
||||
|
||||
SourcePollingChannelAdapter adapter = context.getBean("sftpAutoStartup", SourcePollingChannelAdapter.class);
|
||||
assertFalse(adapter.isRunning());
|
||||
assertThat(adapter.isRunning()).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -72,37 +66,37 @@ public class InboundChannelAdapterParserTests {
|
||||
public void testWithLocalFiles() throws Exception {
|
||||
ConfigurableApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("InboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
assertTrue(new File("src/main/resources").exists());
|
||||
assertThat(new File("src/main/resources").exists()).isTrue();
|
||||
|
||||
Object adapter = context.getBean("sftpAdapterAutoCreate");
|
||||
assertTrue(adapter instanceof SourcePollingChannelAdapter);
|
||||
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
|
||||
SftpInboundFileSynchronizingMessageSource source =
|
||||
(SftpInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source");
|
||||
assertNotNull(source);
|
||||
assertThat(source).isNotNull();
|
||||
|
||||
PriorityBlockingQueue<?> blockingQueue =
|
||||
TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
|
||||
Comparator<?> comparator = blockingQueue.comparator();
|
||||
|
||||
assertNotNull(comparator);
|
||||
assertThat(comparator).isNotNull();
|
||||
SftpInboundFileSynchronizer synchronizer =
|
||||
TestUtils.getPropertyValue(source, "synchronizer", SftpInboundFileSynchronizer.class);
|
||||
assertEquals("'/foo'", TestUtils.getPropertyValue(synchronizer, "remoteDirectoryExpression", Expression.class)
|
||||
.getExpressionString());
|
||||
assertNotNull(TestUtils.getPropertyValue(synchronizer, "localFilenameGeneratorExpression"));
|
||||
assertTrue(TestUtils.getPropertyValue(synchronizer, "preserveTimestamp", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(synchronizer, "remoteDirectoryExpression", Expression.class)
|
||||
.getExpressionString()).isEqualTo("'/foo'");
|
||||
assertThat(TestUtils.getPropertyValue(synchronizer, "localFilenameGeneratorExpression")).isNotNull();
|
||||
assertThat(TestUtils.getPropertyValue(synchronizer, "preserveTimestamp", Boolean.class)).isTrue();
|
||||
String remoteFileSeparator = (String) TestUtils.getPropertyValue(synchronizer, "remoteFileSeparator");
|
||||
assertEquals(".bar", TestUtils.getPropertyValue(synchronizer, "temporaryFileSuffix", String.class));
|
||||
assertNotNull(remoteFileSeparator);
|
||||
assertEquals(".", remoteFileSeparator);
|
||||
assertThat(TestUtils.getPropertyValue(synchronizer, "temporaryFileSuffix", String.class)).isEqualTo(".bar");
|
||||
assertThat(remoteFileSeparator).isNotNull();
|
||||
assertThat(remoteFileSeparator).isEqualTo(".");
|
||||
PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
|
||||
assertNotNull(requestChannel.receive(10000));
|
||||
assertThat(requestChannel.receive(10000)).isNotNull();
|
||||
FileListFilter<?> acceptAllFilter = context.getBean("acceptAllFilter", FileListFilter.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<FileListFilter<?>> filters =
|
||||
TestUtils.getPropertyValue(source, "fileSource.scanner.filter.fileFilters", Collection.class);
|
||||
assertThat(filters, hasItem(acceptAllFilter));
|
||||
assertEquals(42, source.getMaxFetchSize());
|
||||
assertThat(filters).contains(acceptAllFilter);
|
||||
assertThat(source.getMaxFetchSize()).isEqualTo(42);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -114,27 +108,28 @@ public class InboundChannelAdapterParserTests {
|
||||
MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class);
|
||||
SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter",
|
||||
SourcePollingChannelAdapter.class);
|
||||
assertEquals("/foo", TestUtils
|
||||
.getPropertyValue(autoChannelAdapter, "source.synchronizer.remoteDirectoryExpression", Expression.class)
|
||||
.getExpressionString());
|
||||
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
|
||||
assertEquals(Integer.MIN_VALUE, TestUtils.getPropertyValue(autoChannelAdapter, "source.maxFetchSize"));
|
||||
assertThat(TestUtils
|
||||
.getPropertyValue(autoChannelAdapter, "source.synchronizer.remoteDirectoryExpression",
|
||||
Expression.class)
|
||||
.getExpressionString()).isEqualTo("/foo");
|
||||
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
|
||||
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "source.maxFetchSize")).isEqualTo(Integer.MIN_VALUE);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionStoreException.class)
|
||||
//exactly one of 'filename-pattern' or 'filter' is allowed on SFTP inbound adapter
|
||||
public void testFailWithFilePatternAndFilter() throws Exception {
|
||||
assertTrue(!new File("target/bar").exists());
|
||||
assertThat(!new File("target/bar").exists()).isTrue();
|
||||
new ClassPathXmlApplicationContext("InboundChannelAdapterParserTests-context-fail.xml", this.getClass()).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalDirAutoCreated() throws Exception {
|
||||
assertFalse(new File("foo").exists());
|
||||
assertThat(new File("foo").exists()).isFalse();
|
||||
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"InboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
assertTrue(new File("foo").exists());
|
||||
assertThat(new File("foo").exists()).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.sftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -45,13 +45,13 @@ public class OutboundChannelAdapterParserCachingTests {
|
||||
@Test
|
||||
public void cachingAdapter() {
|
||||
Object sessionFactory = TestUtils.getPropertyValue(cachingAdapter, "handler.remoteFileTemplate.sessionFactory");
|
||||
assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
|
||||
assertThat(sessionFactory.getClass()).isEqualTo(CachingSessionFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonCachingAdapter() {
|
||||
Object sessionFactory = TestUtils.getPropertyValue(nonCachingAdapter, "handler.remoteFileTemplate.sessionFactory");
|
||||
assertEquals(DefaultSftpSessionFactory.class, sessionFactory.getClass());
|
||||
assertThat(sessionFactory.getClass()).isEqualTo(DefaultSftpSessionFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,19 +16,12 @@
|
||||
|
||||
package org.springframework.integration.sftp.config;
|
||||
|
||||
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 java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
@@ -64,33 +57,34 @@ public class OutboundChannelAdapterParserTests {
|
||||
ConfigurableApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object consumer = context.getBean("sftpOutboundAdapter");
|
||||
assertTrue(consumer instanceof EventDrivenConsumer);
|
||||
assertThat(consumer instanceof EventDrivenConsumer).isTrue();
|
||||
PublishSubscribeChannel channel = context.getBean("inputChannel", PublishSubscribeChannel.class);
|
||||
assertEquals(channel, TestUtils.getPropertyValue(consumer, "inputChannel"));
|
||||
assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer) consumer).getComponentName());
|
||||
assertThat(TestUtils.getPropertyValue(consumer, "inputChannel")).isEqualTo(channel);
|
||||
assertThat(((EventDrivenConsumer) consumer).getComponentName()).isEqualTo("sftpOutboundAdapter");
|
||||
FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler",
|
||||
FileTransferringMessageHandler.class);
|
||||
String remoteFileSeparator = (String) TestUtils.getPropertyValue(handler,
|
||||
"remoteFileTemplate.remoteFileSeparator");
|
||||
assertNotNull(remoteFileSeparator);
|
||||
assertEquals(".", remoteFileSeparator);
|
||||
assertEquals(".bar",
|
||||
TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryFileSuffix", String.class));
|
||||
assertThat(remoteFileSeparator).isNotNull();
|
||||
assertThat(remoteFileSeparator).isEqualTo(".");
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryFileSuffix", String.class))
|
||||
.isEqualTo(".bar");
|
||||
Expression remoteDirectoryExpression = (Expression) TestUtils.getPropertyValue(handler,
|
||||
"remoteFileTemplate.directoryExpressionProcessor.expression");
|
||||
assertNotNull(remoteDirectoryExpression);
|
||||
assertTrue(remoteDirectoryExpression instanceof LiteralExpression);
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
|
||||
assertEquals(context.getBean("fileNameGenerator"),
|
||||
TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"));
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
|
||||
assertThat(remoteDirectoryExpression).isNotNull();
|
||||
assertThat(remoteDirectoryExpression instanceof LiteralExpression).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"))
|
||||
.isNotNull();
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"))
|
||||
.isEqualTo(context.getBean("fileNameGenerator"));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")).isEqualTo("UTF-8");
|
||||
CachingSessionFactory<?> sessionFactory = TestUtils.getPropertyValue(handler,
|
||||
"remoteFileTemplate.sessionFactory", CachingSessionFactory.class);
|
||||
DefaultSftpSessionFactory clientFactory = TestUtils.getPropertyValue(sessionFactory, "sessionFactory",
|
||||
DefaultSftpSessionFactory.class);
|
||||
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
|
||||
assertEquals(2222, TestUtils.getPropertyValue(clientFactory, "port"));
|
||||
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
|
||||
assertThat(TestUtils.getPropertyValue(clientFactory, "host")).isEqualTo("localhost");
|
||||
assertThat(TestUtils.getPropertyValue(clientFactory, "port")).isEqualTo(2222);
|
||||
assertThat(TestUtils.getPropertyValue(handler, "order")).isEqualTo(23);
|
||||
//verify subscription order
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
|
||||
@@ -98,10 +92,10 @@ public class OutboundChannelAdapterParserTests {
|
||||
TestUtils.getPropertyValue(channel, "dispatcher"),
|
||||
"handlers");
|
||||
Iterator<MessageHandler> iterator = handlers.iterator();
|
||||
assertSame(TestUtils.getPropertyValue(context.getBean("sftpOutboundAdapterWithExpression"), "handler"),
|
||||
iterator.next());
|
||||
assertSame(handler, iterator.next());
|
||||
assertEquals(384, TestUtils.getPropertyValue(handler, "chmod"));
|
||||
assertThat(iterator.next())
|
||||
.isSameAs(TestUtils.getPropertyValue(context.getBean("sftpOutboundAdapterWithExpression"), "handler"));
|
||||
assertThat(iterator.next()).isSameAs(handler);
|
||||
assertThat(TestUtils.getPropertyValue(handler, "chmod")).isEqualTo(384);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -110,19 +104,21 @@ public class OutboundChannelAdapterParserTests {
|
||||
ConfigurableApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object consumer = context.getBean("sftpOutboundAdapterWithExpression");
|
||||
assertTrue(consumer instanceof EventDrivenConsumer);
|
||||
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
|
||||
assertEquals("sftpOutboundAdapterWithExpression", ((EventDrivenConsumer) consumer).getComponentName());
|
||||
assertThat(consumer instanceof EventDrivenConsumer).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(consumer, "inputChannel")).isEqualTo(context.getBean("inputChannel"));
|
||||
assertThat(((EventDrivenConsumer) consumer).getComponentName()).isEqualTo("sftpOutboundAdapterWithExpression");
|
||||
FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class);
|
||||
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor.expression");
|
||||
assertNotNull(remoteDirectoryExpression);
|
||||
assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
|
||||
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler,
|
||||
"remoteFileTemplate.directoryExpressionProcessor.expression");
|
||||
assertThat(remoteDirectoryExpression).isNotNull();
|
||||
assertThat(remoteDirectoryExpression.getExpressionString()).isEqualTo("'foo' + '/' + 'bar'");
|
||||
FileNameGenerator generator = (FileNameGenerator) TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator");
|
||||
Expression fileNameGeneratorExpression = TestUtils.getPropertyValue(generator, "expression", Expression.class);
|
||||
assertNotNull(fileNameGeneratorExpression);
|
||||
assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression.getExpressionString());
|
||||
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
|
||||
assertNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
|
||||
assertThat(fileNameGeneratorExpression).isNotNull();
|
||||
assertThat(fileNameGeneratorExpression.getExpressionString()).isEqualTo("payload.getName() + '-foo'");
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")).isEqualTo("UTF-8");
|
||||
assertThat(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"))
|
||||
.isNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -132,7 +128,7 @@ public class OutboundChannelAdapterParserTests {
|
||||
new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object consumer = context.getBean("sftpOutboundAdapterWithNoTemporaryFileName");
|
||||
FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class);
|
||||
assertFalse((Boolean) TestUtils.getPropertyValue(handler, "remoteFileTemplate.useTemporaryFileName"));
|
||||
assertThat((Boolean) TestUtils.getPropertyValue(handler, "remoteFileTemplate.useTemporaryFileName")).isFalse();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -143,7 +139,7 @@ public class OutboundChannelAdapterParserTests {
|
||||
Object consumer = context.getBean("advised");
|
||||
MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class);
|
||||
handler.handleMessage(new GenericMessage<String>("foo"));
|
||||
assertEquals(1, adviceCalled);
|
||||
assertThat(adviceCalled).isEqualTo(1);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -155,7 +151,7 @@ public class OutboundChannelAdapterParserTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (BeanDefinitionStoreException e) {
|
||||
assertThat(e.getMessage(), Matchers.containsString("Only one of 'remote-directory'"));
|
||||
assertThat(e.getMessage()).contains("Only one of 'remote-directory'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.sftp.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 SftpInboundOutboundSanitySample {
|
||||
Thread.sleep(5000);
|
||||
fileA = new File("local-test-dir/a.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 SftpInboundOutboundSanitySample {
|
||||
Thread.sleep(6000);
|
||||
fileA = new File("remote-target-dir/a.test-foo");
|
||||
fileB = new File("remote-target-dir/b.test-foo");
|
||||
assertTrue(fileA.exists());
|
||||
assertTrue(fileB.exists());
|
||||
assertThat(fileA.exists()).isTrue();
|
||||
assertThat(fileB.exists()).isTrue();
|
||||
ac.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.sftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -35,8 +35,8 @@ public class SftpMessageHistoryTests {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("MessageHistory-context.xml",
|
||||
SftpMessageHistoryTests.class);
|
||||
SourcePollingChannelAdapter spca = ac.getBean("sftpAdapter", SourcePollingChannelAdapter.class);
|
||||
assertEquals("sftpAdapter", spca.getComponentName());
|
||||
assertEquals("sftp:inbound-channel-adapter", spca.getComponentType());
|
||||
assertThat(spca.getComponentName()).isEqualTo("sftpAdapter");
|
||||
assertThat(spca.getComponentType()).isEqualTo("sftp:inbound-channel-adapter");
|
||||
ac.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -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,18 +16,12 @@
|
||||
|
||||
package org.springframework.integration.sftp.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;
|
||||
|
||||
@@ -85,77 +79,83 @@ public class SftpOutboundGatewayParserTests {
|
||||
public void testGateway1() {
|
||||
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway1,
|
||||
"handler", SftpOutboundGateway.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((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory"));
|
||||
assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", 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((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory")).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isTrue();
|
||||
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);
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter"), Matchers.instanceOf(RegexPatternFileListFilter.class));
|
||||
assertThat(sendTimeout).isEqualTo(Long.valueOf(777));
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter")).isInstanceOf(RegexPatternFileListFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGateway2() throws Exception {
|
||||
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway2,
|
||||
"handler", SftpOutboundGateway.class);
|
||||
assertEquals("X", TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator"));
|
||||
assertNotNull(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory"));
|
||||
assertTrue(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory") instanceof CachingSessionFactory);
|
||||
assertNotNull(TestUtils.getPropertyValue(gateway, "outputChannel"));
|
||||
assertEquals("local-test-dir", TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"));
|
||||
assertFalse((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory"));
|
||||
assertEquals(Command.GET, TestUtils.getPropertyValue(gateway, "command"));
|
||||
assertFalse(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.remoteFileSeparator")).isEqualTo("X");
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory")).isNotNull();
|
||||
assertThat(TestUtils
|
||||
.getPropertyValue(gateway, "remoteFileTemplate.sessionFactory") instanceof CachingSessionFactory)
|
||||
.isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isNotNull();
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "localDirectoryExpression.literalValue"))
|
||||
.isEqualTo("local-test-dir");
|
||||
assertThat((Boolean) TestUtils.getPropertyValue(gateway, "autoCreateLocalDirectory")).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "command")).isEqualTo(Command.GET);
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isFalse();
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> options = TestUtils.getPropertyValue(gateway, "options", Set.class);
|
||||
assertTrue(options.contains(Option.PRESERVE_TIMESTAMP));
|
||||
assertThat(options.contains(Option.PRESERVE_TIMESTAMP)).isTrue();
|
||||
|
||||
//INT-3129
|
||||
assertNotNull(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression"));
|
||||
assertThat(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression")).isNotNull();
|
||||
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
|
||||
ReflectionUtils.doWithMethods(SftpOutboundGateway.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() {
|
||||
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway3,
|
||||
"handler", SftpOutboundGateway.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() {
|
||||
SftpOutboundGateway gateway = TestUtils.getPropertyValue(gateway4,
|
||||
"handler", SftpOutboundGateway.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
|
||||
@@ -163,7 +163,7 @@ public class SftpOutboundGatewayParserTests {
|
||||
SftpOutboundGateway gateway = TestUtils.getPropertyValue(advised,
|
||||
"handler", SftpOutboundGateway.class);
|
||||
gateway.handleMessage(new GenericMessage<String>("foo"));
|
||||
assertEquals(1, adviceCalled);
|
||||
assertThat(adviceCalled).isEqualTo(1);
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@@ -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.sftp.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;
|
||||
|
||||
@@ -73,31 +67,31 @@ public class SftpStreamingInboundChannelAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testFtpInboundChannelAdapterComplete() throws Exception {
|
||||
assertFalse(TestUtils.getPropertyValue(this.sftpInbound, "autoStartup", Boolean.class));
|
||||
assertEquals("sftpInbound", this.sftpInbound.getComponentName());
|
||||
assertEquals("sftp:inbound-streaming-channel-adapter", this.sftpInbound.getComponentType());
|
||||
assertSame(this.sftpChannel, TestUtils.getPropertyValue(this.sftpInbound, "outputChannel"));
|
||||
assertThat(TestUtils.getPropertyValue(this.sftpInbound, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(this.sftpInbound.getComponentName()).isEqualTo("sftpInbound");
|
||||
assertThat(this.sftpInbound.getComponentType()).isEqualTo("sftp:inbound-streaming-channel-adapter");
|
||||
assertThat(TestUtils.getPropertyValue(this.sftpInbound, "outputChannel")).isSameAs(this.sftpChannel);
|
||||
SftpStreamingMessageSource source = TestUtils.getPropertyValue(sftpInbound, "source",
|
||||
SftpStreamingMessageSource.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(SftpSimplePatternFileListFilter.class));
|
||||
assertThat(filtersIterator.next(), instanceOf(SftpPersistentAcceptOnceFileListFilter.class));
|
||||
assertThat(filtersIterator.next()).isInstanceOf(SftpSimplePatternFileListFilter.class);
|
||||
assertThat(filtersIterator.next()).isInstanceOf(SftpPersistentAcceptOnceFileListFilter.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);
|
||||
|
||||
source = TestUtils.getPropertyValue(this.contextLoadsWithNoComparator, "source",
|
||||
SftpStreamingMessageSource.class);
|
||||
assertThat(TestUtils.getPropertyValue(source, "filter"), instanceOf(ExpressionFileListFilter.class));
|
||||
assertThat(TestUtils.getPropertyValue(source, "filter")).isInstanceOf(ExpressionFileListFilter.class);
|
||||
}
|
||||
|
||||
public static class TestSessionFactoryBean implements FactoryBean<DefaultSftpSessionFactory> {
|
||||
|
||||
@@ -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,20 +16,13 @@
|
||||
|
||||
package org.springframework.integration.sftp.dsl;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
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.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -87,18 +80,18 @@ public class SftpTests extends SftpTestSupport {
|
||||
.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(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
|
||||
assertThat(file.getAbsolutePath(), containsString("localTarget"));
|
||||
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.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(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
|
||||
assertThat(file.getAbsolutePath(), containsString("localTarget"));
|
||||
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a");
|
||||
assertThat(file.getAbsolutePath()).contains("localTarget");
|
||||
|
||||
registration.destroy();
|
||||
}
|
||||
@@ -115,16 +108,16 @@ public class SftpTests extends SftpTestSupport {
|
||||
.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(" sftpSource1.txt", "sftpSource2.txt"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isInstanceOf(InputStream.class);
|
||||
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
((InputStream) message.getPayload()).close();
|
||||
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(" sftpSource1.txt", "sftpSource2.txt"));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isInstanceOf(InputStream.class);
|
||||
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
((InputStream) message.getPayload()).close();
|
||||
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
|
||||
|
||||
@@ -146,8 +139,8 @@ public class SftpTests extends SftpTestSupport {
|
||||
RemoteFileTemplate<ChannelSftp.LsEntry> template = new RemoteFileTemplate<>(sessionFactory());
|
||||
ChannelSftp.LsEntry[] files = template.execute(session ->
|
||||
session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
|
||||
assertEquals(1, files.length);
|
||||
assertEquals(3, files[0].getAttrs().getSize());
|
||||
assertThat(files.length).isEqualTo(1);
|
||||
assertThat(files[0].getAttrs().getSize()).isEqualTo(3);
|
||||
|
||||
registration.destroy();
|
||||
}
|
||||
@@ -168,17 +161,16 @@ public class SftpTests extends SftpTestSupport {
|
||||
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
|
||||
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 sftpSource2.txt
|
||||
assertEquals(2, localFiles.size());
|
||||
assertThat(localFiles.size()).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 + "subSftpSource"));
|
||||
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
|
||||
.contains(dir + "subSftpSource");
|
||||
|
||||
registration.destroy();
|
||||
}
|
||||
@@ -192,11 +184,11 @@ public class SftpTests extends SftpTestSupport {
|
||||
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
|
||||
registration.getInputChannel().send(new GenericMessage<>("sftpSource"));
|
||||
Message<?> receive = out.receive(10_000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
Object payload = receive.getPayload();
|
||||
assertThat(payload, instanceOf(ChannelSftp.LsEntry[].class));
|
||||
assertThat(payload).isInstanceOf(ChannelSftp.LsEntry[].class);
|
||||
|
||||
assertTrue(((ChannelSftp.LsEntry[]) payload).length > 0);
|
||||
assertThat(((ChannelSftp.LsEntry[]) payload).length > 0).isTrue();
|
||||
|
||||
registration.destroy();
|
||||
}
|
||||
|
||||
@@ -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.sftp.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;
|
||||
@@ -54,16 +52,16 @@ public class SftpFileListFilterTests extends SftpTestSupport {
|
||||
SftpSystemMarkerFilePresentFileListFilter filter = new SftpSystemMarkerFilePresentFileListFilter(
|
||||
new SftpSimplePatternFileListFilter("*.txt"));
|
||||
LsEntry[] files = template.list("sftpSource");
|
||||
assertThat(files.length, greaterThan(0));
|
||||
assertThat(files.length).isGreaterThan(0);
|
||||
List<LsEntry> filtered = filter.filterFiles(files);
|
||||
assertThat(filtered.size(), equalTo(0));
|
||||
assertThat(filtered.size()).isEqualTo(0);
|
||||
File remoteDir = getSourceRemoteDirectory();
|
||||
File marker = new File(remoteDir, "sftpSource2.txt.complete");
|
||||
marker.createNewFile();
|
||||
files = template.list("sftpSource");
|
||||
filtered = filter.filterFiles(files);
|
||||
assertThat(filtered.size(), equalTo(1));
|
||||
assertThat(filtered.get(0).getFilename(), equalTo("sftpSource2.txt"));
|
||||
assertThat(filtered.size()).isEqualTo(1);
|
||||
assertThat(filtered.get(0).getFilename()).isEqualTo("sftpSource2.txt");
|
||||
marker.delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 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.sftp.filters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -54,16 +53,16 @@ public class SftpPersistentAcceptOnceFileListFilterTests {
|
||||
LsEntry ftpFile3 = ctor.newInstance(channel, "baz", "baz", attrs);
|
||||
LsEntry[] files = new LsEntry[] {sftpFile1, sftpFile2, ftpFile3};
|
||||
List<LsEntry> passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
List<LsEntry> 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).getFilename());
|
||||
assertEquals("baz", now.get(1).getFilename());
|
||||
assertThat(now.size()).isEqualTo(2);
|
||||
assertThat(now.get(0).getFilename()).isEqualTo("bar");
|
||||
assertThat(now.get(1).getFilename()).isEqualTo("baz");
|
||||
now = filter.filterFiles(files);
|
||||
assertEquals(0, now.size());
|
||||
assertThat(now.size()).isEqualTo(0);
|
||||
filter.close();
|
||||
}
|
||||
|
||||
@@ -80,9 +79,9 @@ public class SftpPersistentAcceptOnceFileListFilterTests {
|
||||
LsEntry sftpFile2 = ctor.newInstance(channel, "bar", "same", attrs);
|
||||
LsEntry[] files = new LsEntry[] {sftpFile1, sftpFile2};
|
||||
List<LsEntry> now = filter.filterFiles(files);
|
||||
assertEquals(2, now.size());
|
||||
assertEquals("foo", now.get(0).getFilename());
|
||||
assertEquals("bar", now.get(1).getFilename());
|
||||
assertThat(now.size()).isEqualTo(2);
|
||||
assertThat(now.get(0).getFilename()).isEqualTo("foo");
|
||||
assertThat(now.get(1).getFilename()).isEqualTo("bar");
|
||||
filter.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-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.sftp.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -61,8 +60,8 @@ public class RollbackLocalFilterTests extends SftpTestSupport {
|
||||
|
||||
@Test
|
||||
public void testRollback() throws Exception {
|
||||
assertTrue(this.crash.getLatch().await(10, TimeUnit.SECONDS));
|
||||
assertEquals("sftpSource2.txt", this.crash.getFile().getName());
|
||||
assertThat(this.crash.getLatch().await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(this.crash.getFile().getName()).isEqualTo("sftpSource2.txt");
|
||||
}
|
||||
|
||||
public static class Crash {
|
||||
|
||||
@@ -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,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.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;
|
||||
@@ -36,7 +31,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -86,7 +80,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
@Test
|
||||
public void testCopyFileToLocalDir() throws Exception {
|
||||
File localDirectory = new File("test");
|
||||
assertFalse(localDirectory.exists());
|
||||
assertThat(localDirectory.exists()).isFalse();
|
||||
|
||||
TestSftpSessionFactory ftpSessionFactory = new TestSftpSessionFactory();
|
||||
ftpSessionFactory.setUser("kermit");
|
||||
@@ -124,25 +118,25 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
ms.start();
|
||||
|
||||
Message<File> atestFile = ms.receive();
|
||||
assertNotNull(atestFile);
|
||||
assertEquals("a.test", atestFile.getPayload().getName());
|
||||
assertThat(atestFile).isNotNull();
|
||||
assertThat(atestFile.getPayload().getName()).isEqualTo("a.test");
|
||||
// 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> btestFile = ms.receive();
|
||||
assertNotNull(btestFile);
|
||||
assertEquals("b.test", btestFile.getPayload().getName());
|
||||
assertThat(btestFile).isNotNull();
|
||||
assertThat(btestFile.getPayload().getName()).isEqualTo("b.test");
|
||||
// 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/a.test").exists());
|
||||
assertTrue(new File("test/b.test").exists());
|
||||
assertThat(new File("test/a.test").exists()).isTrue();
|
||||
assertThat(new File("test/b.test").exists()).isTrue();
|
||||
|
||||
TestUtils.getPropertyValue(localAcceptOnceFilter, "seenSet", Collection.class).clear();
|
||||
|
||||
@@ -150,7 +144,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
new File("test/b.test").delete();
|
||||
// the remote filter should prevent a re-fetch
|
||||
nothing = ms.receive();
|
||||
assertNull(nothing);
|
||||
assertThat(nothing).isNull();
|
||||
|
||||
ms.stop();
|
||||
verify(synchronizer).close();
|
||||
|
||||
@@ -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,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.inbound;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
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;
|
||||
@@ -35,6 +32,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem bilan
|
||||
*
|
||||
* @since 5.0.7
|
||||
*
|
||||
*/
|
||||
@@ -49,9 +48,9 @@ public class SftpMessageSourceTests extends SftpTestSupport {
|
||||
public void testMaxFetch() throws Exception {
|
||||
SftpInboundFileSynchronizingMessageSource messageSource = buildSource();
|
||||
Message<?> received = messageSource.receive();
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get(FileHeaders.FILENAME),
|
||||
anyOf(equalTo(" sftpSource1.txt"), equalTo("sftpSource2.txt")));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.FILENAME))
|
||||
.isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
}
|
||||
|
||||
private SftpInboundFileSynchronizingMessageSource buildSource() throws Exception {
|
||||
|
||||
@@ -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,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.inbound;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
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 java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
@@ -86,35 +81,35 @@ public class SftpStreamingMessageSourceTests extends SftpTestSupport {
|
||||
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\":\"sftpSource"));
|
||||
assertThat(fileInfo, containsString("permissions\":"));
|
||||
assertThat(fileInfo, containsString("size\":7"));
|
||||
assertThat(fileInfo, containsString("directory\":false"));
|
||||
assertThat(fileInfo, containsString("filename\":\" sftpSource1.txt"));
|
||||
assertThat(fileInfo, containsString("modified\":"));
|
||||
assertThat(fileInfo, containsString("link\":false"));
|
||||
assertThat(fileInfo).contains("remoteDirectory\":\"sftpSource");
|
||||
assertThat(fileInfo).contains("permissions\":");
|
||||
assertThat(fileInfo).contains("size\":7");
|
||||
assertThat(fileInfo).contains("directory\":false");
|
||||
assertThat(fileInfo).contains("filename\":\" sftpSource1.txt");
|
||||
assertThat(fileInfo).contains("modified\":");
|
||||
assertThat(fileInfo).contains("link\":false");
|
||||
received = (Message<byte[]>) this.data.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
fileInfo = (String) received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO);
|
||||
assertThat(fileInfo, containsString("remoteDirectory\":\"sftpSource"));
|
||||
assertThat(fileInfo, containsString("permissions\":"));
|
||||
assertThat(fileInfo, containsString("size\":7"));
|
||||
assertThat(fileInfo, containsString("directory\":false"));
|
||||
assertThat(fileInfo, containsString("filename\":\"sftpSource2.txt"));
|
||||
assertThat(fileInfo, containsString("modified\":"));
|
||||
assertThat(fileInfo, containsString("link\":false"));
|
||||
assertThat(new String(received.getPayload()), equalTo("source2"));
|
||||
assertThat(fileInfo).contains("remoteDirectory\":\"sftpSource");
|
||||
assertThat(fileInfo).contains("permissions\":");
|
||||
assertThat(fileInfo).contains("size\":7");
|
||||
assertThat(fileInfo).contains("directory\":false");
|
||||
assertThat(fileInfo).contains("filename\":\"sftpSource2.txt");
|
||||
assertThat(fileInfo).contains("modified\":");
|
||||
assertThat(fileInfo).contains("link\":false");
|
||||
assertThat(new String(received.getPayload())).isEqualTo("source2");
|
||||
|
||||
this.adapter.stop();
|
||||
this.source.setFileInfoJson(false);
|
||||
this.data.purge(null);
|
||||
this.adapter.start();
|
||||
received = (Message<byte[]>) this.data.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO), instanceOf(SftpFileInfo.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO)).isInstanceOf(SftpFileInfo.class);
|
||||
this.adapter.stop();
|
||||
}
|
||||
|
||||
@@ -124,9 +119,9 @@ public class SftpStreamingMessageSourceTests extends SftpTestSupport {
|
||||
messageSource.setFilter(new AcceptAllFileListFilter<>());
|
||||
messageSource.afterPropertiesSet();
|
||||
Message<InputStream> received = messageSource.receive();
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE),
|
||||
anyOf(equalTo(" sftpSource1.txt"), equalTo("sftpSource2.txt")));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE))
|
||||
.isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
|
||||
received.getPayload().close();
|
||||
}
|
||||
@@ -137,9 +132,9 @@ public class SftpStreamingMessageSourceTests extends SftpTestSupport {
|
||||
messageSource.setFilter(null);
|
||||
messageSource.afterPropertiesSet();
|
||||
Message<InputStream> received = messageSource.receive();
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE),
|
||||
anyOf(equalTo(" sftpSource1.txt"), equalTo("sftpSource2.txt")));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE))
|
||||
.isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
|
||||
received.getPayload().close();
|
||||
}
|
||||
@@ -150,16 +145,17 @@ public class SftpStreamingMessageSourceTests extends SftpTestSupport {
|
||||
messageSource.setFilter(Arrays::asList);
|
||||
messageSource.afterPropertiesSet();
|
||||
Message<InputStream> received = messageSource.receive();
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE),
|
||||
anyOf(equalTo(" sftpSource1.txt"), equalTo("sftpSource2.txt")));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE))
|
||||
.isIn(" sftpSource1.txt", "sftpSource2.txt");
|
||||
|
||||
received.getPayload().close();
|
||||
}
|
||||
|
||||
private SftpStreamingMessageSource buildSource() {
|
||||
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(this.config.template(),
|
||||
Comparator.comparing(LsEntry::getFilename));
|
||||
SftpStreamingMessageSource messageSource =
|
||||
new SftpStreamingMessageSource(this.config.template(),
|
||||
Comparator.comparing(LsEntry::getFilename));
|
||||
messageSource.setRemoteDirectory("sftpSource/");
|
||||
messageSource.setMaxFetchSize(1);
|
||||
messageSource.setBeanFactory(this.context);
|
||||
|
||||
@@ -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.sftp.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.sftp.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.willAnswer;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -83,7 +80,7 @@ public class SftpOutboundTests {
|
||||
@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();
|
||||
|
||||
SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
|
||||
FileTransferringMessageHandler<LsEntry> handler = new FileTransferringMessageHandler<LsEntry>(sessionFactory);
|
||||
@@ -102,7 +99,7 @@ public class SftpOutboundTests {
|
||||
destFile.deleteOnExit();
|
||||
|
||||
handler.handleMessage(new GenericMessage<>(srcFile));
|
||||
assertTrue("destination file was not created", destFile.exists());
|
||||
assertThat(destFile.exists()).as("destination file was not created").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,9 +119,9 @@ public class SftpOutboundTests {
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.handleMessage(new GenericMessage<String>("String data"));
|
||||
assertTrue(new File("remote-target-dir", "foo.txt").exists());
|
||||
assertThat(new File("remote-target-dir", "foo.txt").exists()).isTrue();
|
||||
byte[] inFile = FileCopyUtils.copyToByteArray(file);
|
||||
assertEquals("String data", new String(inFile));
|
||||
assertThat(new String(inFile)).isEqualTo("String data");
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@@ -145,16 +142,16 @@ public class SftpOutboundTests {
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.handleMessage(new GenericMessage<byte[]>("byte[] data".getBytes()));
|
||||
assertTrue(new File("remote-target-dir", "foo.txt").exists());
|
||||
assertThat(new File("remote-target-dir", "foo.txt").exists()).isTrue();
|
||||
byte[] inFile = FileCopyUtils.copyToByteArray(file);
|
||||
assertEquals("byte[] data", new String(inFile));
|
||||
assertThat(new String(inFile)).isEqualTo("byte[] data");
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@Test //INT-2275
|
||||
public void testSftpOutboundChannelAdapterInsideChain() 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();
|
||||
@@ -168,7 +165,7 @@ public class SftpOutboundTests {
|
||||
MessageChannel channel = context.getBean("outboundChannelAdapterInsideChain", 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();
|
||||
}
|
||||
|
||||
@@ -185,13 +182,13 @@ public class SftpOutboundTests {
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -215,10 +212,10 @@ public class SftpOutboundTests {
|
||||
return null;
|
||||
}).when(session).mkdir(anyString());
|
||||
handler.handleMessage(new GenericMessage<String>("qux"));
|
||||
assertEquals(3, madeDirs.size());
|
||||
assertEquals("/foo", madeDirs.get(0));
|
||||
assertEquals("/foo/bar", madeDirs.get(1));
|
||||
assertEquals("/foo/bar/baz", madeDirs.get(2));
|
||||
assertThat(madeDirs.size()).isEqualTo(3);
|
||||
assertThat(madeDirs.get(0)).isEqualTo("/foo");
|
||||
assertThat(madeDirs.get(1)).isEqualTo("/foo/bar");
|
||||
assertThat(madeDirs.get(2)).isEqualTo("/foo/bar/baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -262,16 +259,18 @@ public class SftpOutboundTests {
|
||||
noopConnect(channel2);
|
||||
Session<LsEntry> s1 = factory.getSession();
|
||||
Session<LsEntry> s2 = factory.getSession();
|
||||
assertSame(TestUtils.getPropertyValue(s1, "jschSession"), TestUtils.getPropertyValue(s2, "jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "channel"));
|
||||
assertThat(TestUtils.getPropertyValue(s2, "jschSession"))
|
||||
.isSameAs(TestUtils.getPropertyValue(s1, "jschSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s1, "channel")).isSameAs(channel1);
|
||||
assertThat(TestUtils.getPropertyValue(s2, "channel")).isSameAs(channel2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotSharedSession() throws Exception {
|
||||
JSch jsch = spy(new JSch());
|
||||
Constructor<com.jcraft.jsch.Session> ctor =
|
||||
com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class, String.class, String.class, int.class);
|
||||
com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class, String.class, String.class,
|
||||
int.class);
|
||||
ctor.setAccessible(true);
|
||||
com.jcraft.jsch.Session jschSession1 = spy(ctor.newInstance(jsch, "foo", "host", 22));
|
||||
com.jcraft.jsch.Session jschSession2 = spy(ctor.newInstance(jsch, "foo", "host", 22));
|
||||
@@ -292,16 +291,18 @@ public class SftpOutboundTests {
|
||||
noopConnect(channel2);
|
||||
Session<LsEntry> s1 = factory.getSession();
|
||||
Session<LsEntry> s2 = factory.getSession();
|
||||
assertNotSame(TestUtils.getPropertyValue(s1, "jschSession"), TestUtils.getPropertyValue(s2, "jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "channel"));
|
||||
assertThat(TestUtils.getPropertyValue(s2, "jschSession"))
|
||||
.isNotSameAs(TestUtils.getPropertyValue(s1, "jschSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s1, "channel")).isSameAs(channel1);
|
||||
assertThat(TestUtils.getPropertyValue(s2, "channel")).isSameAs(channel2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSharedSessionCachedReset() throws Exception {
|
||||
JSch jsch = spy(new JSch());
|
||||
Constructor<com.jcraft.jsch.Session> ctor =
|
||||
com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class, String.class, String.class, int.class);
|
||||
com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class, String.class, String.class,
|
||||
int.class);
|
||||
ctor.setAccessible(true);
|
||||
com.jcraft.jsch.Session jschSession1 = spy(ctor.newInstance(jsch, "foo", "host", 22));
|
||||
com.jcraft.jsch.Session jschSession2 = spy(ctor.newInstance(jsch, "foo", "host", 22));
|
||||
@@ -346,27 +347,31 @@ public class SftpOutboundTests {
|
||||
noopConnect(channel4);
|
||||
Session<LsEntry> s1 = cachedFactory.getSession();
|
||||
Session<LsEntry> s2 = cachedFactory.getSession();
|
||||
assertSame(jschSession1, TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "targetSession.channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "targetSession.channel"));
|
||||
assertSame(TestUtils.getPropertyValue(s1, "targetSession.jschSession"), TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession.jschSession")).isSameAs(jschSession1);
|
||||
assertThat(TestUtils.getPropertyValue(s1, "targetSession.channel")).isSameAs(channel1);
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession.channel")).isSameAs(channel2);
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession.jschSession"))
|
||||
.isSameAs(TestUtils.getPropertyValue(s1, "targetSession.jschSession"));
|
||||
s1.close();
|
||||
Session<LsEntry> s3 = cachedFactory.getSession();
|
||||
assertSame(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s3, "targetSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s3, "targetSession.channel"));
|
||||
assertThat(TestUtils.getPropertyValue(s3, "targetSession"))
|
||||
.isSameAs(TestUtils.getPropertyValue(s1, "targetSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s3, "targetSession.channel")).isSameAs(channel1);
|
||||
s3.close();
|
||||
cachedFactory.resetCache();
|
||||
verify(jschSession1, never()).disconnect();
|
||||
s3 = cachedFactory.getSession();
|
||||
assertSame(jschSession2, TestUtils.getPropertyValue(s3, "targetSession.jschSession"));
|
||||
assertNotSame(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s3, "targetSession"));
|
||||
assertSame(channel3, TestUtils.getPropertyValue(s3, "targetSession.channel"));
|
||||
assertThat(TestUtils.getPropertyValue(s3, "targetSession.jschSession")).isSameAs(jschSession2);
|
||||
assertThat(TestUtils.getPropertyValue(s3, "targetSession"))
|
||||
.isNotSameAs(TestUtils.getPropertyValue(s1, "targetSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s3, "targetSession.channel")).isSameAs(channel3);
|
||||
s2.close();
|
||||
verify(jschSession1).disconnect();
|
||||
s2 = cachedFactory.getSession();
|
||||
assertSame(jschSession2, TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
assertNotSame(TestUtils.getPropertyValue(s3, "targetSession"), TestUtils.getPropertyValue(s2, "targetSession"));
|
||||
assertSame(channel4, TestUtils.getPropertyValue(s2, "targetSession.channel"));
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession.jschSession")).isSameAs(jschSession2);
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession"))
|
||||
.isNotSameAs(TestUtils.getPropertyValue(s3, "targetSession"));
|
||||
assertThat(TestUtils.getPropertyValue(s2, "targetSession.channel")).isSameAs(channel4);
|
||||
s2.close();
|
||||
s3.close();
|
||||
verify(jschSession2, never()).disconnect();
|
||||
@@ -387,21 +392,21 @@ public class SftpOutboundTests {
|
||||
|
||||
doAnswer(invocation -> {
|
||||
File file = new File((String) invocation.getArgument(1));
|
||||
assertTrue(file.getName().endsWith(".writing"));
|
||||
assertThat(file.getName()).endsWith(".writing");
|
||||
FileCopyUtils.copy((InputStream) invocation.getArgument(0), new FileOutputStream(file));
|
||||
return null;
|
||||
}).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
File file = new File((String) invocation.getArgument(0));
|
||||
assertTrue(file.getName().endsWith(".writing"));
|
||||
assertThat(file.getName()).endsWith(".writing");
|
||||
File renameToFile = new File((String) invocation.getArgument(1));
|
||||
file.renameTo(renameToFile);
|
||||
return null;
|
||||
}).when(channel).rename(Mockito.anyString(), Mockito.anyString());
|
||||
|
||||
String[] files = new File("remote-test-dir").list();
|
||||
Vector<LsEntry> sftpEntries = new Vector<LsEntry>();
|
||||
Vector<LsEntry> sftpEntries = new Vector<>();
|
||||
for (String fileName : files) {
|
||||
LsEntry lsEntry = mock(LsEntry.class);
|
||||
SftpATTRS attributes = mock(SftpATTRS.class);
|
||||
@@ -418,6 +423,7 @@ public class SftpOutboundTests {
|
||||
throw new RuntimeException("Failed to create mock sftp session", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,16 +16,8 @@
|
||||
|
||||
package org.springframework.integration.sftp.outbound;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -42,7 +34,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -139,22 +130,22 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
long modified = setModifiedOnSource1();
|
||||
this.inboundGet.send(new GenericMessage<Object>(dir + " sftpSource1.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 = "sftpSource/subSftpSource/";
|
||||
this.inboundGet.send(new GenericMessage<Object>(dir + "subSftpSource1.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());
|
||||
Session<?> session2 = this.sessionFactory.getSession();
|
||||
assertSame(TestUtils.getPropertyValue(session, "targetSession.jschSession"),
|
||||
TestUtils.getPropertyValue(session2, "targetSession.jschSession"));
|
||||
assertThat(TestUtils.getPropertyValue(session2, "targetSession.jschSession"))
|
||||
.isSameAs(TestUtils.getPropertyValue(session, "targetSession.jschSession"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,10 +156,10 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,32 +170,30 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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).hasSizeGreaterThan(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 = "sftpSource/subSftpSource/";
|
||||
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).hasSizeGreaterThan(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,21 +206,20 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
secondRemote.setLastModified(System.currentTimeMillis() - 1_000_000);
|
||||
this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*"));
|
||||
Message<?> result = this.output.receive(1000);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
List<File> localFiles = (List<File>) result.getPayload();
|
||||
assertEquals(3, localFiles.size());
|
||||
assertThat(localFiles).hasSize(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 + "subSftpSource"));
|
||||
assertThat(assertedModified).isTrue();
|
||||
assertThat(localFiles.get(2).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
|
||||
.contains(dir + "subSftpSource");
|
||||
|
||||
File secondTarget = new File(getTargetLocalDirectory() + File.separator + "sftpSource", "localTarget2.txt");
|
||||
ByteArrayOutputStream remoteContents = new ByteArrayOutputStream();
|
||||
@@ -239,7 +227,7 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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();
|
||||
@@ -248,13 +236,13 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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>(dir + "*"));
|
||||
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);
|
||||
}
|
||||
@@ -263,13 +251,13 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
File firstRemote = new File(getSourceRemoteDirectory(), " sftpSource1.txt");
|
||||
firstRemote.setLastModified(System.currentTimeMillis() - 1_000_000);
|
||||
long modified = firstRemote.lastModified();
|
||||
assertTrue(modified > 0);
|
||||
assertThat(modified).isGreaterThan(0);
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean assertPreserved(long modified, File file) {
|
||||
assertTrue("lastModified wrong by " + (modified - file.lastModified()),
|
||||
Math.abs(file.lastModified() - modified) < 1_000);
|
||||
assertThat(Math.abs(file.lastModified() - modified))
|
||||
.as("lastModified wrong by " + (modified - file.lastModified())).isLessThan(1_000);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -279,17 +267,16 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
String dir = "sftpSource/";
|
||||
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 sftpSource2.txt
|
||||
assertEquals(2, localFiles.size());
|
||||
assertThat(localFiles).hasSize(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 + "subSftpSource"));
|
||||
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"))
|
||||
.contains(dir + "subSftpSource");
|
||||
|
||||
}
|
||||
|
||||
@@ -301,13 +288,13 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
Session<?> session = this.sessionFactory.getSession();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
FileCopyUtils.copy(session.readRaw("sftpSource/ sftpSource1.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("sftpSource/sftpSource2.txt"), baos);
|
||||
assertTrue(session.finalizeRaw());
|
||||
assertEquals("source2", new String(baos.toByteArray()));
|
||||
assertThat(session.finalizeRaw()).isTrue();
|
||||
assertThat(new String(baos.toByteArray())).isEqualTo("source2");
|
||||
|
||||
session.close();
|
||||
}
|
||||
@@ -349,14 +336,14 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
out2.write('f');
|
||||
out1.close();
|
||||
out2.close();
|
||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
||||
assertTrue(latch2.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
|
||||
session1.read("foo.txt", bos1);
|
||||
session2.read("bar.txt", bos2);
|
||||
assertEquals("ace", new String(bos1.toByteArray()));
|
||||
assertEquals("bdf", new String(bos2.toByteArray()));
|
||||
assertThat(new String(bos1.toByteArray())).isEqualTo("ace");
|
||||
assertThat(new String(bos2.toByteArray())).isEqualTo("bdf");
|
||||
session1.remove("foo.txt");
|
||||
session2.remove("bar.txt");
|
||||
session1.close();
|
||||
@@ -379,16 +366,13 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt")));
|
||||
assertThat(
|
||||
out.getPayload().get(1),
|
||||
anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.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("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt");
|
||||
assertThat(out.getPayload().get(1))
|
||||
.isIn("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt");
|
||||
verify(channel).chmod(384, "sftpTarget/localSource1.txt"); // 384 = 600 octal
|
||||
verify(channel).chmod(384, "sftpTarget/localSource2.txt");
|
||||
}
|
||||
@@ -403,22 +387,18 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"),
|
||||
equalTo("sftpTarget/subLocalSource/subLocalSource1.txt")));
|
||||
assertThat(
|
||||
out.getPayload().get(1),
|
||||
anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"),
|
||||
equalTo("sftpTarget/subLocalSource/subLocalSource1.txt")));
|
||||
assertThat(
|
||||
out.getPayload().get(2),
|
||||
anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"),
|
||||
equalTo("sftpTarget/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("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt",
|
||||
"sftpTarget/subLocalSource/subLocalSource1.txt");
|
||||
assertThat(out.getPayload().get(1))
|
||||
.isIn("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt",
|
||||
"sftpTarget/subLocalSource/subLocalSource1.txt");
|
||||
assertThat(out.getPayload().get(2))
|
||||
.isIn("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt",
|
||||
"sftpTarget/subLocalSource/subLocalSource1.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,18 +411,15 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"),
|
||||
equalTo("sftpTarget/subLocalSource/subLocalSource1.txt")));
|
||||
assertThat(
|
||||
out.getPayload().get(1),
|
||||
anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"),
|
||||
equalTo("sftpTarget/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("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt",
|
||||
"sftpTarget/subLocalSource/subLocalSource1.txt");
|
||||
assertThat(out.getPayload().get(1))
|
||||
.isIn("sftpTarget/localSource1.txt", "sftpTarget/localSource2.txt",
|
||||
"sftpTarget/subLocalSource/subLocalSource1.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,7 +440,7 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -474,12 +451,13 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
session.close();
|
||||
|
||||
String dir = "sftpSource/";
|
||||
this.inboundGetStream.send(new GenericMessage<Object>(dir + " sftpSource1.txt"));
|
||||
this.inboundGetStream.send(new GenericMessage<>(dir + " sftpSource1.txt"));
|
||||
Message<?> result = this.output.receive(1000);
|
||||
assertNotNull(result);
|
||||
assertEquals("source1", result.getPayload());
|
||||
assertEquals("sftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals(" sftpSource1.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isEqualTo("source1");
|
||||
assertThat(result.getHeaders())
|
||||
.containsEntry(FileHeaders.REMOTE_DIRECTORY, "sftpSource/")
|
||||
.containsEntry(FileHeaders.REMOTE_FILE, " sftpSource1.txt");
|
||||
verify(session).close();
|
||||
}
|
||||
|
||||
@@ -487,14 +465,14 @@ public class SftpServerOutboundTests extends SftpTestSupport {
|
||||
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");
|
||||
}
|
||||
|
||||
private void assertLength6(SftpRemoteFileTemplate template) {
|
||||
LsEntry[] files = template.execute(session -> session.list("sftpTarget/appending.txt"));
|
||||
assertEquals(1, files.length);
|
||||
assertEquals(6, files[0].getAttrs().getSize());
|
||||
assertThat(files.length).isEqualTo(1);
|
||||
assertThat(files[0].getAttrs().getSize()).isEqualTo(6);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -94,9 +92,9 @@ public class ProxyTests {
|
||||
}
|
||||
|
||||
private void assertProxy(Proxy proxy, Class<? extends Proxy> clazz) {
|
||||
assertThat(proxy, instanceOf(clazz));
|
||||
assertEquals("ftptest", TestUtils.getPropertyValue(proxy, "user"));
|
||||
assertEquals("pass", TestUtils.getPropertyValue(proxy, "passwd"));
|
||||
assertThat(proxy).isInstanceOf(clazz);
|
||||
assertThat(TestUtils.getPropertyValue(proxy, "user")).isEqualTo("ftptest");
|
||||
assertThat(TestUtils.getPropertyValue(proxy, "passwd")).isEqualTo("pass");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 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,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -76,11 +72,11 @@ public class SftpRemoteFileTemplateTests extends SftpTestSupport {
|
||||
});
|
||||
template.append(new GenericMessage<String>("foo"));
|
||||
template.append(new GenericMessage<String>("bar"));
|
||||
assertTrue(template.exists("foo/foobar.txt"));
|
||||
assertThat(template.exists("foo/foobar.txt")).isTrue();
|
||||
template.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> {
|
||||
try {
|
||||
SftpATTRS file = client.lstat("foo/foobar.txt");
|
||||
assertEquals(6, file.getSize());
|
||||
assertThat(file.getSize()).isEqualTo(6);
|
||||
}
|
||||
catch (SftpException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -88,17 +84,16 @@ public class SftpRemoteFileTemplateTests extends SftpTestSupport {
|
||||
});
|
||||
template.execute((SessionCallbackWithoutResult<LsEntry>) session -> {
|
||||
LsEntry[] files = session.list("foo/");
|
||||
assertEquals(4, files.length);
|
||||
assertTrue(session.remove("foo/foobar.txt"));
|
||||
assertTrue(session.rmdir("foo/bar/"));
|
||||
assertThat(files.length).isEqualTo(4);
|
||||
assertThat(session.remove("foo/foobar.txt")).isTrue();
|
||||
assertThat(session.rmdir("foo/bar/")).isTrue();
|
||||
files = session.list("foo/");
|
||||
assertEquals(2, files.length);
|
||||
assertThat(files.length).isEqualTo(2);
|
||||
List<LsEntry> list = Arrays.asList(files);
|
||||
assertThat(list.stream().map(l -> l.getFilename()).collect(Collectors.toList()),
|
||||
containsInAnyOrder(".", ".."));
|
||||
assertTrue(session.rmdir("foo/"));
|
||||
assertThat(list.stream().map(l -> l.getFilename()).collect(Collectors.toList())).contains(".", "..");
|
||||
assertThat(session.rmdir("foo/")).isTrue();
|
||||
});
|
||||
assertFalse(template.exists("foo"));
|
||||
assertThat(template.exists("foo")).isFalse();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -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,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -156,17 +156,17 @@ public class SftpServerTests {
|
||||
}
|
||||
|
||||
protected void doTest(SshServer server, Session<LsEntry> session) throws IOException {
|
||||
assertEquals(1, server.getActiveSessions().size());
|
||||
assertThat(server.getActiveSessions().size()).isEqualTo(1);
|
||||
LsEntry[] list = session.list(".");
|
||||
if (list.length > 0) {
|
||||
session.remove("*");
|
||||
}
|
||||
session.write(new ByteArrayInputStream("foo".getBytes()), "bar");
|
||||
list = session.list(".");
|
||||
assertEquals("bar", list[1].getFilename());
|
||||
assertThat(list[1].getFilename()).isEqualTo("bar");
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
session.read("bar", outputStream);
|
||||
assertEquals("foo", new String(outputStream.toByteArray()));
|
||||
assertThat(new String(outputStream.toByteArray())).isEqualTo("foo");
|
||||
session.remove("bar");
|
||||
session.close();
|
||||
}
|
||||
|
||||
@@ -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,8 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
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 static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -82,16 +76,16 @@ public class SftpSessionFactoryTests {
|
||||
if (e.getCause() instanceof IllegalStateException) {
|
||||
if (e.getCause().getCause() instanceof JSchException) {
|
||||
if (e.getCause().getCause().getCause() instanceof ConnectException) {
|
||||
assertTrue("Server failed to start in 10 seconds", n++ < 100);
|
||||
assertThat(n++ < 100).as("Server failed to start in 10 seconds").isTrue();
|
||||
Thread.sleep(100);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getCause().getMessage(), equalTo("failed to connect"));
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("failed to connect");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +95,7 @@ public class SftpSessionFactoryTests {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertEquals(0, server.getActiveSessions().size());
|
||||
assertThat(server.getActiveSessions().size()).isEqualTo(0);
|
||||
}
|
||||
finally {
|
||||
server.stop(true);
|
||||
@@ -118,16 +112,16 @@ public class SftpSessionFactoryTests {
|
||||
when(ui.getPassphrase()).thenReturn("pp").thenReturn(null);
|
||||
f.setUserInfo(ui);
|
||||
UserInfo userInfo = TestUtils.getPropertyValue(f, "userInfoWrapper", UserInfo.class);
|
||||
assertEquals("pass", userInfo.getPassword());
|
||||
assertThat(userInfo.getPassword()).isEqualTo("pass");
|
||||
f.setPassword("foo");
|
||||
try {
|
||||
userInfo.getPassword();
|
||||
fail("expected Exception");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertThat(e.getMessage(), startsWith("When a 'UserInfo' is provided, 'password' is not allowed"));
|
||||
assertThat(e.getMessage()).startsWith("When a 'UserInfo' is provided, 'password' is not allowed");
|
||||
}
|
||||
assertEquals("pp", userInfo.getPassphrase());
|
||||
assertThat(userInfo.getPassphrase()).isEqualTo("pp");
|
||||
f.setPrivateKeyPassphrase("bar");
|
||||
try {
|
||||
userInfo.getPassphrase();
|
||||
@@ -135,11 +129,11 @@ public class SftpSessionFactoryTests {
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertThat(e
|
||||
.getMessage(), startsWith("When a 'UserInfo' is provided, 'privateKeyPassphrase' is not allowed"));
|
||||
.getMessage()).startsWith("When a 'UserInfo' is provided, 'privateKeyPassphrase' is not allowed");
|
||||
}
|
||||
f.setUserInfo(null);
|
||||
assertEquals("foo", userInfo.getPassword());
|
||||
assertEquals("bar", userInfo.getPassphrase());
|
||||
assertThat(userInfo.getPassword()).isEqualTo("foo");
|
||||
assertThat(userInfo.getPassphrase()).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,10 +182,10 @@ public class SftpSessionFactoryTests {
|
||||
fail("Expected Exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getCause().getCause(), instanceOf(JSchException.class));
|
||||
assertThat(e.getCause().getCause().getMessage(), containsString("reject HostKey"));
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause().getCause()).isInstanceOf(JSchException.class);
|
||||
assertThat(e.getCause().getCause().getMessage()).contains("reject HostKey");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user