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-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -67,7 +67,7 @@ public class AutoCreateDirectoryTests {
|
||||
source.setBeanFactory(mock(BeanFactory.class));
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
assertTrue(new File(INBOUND_PATH).exists());
|
||||
assertThat(new File(INBOUND_PATH).exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -86,7 +86,7 @@ public class AutoCreateDirectoryTests {
|
||||
new File(OUTBOUND_PATH));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
assertTrue(new File(OUTBOUND_PATH).exists());
|
||||
assertThat(new File(OUTBOUND_PATH).exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
@@ -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.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -39,7 +39,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
generator.setBeanFactory(mock(BeanFactory.class));
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader(FileHeaders.FILENAME, "foo").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo", filename);
|
||||
assertThat(filename).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,7 +48,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
generator.setBeanFactory(mock(BeanFactory.class));
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals(message.getHeaders().getId() + ".msg", filename);
|
||||
assertThat(filename).isEqualTo(message.getHeaders().getId() + ".msg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader(FileHeaders.FILENAME, new Integer(123))
|
||||
.build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals(message.getHeaders().getId() + ".msg", filename);
|
||||
assertThat(filename).isEqualTo(message.getHeaders().getId() + ".msg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
generator.setHeaderName("foo");
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader("foo", "bar").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("bar", filename);
|
||||
assertThat(filename).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +78,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
generator.setHeaderName("foo");
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals(message.getHeaders().getId() + ".msg", filename);
|
||||
assertThat(filename).isEqualTo(message.getHeaders().getId() + ".msg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +88,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
generator.setHeaderName("foo");
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader("foo", new Integer(123)).build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals(message.getHeaders().getId() + ".msg", filename);
|
||||
assertThat(filename).isEqualTo(message.getHeaders().getId() + ".msg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,7 +98,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
File payload = new File("/some/path/foo");
|
||||
Message<?> message = MessageBuilder.withPayload(payload).build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo", filename);
|
||||
assertThat(filename).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +108,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
File payload = new File("/some/path/ignore");
|
||||
Message<?> message = MessageBuilder.withPayload(payload).setHeader(FileHeaders.FILENAME, "foo").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo", filename);
|
||||
assertThat(filename).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,7 +119,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
File payload = new File("/some/path/ignore");
|
||||
Message<?> message = MessageBuilder.withPayload(payload).setHeader("foo", "bar").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("bar", filename);
|
||||
assertThat(filename).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +130,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
File payload = new File("/some/path/ignore");
|
||||
Message<?> message = MessageBuilder.withPayload(payload).build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foobar", filename);
|
||||
assertThat(filename).isEqualTo("foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,7 +141,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
Message<?> message = MessageBuilder.withPayload("test").setHeader(FileHeaders.FILENAME, "ignore")
|
||||
.setHeader("foo", "bar").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("bar", filename);
|
||||
assertThat(filename).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +153,7 @@ public class DefaultFileNameGeneratorTests {
|
||||
Message<?> message = MessageBuilder.withPayload(payload).setHeader(FileHeaders.FILENAME, "ignore2")
|
||||
.setHeader("foo", "bar").build();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("bar", filename);
|
||||
assertThat(filename).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.file;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
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 static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -90,7 +85,7 @@ public class FileInboundTransactionTests {
|
||||
public void testNoTx() throws Exception {
|
||||
|
||||
Object scanner = TestUtils.getPropertyValue(pseudoTx.getMessageSource(), "scanner");
|
||||
assertThat(scanner.getClass().getName(), containsString("FileReadingMessageSource$WatchServiceDirectoryScanner"));
|
||||
assertThat(scanner.getClass().getName()).contains("FileReadingMessageSource$WatchServiceDirectoryScanner");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ResettableFileListFilter<File> fileListFilter =
|
||||
@@ -110,19 +105,19 @@ public class FileInboundTransactionTests {
|
||||
File file = new File(tmpDir.getRoot(), "si-test1/foo");
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(60000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertFalse(file.delete());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(file.delete()).isFalse();
|
||||
crash.set(true);
|
||||
file = new File(tmpDir.getRoot(), "si-test1/bar");
|
||||
file.createNewFile();
|
||||
result = failureChannel.receive(60000);
|
||||
assertNotNull(result);
|
||||
assertTrue(file.delete());
|
||||
assertEquals("foo", result.getPayload());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(file.delete()).isTrue();
|
||||
assertThat(result.getPayload()).isEqualTo("foo");
|
||||
pseudoTx.stop();
|
||||
assertFalse(transactionManager.getCommitted());
|
||||
assertFalse(transactionManager.getRolledBack());
|
||||
assertThat(transactionManager.getCommitted()).isFalse();
|
||||
assertThat(transactionManager.getRolledBack()).isFalse();
|
||||
|
||||
verify(fileListFilter).remove(new File(tmpDir.getRoot(), "si-test1/foo"));
|
||||
}
|
||||
@@ -141,19 +136,19 @@ public class FileInboundTransactionTests {
|
||||
File file = new File(tmpDir.getRoot(), "si-test2/baz");
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(60000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertTrue(file.delete());
|
||||
assertTrue(transactionManager.getCommitted());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(file.delete()).isTrue();
|
||||
assertThat(transactionManager.getCommitted()).isTrue();
|
||||
crash.set(true);
|
||||
file = new File(tmpDir.getRoot(), "si-test2/qux");
|
||||
file.createNewFile();
|
||||
result = failureChannel.receive(60000);
|
||||
assertNotNull(result);
|
||||
assertTrue(file.delete());
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(file.delete()).isTrue();
|
||||
assertThat(result.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
realTx.stop();
|
||||
assertTrue(transactionManager.getRolledBack());
|
||||
assertThat(transactionManager.getRolledBack()).isTrue();
|
||||
}
|
||||
|
||||
public static class DummyTxManager extends AbstractPlatformTransactionManager {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
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.io.IOException;
|
||||
@@ -86,9 +85,9 @@ public class FileOutboundChannelAdapterInsideChainTests {
|
||||
Message<String> message = MessageBuilder.withPayload(SAMPLE_CONTENT).build();
|
||||
outboundChainChannel.send(message);
|
||||
File testFile = new File(workDir, TEST_FILE_NAME);
|
||||
assertTrue(testFile.exists());
|
||||
assertThat(testFile.exists()).isTrue();
|
||||
byte[] testFileContent = FileCopyUtils.copyToByteArray(testFile);
|
||||
assertEquals(new String(testFileContent), SAMPLE_CONTENT);
|
||||
assertThat(SAMPLE_CONTENT).isEqualTo(new String(testFileContent));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,11 +16,13 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -94,22 +96,22 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
public void saveToBaseDir() throws Exception {
|
||||
this.inputChannelSaveToBaseDir.send(message);
|
||||
|
||||
Assert.assertTrue(new File("target/base-directory/foo.txt").exists());
|
||||
assertThat(new File("target/base-directory/foo.txt").exists()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveToBaseDirDeleteSourceFile() throws Exception {
|
||||
Assert.assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
this.inputChannelSaveToBaseDirDeleteSource.send(message);
|
||||
Assert.assertTrue(new File("target/base-directory/foo.txt").exists());
|
||||
Assert.assertFalse(sourceFile.exists());
|
||||
assertThat(new File("target/base-directory/foo.txt").exists()).isTrue();
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveToSubDir() throws Exception {
|
||||
this.inputChannelSaveToSubDir.send(message);
|
||||
Assert.assertTrue(new File("target/base-directory/sub-directory/foo.txt").exists());
|
||||
assertThat(new File("target/base-directory/sub-directory/foo.txt").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,13 +121,13 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
this.inputChannelSaveToSubDirWrongExpression.send(message);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
Assert.assertEquals(
|
||||
TestUtils.applySystemFileSeparator("Destination path [target/base-directory/sub-directory/foo.txt] does not point to a directory."),
|
||||
e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage()).isEqualTo(TestUtils
|
||||
.applySystemFileSeparator("Destination path [target/base-directory/sub-directory/foo.txt] does not" +
|
||||
" point to a directory."));
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting a MessageHandlingException to be thrown");
|
||||
fail("Was expecting a MessageHandlingException to be thrown");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,12 +137,12 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
this.inputChannelSaveToSubDirEmptyStringExpression.send(message);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
Assert.assertEquals("Unable to resolve Destination Directory for the provided Expression '' ''.",
|
||||
e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage())
|
||||
.isEqualTo("Unable to resolve Destination Directory for the provided Expression '' ''.");
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting a MessageHandlingException to be thrown");
|
||||
fail("Was expecting a MessageHandlingException to be thrown");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,7 +153,7 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
.build();
|
||||
|
||||
this.inputChannelSaveToSubDirWithHeader.send(message2);
|
||||
Assert.assertTrue(new File("target/base-directory/headerdir/foo.txt").exists());
|
||||
assertThat(new File("target/base-directory/headerdir/foo.txt").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,13 +163,13 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
this.inputChannelSaveToSubDirAutoCreateOff.send(message);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
Assert.assertEquals(
|
||||
TestUtils.applySystemFileSeparator("Destination directory [target/base-directory2/sub-directory2] does not exist."),
|
||||
e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage()).isEqualTo(TestUtils
|
||||
.applySystemFileSeparator("Destination directory [target/base-directory2/sub-directory2] does not " +
|
||||
"exist."));
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting a MessageHandlingException to be thrown");
|
||||
fail("Was expecting a MessageHandlingException to be thrown");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +180,7 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
.setHeader("subDirectory", directory)
|
||||
.build();
|
||||
this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
|
||||
Assert.assertTrue(new File("target/base-directory/sub-directory/foo.txt").exists());
|
||||
assertThat(new File("target/base-directory/sub-directory/foo.txt").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,14 +195,13 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
Assert.assertEquals("The provided Destination Directory expression " +
|
||||
"(headers['subDirectory']) must not evaluate to null.",
|
||||
e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("The provided Destination Directory expression " +
|
||||
"(headers['subDirectory']) must not evaluate to null.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting a MessageHandlingException to be thrown");
|
||||
fail("Was expecting a MessageHandlingException to be thrown");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,15 +216,14 @@ public class FileOutboundChannelAdapterIntegrationTests {
|
||||
this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
Assert.assertEquals("The provided Destination Directory expression" +
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("The provided Destination Directory expression" +
|
||||
" (headers['subDirectory']) must evaluate to type " +
|
||||
"java.io.File or String, not java.lang.Integer.",
|
||||
e.getCause().getMessage());
|
||||
"java.io.File or String, not java.lang.Integer.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting a MessageHandlingException to be thrown");
|
||||
fail("Was expecting a MessageHandlingException to be thrown");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
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.FileOutputStream;
|
||||
@@ -74,7 +70,7 @@ public class FileOutboundGatewayIntegrationTests {
|
||||
|
||||
static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\n????????";
|
||||
|
||||
Message<File> message;
|
||||
|
||||
@@ -115,55 +111,54 @@ public class FileOutboundGatewayIntegrationTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void instancesCreated() throws Exception {
|
||||
assertThat(beanFactory.getBean("copier"), is(notNullValue()));
|
||||
assertThat(beanFactory.getBean("mover"), is(notNullValue()));
|
||||
public void instancesCreated() {
|
||||
assertThat(beanFactory.getBean("copier")).isNotNull();
|
||||
assertThat(beanFactory.getBean("mover")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copy() throws Exception {
|
||||
public void copy() {
|
||||
copyInputChannel.send(message);
|
||||
List<Message<?>> result = outputChannel.clear();
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
Message<?> resultMessage = result.get(0);
|
||||
File payloadFile = (File) resultMessage.getPayload();
|
||||
assertThat(payloadFile, is(not(sourceFile)));
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class),
|
||||
is(sourceFile));
|
||||
assertThat(sourceFile.exists(), is(true));
|
||||
assertThat(payloadFile.exists(), is(true));
|
||||
assertThat(payloadFile).isNotEqualTo(sourceFile);
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class)).isEqualTo(sourceFile);
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
assertThat(payloadFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void move() throws Exception {
|
||||
public void move() {
|
||||
moveInputChannel.send(message);
|
||||
List<Message<?>> result = outputChannel.clear();
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
Message<?> resultMessage = result.get(0);
|
||||
File payloadFile = (File) resultMessage.getPayload();
|
||||
assertThat(payloadFile, is(not(sourceFile)));
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class),
|
||||
is(sourceFile));
|
||||
assertThat(sourceFile.exists(), is(false));
|
||||
assertThat(payloadFile.exists(), is(true));
|
||||
assertThat(payloadFile).isNotEqualTo(sourceFile);
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class)).isEqualTo(sourceFile);
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
assertThat(payloadFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test //INT-1029
|
||||
public void moveInsideTheChain() throws Exception {
|
||||
public void moveInsideTheChain() {
|
||||
// INT-2755
|
||||
Object bean = this.beanFactory.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child.file-outbound-gateway-within-chain.handler");
|
||||
assertTrue(bean instanceof FileWritingMessageHandler);
|
||||
Object bean = this.beanFactory
|
||||
.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child" +
|
||||
".file-outbound-gateway-within-chain.handler");
|
||||
assertThat(bean instanceof FileWritingMessageHandler).isTrue();
|
||||
|
||||
fileOutboundGatewayInsideChain.send(message);
|
||||
List<Message<?>> result = outputChannel.clear();
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
Message<?> resultMessage = result.get(0);
|
||||
File payloadFile = (File) resultMessage.getPayload();
|
||||
assertThat(payloadFile, is(not(sourceFile)));
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class),
|
||||
is(sourceFile));
|
||||
assertThat(sourceFile.exists(), is(false));
|
||||
assertThat(payloadFile.exists(), is(true));
|
||||
assertThat(payloadFile).isNotEqualTo(sourceFile);
|
||||
assertThat(resultMessage.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class)).isEqualTo(sourceFile);
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
assertThat(payloadFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -104,20 +101,20 @@ public class FileReadingMessageSourceIntegrationTests {
|
||||
@Test
|
||||
public void configured() throws Exception {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollableFileSource);
|
||||
assertEquals(inputDir, accessor.getPropertyValue("directory"));
|
||||
assertThat(accessor.getPropertyValue("directory")).isEqualTo(inputDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFiles() throws Exception {
|
||||
Message<File> received1 = pollableFileSource.receive();
|
||||
assertNotNull("This should return the first message", received1);
|
||||
assertThat(received1).as("This should return the first message").isNotNull();
|
||||
Message<File> received2 = pollableFileSource.receive();
|
||||
assertNotNull(received2);
|
||||
assertThat(received2).isNotNull();
|
||||
Message<File> received3 = pollableFileSource.receive();
|
||||
assertNotNull(received3);
|
||||
assertNotSame(received1 + " == " + received2, received1.getPayload(), received2.getPayload());
|
||||
assertNotSame(received1 + " == " + received3, received1.getPayload(), received3.getPayload());
|
||||
assertNotSame(received2 + " == " + received3, received2.getPayload(), received3.getPayload());
|
||||
assertThat(received3).isNotNull();
|
||||
assertThat(received2.getPayload()).as(received1 + " == " + received2).isNotSameAs(received1.getPayload());
|
||||
assertThat(received3.getPayload()).as(received1 + " == " + received3).isNotSameAs(received1.getPayload());
|
||||
assertThat(received3.getPayload()).as(received2 + " == " + received3).isNotSameAs(received2.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,22 +122,22 @@ public class FileReadingMessageSourceIntegrationTests {
|
||||
Message<File> received1 = pollableFileSource.receive();
|
||||
Message<File> received2 = pollableFileSource.receive();
|
||||
Message<File> received3 = pollableFileSource.receive();
|
||||
assertNotSame(received1 + " == " + received2, received1, received2);
|
||||
assertNotSame(received1 + " == " + received3, received1, received3);
|
||||
assertNotSame(received2 + " == " + received3, received2, received3);
|
||||
assertThat(received2).as(received1 + " == " + received2).isNotSameAs(received1);
|
||||
assertThat(received3).as(received1 + " == " + received3).isNotSameAs(received1);
|
||||
assertThat(received3).as(received2 + " == " + received3).isNotSameAs(received2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputDirExhausted() throws Exception {
|
||||
assertNotNull(pollableFileSource.receive());
|
||||
assertNotNull(pollableFileSource.receive());
|
||||
assertThat(pollableFileSource.receive()).isNotNull();
|
||||
assertThat(pollableFileSource.receive()).isNotNull();
|
||||
Message<File> receive = pollableFileSource.receive();
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
File payload = receive.getPayload();
|
||||
assertEquals(payload, receive.getHeaders().get(FileHeaders.ORIGINAL_FILE));
|
||||
assertEquals(payload.getName(), receive.getHeaders().get(FileHeaders.FILENAME));
|
||||
assertEquals(payload.getName(), receive.getHeaders().get(FileHeaders.RELATIVE_PATH));
|
||||
assertNull(pollableFileSource.receive());
|
||||
assertThat(receive.getHeaders().get(FileHeaders.ORIGINAL_FILE)).isEqualTo(payload);
|
||||
assertThat(receive.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(payload.getName());
|
||||
assertThat(receive.getHeaders().get(FileHeaders.RELATIVE_PATH)).isEqualTo(payload.getName());
|
||||
assertThat(pollableFileSource.receive()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,7 +169,7 @@ public class FileReadingMessageSourceIntegrationTests {
|
||||
}
|
||||
// make sure three different files were taken
|
||||
Message<File> received = pollableFileSource.receive();
|
||||
assertNull(received);
|
||||
assertThat(received).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -97,25 +94,25 @@ public class FileReadingMessageSourcePersistentFilterIntegrationTests {
|
||||
@Test
|
||||
public void configured() throws Exception {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(this.pollableFileSource);
|
||||
assertEquals(inputDir, accessor.getPropertyValue("directory"));
|
||||
assertThat(accessor.getPropertyValue("directory")).isEqualTo(inputDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFiles() throws Exception {
|
||||
Message<File> received1 = this.pollableFileSource.receive();
|
||||
assertNotNull("This should return the first message", received1);
|
||||
assertThat(received1).as("This should return the first message").isNotNull();
|
||||
Message<File> received2 = this.pollableFileSource.receive();
|
||||
assertNotNull(received2);
|
||||
assertThat(received2).isNotNull();
|
||||
Message<File> received3 = this.pollableFileSource.receive();
|
||||
assertNotNull(received3);
|
||||
assertNotSame(received1 + " == " + received2, received1.getPayload(), received2.getPayload());
|
||||
assertNotSame(received1 + " == " + received3, received1.getPayload(), received3.getPayload());
|
||||
assertNotSame(received2 + " == " + received3, received2.getPayload(), received3.getPayload());
|
||||
assertThat(received3).isNotNull();
|
||||
assertThat(received2.getPayload()).as(received1 + " == " + received2).isNotSameAs(received1.getPayload());
|
||||
assertThat(received3.getPayload()).as(received1 + " == " + received3).isNotSameAs(received1.getPayload());
|
||||
assertThat(received3.getPayload()).as(received2 + " == " + received3).isNotSameAs(received2.getPayload());
|
||||
this.context.close();
|
||||
|
||||
loadContextAndGetMessageSource();
|
||||
Message<File> received4 = this.pollableFileSource.receive();
|
||||
assertNull(received4);
|
||||
assertThat(received4).isNull();
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -84,16 +79,16 @@ public class FileReadingMessageSourceTests {
|
||||
@Test
|
||||
public void straightProcess() throws Exception {
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock });
|
||||
assertThat(source.receive().getPayload(), is(fileMock));
|
||||
assertThat(source.receive().getPayload()).isEqualTo(fileMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requeueOnFailure() throws Exception {
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock });
|
||||
Message<File> received = source.receive();
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
source.onFailure(received);
|
||||
assertEquals(received.getPayload(), source.receive().getPayload());
|
||||
assertThat(source.receive().getPayload()).isEqualTo(received.getPayload());
|
||||
verify(inputDirectoryMock, times(1)).listFiles();
|
||||
}
|
||||
|
||||
@@ -103,9 +98,9 @@ public class FileReadingMessageSourceTests {
|
||||
when(anotherFileMock.getAbsolutePath()).thenReturn("foo/bar/anotherFileMock");
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock, anotherFileMock });
|
||||
source.setScanEachPoll(true);
|
||||
assertNotNull(source.receive());
|
||||
assertNotNull(source.receive());
|
||||
assertNull(source.receive());
|
||||
assertThat(source.receive()).isNotNull();
|
||||
assertThat(source.receive()).isNotNull();
|
||||
assertThat(source.receive()).isNull();
|
||||
verify(inputDirectoryMock, times(3)).listFiles();
|
||||
}
|
||||
|
||||
@@ -113,9 +108,9 @@ public class FileReadingMessageSourceTests {
|
||||
public void noDuplication() throws Exception {
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock });
|
||||
Message<File> received = source.receive();
|
||||
assertNotNull(received);
|
||||
assertEquals(fileMock, received.getPayload());
|
||||
assertNull(source.receive());
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload()).isEqualTo(fileMock);
|
||||
assertThat(source.receive()).isNull();
|
||||
verify(inputDirectoryMock, times(2)).listFiles();
|
||||
}
|
||||
|
||||
@@ -128,8 +123,8 @@ public class FileReadingMessageSourceTests {
|
||||
public void lockIsAcquired() throws IOException {
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock });
|
||||
Message<File> received = source.receive();
|
||||
assertNotNull(received);
|
||||
assertEquals(fileMock, received.getPayload());
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getPayload()).isEqualTo(fileMock);
|
||||
verify(locker).lock(fileMock);
|
||||
}
|
||||
|
||||
@@ -138,7 +133,7 @@ public class FileReadingMessageSourceTests {
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[] { fileMock });
|
||||
when(locker.lock(fileMock)).thenReturn(false);
|
||||
Message<File> received = source.receive();
|
||||
assertNull(received);
|
||||
assertThat(received).isNull();
|
||||
verify(locker).lock(fileMock);
|
||||
}
|
||||
|
||||
@@ -157,10 +152,10 @@ public class FileReadingMessageSourceTests {
|
||||
when(comparator.compare(file3, file2)).thenReturn(-1);
|
||||
|
||||
when(inputDirectoryMock.listFiles()).thenReturn(new File[]{file2, file3, file1});
|
||||
assertSame(file3, source.receive().getPayload());
|
||||
assertSame(file2, source.receive().getPayload());
|
||||
assertSame(file1, source.receive().getPayload());
|
||||
assertNull(source.receive());
|
||||
assertThat(source.receive().getPayload()).isSameAs(file3);
|
||||
assertThat(source.receive().getPayload()).isSameAs(file2);
|
||||
assertThat(source.receive().getPayload()).isSameAs(file1);
|
||||
assertThat(source.receive()).isNull();
|
||||
verify(inputDirectoryMock, times(2)).listFiles();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -58,19 +55,19 @@ public class FileToChannelIntegrationTests {
|
||||
file.setLastModified(System.currentTimeMillis() - 1000);
|
||||
|
||||
Message<?> received = this.fileMessages.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
Message<?> result = this.resultChannel.receive(10000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertTrue(!file.exists());
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(!file.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directoryExhaustion() throws Exception {
|
||||
File.createTempFile("test", null, inputDirectory).setLastModified(System.currentTimeMillis() - 1000);
|
||||
Message<?> received = this.fileMessages.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertNull(fileMessages.receive(200));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(fileMessages.receive(200)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,19 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
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.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.startsWith;
|
||||
@@ -90,7 +79,7 @@ public class FileWritingMessageHandlerTests {
|
||||
|
||||
static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\näöüß";
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\n????";
|
||||
|
||||
|
||||
private File sourceFile;
|
||||
@@ -119,7 +108,7 @@ public class FileWritingMessageHandlerTests {
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void unsupportedType() {
|
||||
this.handler.handleMessage(new GenericMessage<>(99));
|
||||
assertThat(this.outputDirectory.listFiles()[0], nullValue());
|
||||
assertThat(this.outputDirectory.listFiles()[0]).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,18 +117,18 @@ public class FileWritingMessageHandlerTests {
|
||||
FileWritingMessageHandler handler = new FileWritingMessageHandler(mock(Expression.class));
|
||||
handler.setChmod(0421);
|
||||
Set<?> permissions = TestUtils.getPropertyValue(handler, "permissions", Set.class);
|
||||
assertThat(permissions.size(), equalTo(3));
|
||||
assertTrue(permissions.contains(PosixFilePermission.OWNER_READ));
|
||||
assertTrue(permissions.contains(PosixFilePermission.GROUP_WRITE));
|
||||
assertTrue(permissions.contains(PosixFilePermission.OTHERS_EXECUTE));
|
||||
assertThat(permissions.size()).isEqualTo(3);
|
||||
assertThat(permissions.contains(PosixFilePermission.OWNER_READ)).isTrue();
|
||||
assertThat(permissions.contains(PosixFilePermission.GROUP_WRITE)).isTrue();
|
||||
assertThat(permissions.contains(PosixFilePermission.OTHERS_EXECUTE)).isTrue();
|
||||
handler.setChmod(0600);
|
||||
permissions = TestUtils.getPropertyValue(handler, "permissions", Set.class);
|
||||
assertThat(permissions.size(), equalTo(2));
|
||||
assertTrue(permissions.contains(PosixFilePermission.OWNER_READ));
|
||||
assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE));
|
||||
assertThat(permissions.size()).isEqualTo(2);
|
||||
assertThat(permissions.contains(PosixFilePermission.OWNER_READ)).isTrue();
|
||||
assertThat(permissions.contains(PosixFilePermission.OWNER_WRITE)).isTrue();
|
||||
handler.setChmod(0777);
|
||||
permissions = TestUtils.getPropertyValue(handler, "permissions", Set.class);
|
||||
assertThat(permissions.size(), equalTo(9));
|
||||
assertThat(permissions.size()).isEqualTo(9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,11 +140,11 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.setOutputChannel(new NullChannel());
|
||||
handler.handleMessage(new GenericMessage<String>("test"));
|
||||
File[] output = outputDirectory.listFiles();
|
||||
assertThat(output.length, equalTo(1));
|
||||
assertThat(output[0], notNullValue());
|
||||
assertThat(output.length).isEqualTo(1);
|
||||
assertThat(output[0]).isNotNull();
|
||||
if (FileUtils.IS_POSIX) {
|
||||
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(output[0].toPath());
|
||||
assertThat(permissions.size(), equalTo(9));
|
||||
assertThat(permissions.size()).isEqualTo(9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +176,7 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
File destFile = (File) result.getPayload();
|
||||
assertThat(destFile.getAbsolutePath(), containsString(TestUtils.applySystemFileSeparator("/dir1/dir2/test")));
|
||||
assertThat(destFile.getAbsolutePath()).contains(TestUtils.applySystemFileSeparator("/dir1/dir2/test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,7 +275,7 @@ public class FileWritingMessageHandlerTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("[/foo] could not be created"));
|
||||
assertThat(e.getMessage()).contains("[/foo] could not be created");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +287,7 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -310,7 +299,7 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -322,11 +311,11 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT)
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile)
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -338,11 +327,11 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT)
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath())
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -355,11 +344,11 @@ public class FileWritingMessageHandlerTests {
|
||||
SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING))
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile)
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -372,11 +361,11 @@ public class FileWritingMessageHandlerTests {
|
||||
SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING))
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath())
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -391,11 +380,11 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> message = MessageBuilder.withPayload(is)
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile)
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -410,11 +399,11 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> message = MessageBuilder.withPayload(is)
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath())
|
||||
.build();
|
||||
assertTrue(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
assertFileContentIsMatching(result);
|
||||
assertFalse(sourceFile.exists());
|
||||
assertThat(sourceFile.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -426,7 +415,7 @@ public class FileWritingMessageHandlerTests {
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
handler.handleMessage(message);
|
||||
File result = (File) output.receive(0).getPayload();
|
||||
assertThat(result.getName(), is(anyFilename));
|
||||
assertThat(result.getName()).isEqualTo(anyFilename);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -455,9 +444,9 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
File destFile = (File) result.getPayload();
|
||||
assertNotSame(destFile, sourceFile);
|
||||
assertThat(destFile.exists(), is(false));
|
||||
assertThat(outFile.exists(), is(true));
|
||||
assertThat(sourceFile).isNotSameAs(destFile);
|
||||
assertThat(destFile.exists()).isFalse();
|
||||
assertThat(outFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -473,9 +462,9 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(message);
|
||||
Message<?> result = output.receive(0);
|
||||
File destFile = (File) result.getPayload();
|
||||
assertNotSame(destFile, sourceFile);
|
||||
assertThat(sourceFile).isNotSameAs(destFile);
|
||||
assertFileContentIsMatching(result);
|
||||
assertThat(outFile.exists(), is(true));
|
||||
assertThat(outFile.exists()).isTrue();
|
||||
assertFileContentIs(outFile, "foo");
|
||||
}
|
||||
|
||||
@@ -498,9 +487,9 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(new GenericMessage<String>("bar"));
|
||||
handler.handleMessage(new GenericMessage<String>("baz"));
|
||||
handler.handleMessage(new GenericMessage<byte[]>("qux".getBytes())); // change of payload type forces flush
|
||||
assertThat(file.length(), greaterThanOrEqualTo(9L));
|
||||
assertThat(file.length()).isGreaterThanOrEqualTo(9L);
|
||||
handler.stop(); // forces flush
|
||||
assertThat(file.length(), equalTo(12L));
|
||||
assertThat(file.length()).isEqualTo(12L);
|
||||
handler.setFlushInterval(100);
|
||||
handler.start();
|
||||
handler.handleMessage(new GenericMessage<InputStream>(new ByteArrayInputStream("fiz".getBytes())));
|
||||
@@ -508,11 +497,11 @@ public class FileWritingMessageHandlerTests {
|
||||
while (n++ < 100 && file.length() < 15) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertThat(file.length(), equalTo(15L));
|
||||
assertThat(file.length()).isEqualTo(15L);
|
||||
handler.handleMessage(new GenericMessage<InputStream>(new ByteArrayInputStream("buz".getBytes())));
|
||||
handler.trigger(new GenericMessage<String>(Matcher.quoteReplacement(file.getAbsolutePath())));
|
||||
assertThat(file.length(), equalTo(18L));
|
||||
assertEquals(0, TestUtils.getPropertyValue(handler, "fileStates", Map.class).size());
|
||||
assertThat(file.length()).isEqualTo(18L);
|
||||
assertThat(TestUtils.getPropertyValue(handler, "fileStates", Map.class).size()).isEqualTo(0);
|
||||
|
||||
handler.setFlushInterval(30000);
|
||||
final AtomicBoolean called = new AtomicBoolean();
|
||||
@@ -522,8 +511,8 @@ public class FileWritingMessageHandlerTests {
|
||||
});
|
||||
handler.handleMessage(new GenericMessage<InputStream>(new ByteArrayInputStream("box".getBytes())));
|
||||
handler.trigger(new GenericMessage<String>("foo"));
|
||||
assertThat(file.length(), equalTo(21L));
|
||||
assertTrue(called.get());
|
||||
assertThat(file.length()).isEqualTo(21L);
|
||||
assertThat(called.get()).isTrue();
|
||||
|
||||
handler.handleMessage(new GenericMessage<InputStream>(new ByteArrayInputStream("bux".getBytes())));
|
||||
called.set(false);
|
||||
@@ -531,8 +520,8 @@ public class FileWritingMessageHandlerTests {
|
||||
called.set(true);
|
||||
return true;
|
||||
});
|
||||
assertThat(file.length(), equalTo(24L));
|
||||
assertTrue(called.get());
|
||||
assertThat(file.length()).isEqualTo(24L);
|
||||
assertThat(called.get()).isTrue();
|
||||
|
||||
handler.stop();
|
||||
Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
|
||||
@@ -550,7 +539,7 @@ public class FileWritingMessageHandlerTests {
|
||||
handler.handleMessage(new GenericMessage<String>("foo"));
|
||||
Thread.sleep(5);
|
||||
}
|
||||
assertThat(flushes.get(), greaterThanOrEqualTo(2));
|
||||
assertThat(flushes.get()).isGreaterThanOrEqualTo(2);
|
||||
handler.stop();
|
||||
}
|
||||
|
||||
@@ -593,7 +582,7 @@ public class FileWritingMessageHandlerTests {
|
||||
}).given(out).close();
|
||||
handler.handleMessage(new GenericMessage<>("foo".getBytes()));
|
||||
verify(out).write(any(byte[].class), anyInt(), anyInt());
|
||||
assertFalse(closeWhileWriting.get());
|
||||
assertThat(closeWhileWriting.get()).isFalse();
|
||||
handler.stop();
|
||||
}
|
||||
|
||||
@@ -689,19 +678,19 @@ public class FileWritingMessageHandlerTests {
|
||||
}
|
||||
|
||||
void assertLastModifiedIs(Message<?> result, long expected) {
|
||||
assertThat(messageToFile(result).lastModified(), is(expected));
|
||||
assertThat(messageToFile(result).lastModified()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
void assertFileContentIs(File destFile, String expected) throws IOException {
|
||||
assertNotSame(destFile, sourceFile);
|
||||
assertThat(destFile.exists(), is(true));
|
||||
assertThat(sourceFile).isNotSameAs(destFile);
|
||||
assertThat(destFile.exists()).isTrue();
|
||||
byte[] destFileContent = FileCopyUtils.copyToByteArray(destFile);
|
||||
assertThat(new String(destFileContent, DEFAULT_ENCODING), is(expected));
|
||||
assertThat(new String(destFileContent, DEFAULT_ENCODING)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
protected File messageToFile(Message<?> result) {
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.getPayload(), is(instanceOf(File.class)));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isInstanceOf(File.class);
|
||||
File destFile = (File) result.getPayload();
|
||||
return destFile;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
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.List;
|
||||
@@ -42,7 +41,7 @@ public class PatternMatchingFileListFilterTests {
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(1, accepted.size());
|
||||
assertThat(accepted.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +50,7 @@ public class PatternMatchingFileListFilterTests {
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(0, accepted.size());
|
||||
assertThat(accepted.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,9 +63,9 @@ public class PatternMatchingFileListFilterTests {
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
RegexPatternFileListFilter filter = new RegexPatternFileListFilter(pattern);
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(2, accepted.size());
|
||||
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
|
||||
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
|
||||
assertThat(accepted.size()).isEqualTo(2);
|
||||
assertThat(accepted.contains(new File("/some/path/foo.txt"))).isTrue();
|
||||
assertThat(accepted.contains(new File("/some/path/bar.txt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +76,7 @@ public class PatternMatchingFileListFilterTests {
|
||||
FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
|
||||
File[] files = new File[] { new File("/some/path/foo.txt") };
|
||||
List<File> accepted = filter.filterFiles(files);
|
||||
assertEquals(1, accepted.size());
|
||||
assertThat(accepted.size()).isEqualTo(1);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.file;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -71,17 +69,17 @@ public class RecursiveDirectoryScannerTests {
|
||||
RecursiveDirectoryScanner scanner = new RecursiveDirectoryScanner();
|
||||
scanner.setFilter(new AcceptOnceFileListFilter<>());
|
||||
List<File> files = scanner.listFiles(this.recursivePath.getRoot());
|
||||
assertEquals(5, files.size());
|
||||
assertThat(files, hasItem(this.topLevelFile));
|
||||
assertThat(files, hasItem(this.subLevelFile));
|
||||
assertThat(files, hasItem(this.subSubLevelFile));
|
||||
assertThat(files, hasItem(this.subFolder));
|
||||
assertThat(files, hasItem(this.subSubFolder));
|
||||
assertThat(files.size()).isEqualTo(5);
|
||||
assertThat(files).contains(this.topLevelFile);
|
||||
assertThat(files).contains(this.subLevelFile);
|
||||
assertThat(files).contains(this.subSubLevelFile);
|
||||
assertThat(files).contains(this.subFolder);
|
||||
assertThat(files).contains(this.subSubFolder);
|
||||
File file = new File(this.subSubFolder, "file4");
|
||||
file.createNewFile();
|
||||
files = scanner.listFiles(this.recursivePath.getRoot());
|
||||
assertEquals(1, files.size());
|
||||
assertThat(files, hasItem(file));
|
||||
assertThat(files.size()).isEqualTo(1);
|
||||
assertThat(files).contains(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
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 static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -109,19 +104,18 @@ public class WatchServiceDirectoryScannerTests {
|
||||
fileReadingMessageSource.afterPropertiesSet();
|
||||
fileReadingMessageSource.start();
|
||||
DirectoryScanner scanner = fileReadingMessageSource.getScanner();
|
||||
assertThat(scanner.getClass().getName(),
|
||||
containsString("FileReadingMessageSource$WatchServiceDirectoryScanner"));
|
||||
assertThat(scanner.getClass().getName()).contains("FileReadingMessageSource$WatchServiceDirectoryScanner");
|
||||
|
||||
// Files are skipped by the LastModifiedFileListFilter
|
||||
List<File> files = scanner.listFiles(folder.getRoot());
|
||||
assertEquals(0, files.size());
|
||||
assertThat(files.size()).isEqualTo(0);
|
||||
// Consider all the files as one day old
|
||||
fileLastModifiedFileListFilter.setAge(-60 * 60 * 24);
|
||||
files = scanner.listFiles(folder.getRoot());
|
||||
assertEquals(3, files.size());
|
||||
assertTrue(files.contains(top1));
|
||||
assertTrue(files.contains(foo1));
|
||||
assertTrue(files.contains(bar1));
|
||||
assertThat(files.size()).isEqualTo(3);
|
||||
assertThat(files.contains(top1)).isTrue();
|
||||
assertThat(files.contains(foo1)).isTrue();
|
||||
assertThat(files.contains(bar1)).isTrue();
|
||||
fileReadingMessageSource.start();
|
||||
File top2 = this.folder.newFile();
|
||||
File foo2 = File.createTempFile("foo", ".txt", this.foo);
|
||||
@@ -137,11 +131,11 @@ public class WatchServiceDirectoryScannerTests {
|
||||
files = scanner.listFiles(folder.getRoot());
|
||||
accum.addAll(files);
|
||||
}
|
||||
assertEquals(4, accum.size());
|
||||
assertTrue(accum.contains(top2));
|
||||
assertTrue(accum.contains(foo2));
|
||||
assertTrue(accum.contains(bar2));
|
||||
assertTrue(accum.contains(baz1));
|
||||
assertThat(accum.size()).isEqualTo(4);
|
||||
assertThat(accum.contains(top2)).isTrue();
|
||||
assertThat(accum.contains(foo2)).isTrue();
|
||||
assertThat(accum.contains(bar2)).isTrue();
|
||||
assertThat(accum.contains(baz1)).isTrue();
|
||||
|
||||
/*See AbstractWatchKey#signalEvent source code:
|
||||
if(var5 >= 512) {
|
||||
@@ -162,7 +156,7 @@ public class WatchServiceDirectoryScannerTests {
|
||||
accum.addAll(files);
|
||||
}
|
||||
|
||||
assertEquals(604, accum.size());
|
||||
assertThat(accum.size()).isEqualTo(604);
|
||||
|
||||
for (File fileForOverFlow : filesForOverflow) {
|
||||
accum.contains(fileForOverFlow);
|
||||
@@ -177,7 +171,7 @@ public class WatchServiceDirectoryScannerTests {
|
||||
accum.addAll(files);
|
||||
}
|
||||
|
||||
assertTrue(accum.contains(baz2));
|
||||
assertThat(accum.contains(baz2)).isTrue();
|
||||
|
||||
File baz2Copy = new File(baz2.getAbsolutePath());
|
||||
|
||||
@@ -191,8 +185,8 @@ public class WatchServiceDirectoryScannerTests {
|
||||
accum.addAll(files);
|
||||
}
|
||||
|
||||
assertEquals(1, files.size());
|
||||
assertTrue(files.contains(baz2));
|
||||
assertThat(files.size()).isEqualTo(1);
|
||||
assertThat(files.contains(baz2)).isTrue();
|
||||
|
||||
baz2.delete();
|
||||
|
||||
@@ -203,7 +197,7 @@ public class WatchServiceDirectoryScannerTests {
|
||||
scanner.listFiles(folder.getRoot());
|
||||
}
|
||||
|
||||
assertTrue(removeFileLatch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(removeFileLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
File baz3 = File.createTempFile("baz3", ".txt", baz);
|
||||
|
||||
@@ -213,10 +207,10 @@ public class WatchServiceDirectoryScannerTests {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertNotNull(fileMessage);
|
||||
assertEquals(baz3, fileMessage.getPayload());
|
||||
assertThat(fileMessage.getHeaders().get(FileHeaders.RELATIVE_PATH, String.class),
|
||||
startsWith(TestUtils.applySystemFileSeparator("foo/baz/")));
|
||||
assertThat(fileMessage).isNotNull();
|
||||
assertThat(fileMessage.getPayload()).isEqualTo(baz3);
|
||||
assertThat(fileMessage.getHeaders().get(FileHeaders.RELATIVE_PATH, String.class))
|
||||
.startsWith(TestUtils.applySystemFileSeparator("foo/baz/"));
|
||||
|
||||
fileReadingMessageSource.stop();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -71,10 +70,9 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
FileReadingMessageSource source = (FileReadingMessageSource)
|
||||
adapterAccessor.getPropertyValue("source");
|
||||
assertEquals(Boolean.TRUE,
|
||||
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
|
||||
assertThat(new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.TRUE);
|
||||
source.start();
|
||||
assertTrue(new File(BASE_PATH + File.separator + "defaultInbound").exists());
|
||||
assertThat(new File(BASE_PATH + File.separator + "defaultInbound").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,9 +81,8 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
FileReadingMessageSource source = (FileReadingMessageSource)
|
||||
adapterAccessor.getPropertyValue("source");
|
||||
assertTrue(new File(BASE_PATH + File.separator + "customInbound").exists());
|
||||
assertEquals(Boolean.FALSE,
|
||||
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
|
||||
assertThat(new File(BASE_PATH + File.separator + "customInbound").exists()).isTrue();
|
||||
assertThat(new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,9 +91,8 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
assertEquals(Boolean.TRUE,
|
||||
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
|
||||
assertTrue(new File(BASE_PATH + File.separator + "defaultOutbound").exists());
|
||||
assertThat(new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.TRUE);
|
||||
assertThat(new File(BASE_PATH + File.separator + "defaultOutbound").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,9 +101,8 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
assertTrue(new File(BASE_PATH + File.separator + "customOutbound").exists());
|
||||
assertEquals(Boolean.FALSE,
|
||||
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
|
||||
assertThat(new File(BASE_PATH + File.separator + "customOutbound").exists()).isTrue();
|
||||
assertThat(new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,9 +111,8 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
gatewayAccessor.getPropertyValue("handler");
|
||||
assertEquals(Boolean.TRUE,
|
||||
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
|
||||
assertTrue(new File(BASE_PATH + File.separator + "defaultOutboundGateway").exists());
|
||||
assertThat(new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.TRUE);
|
||||
assertThat(new File(BASE_PATH + File.separator + "defaultOutboundGateway").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,9 +121,8 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
gatewayAccessor.getPropertyValue("handler");
|
||||
assertTrue(new File(BASE_PATH + File.separator + "customOutboundGateway").exists());
|
||||
assertEquals(Boolean.FALSE,
|
||||
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
|
||||
assertThat(new File(BASE_PATH + File.separator + "customOutboundGateway").exists()).isTrue();
|
||||
assertThat(new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Properties;
|
||||
@@ -55,8 +54,9 @@ public class ChainElementsTests {
|
||||
"inside a <chain/>) endpoint element: 'int-file:outbound-gateway' " +
|
||||
"with id='myFileOutboundGateway'.";
|
||||
final String actualMessage = e.getMessage();
|
||||
assertTrue("Error message did not start with '" + expectedMessage +
|
||||
"' but instead returned: '" + actualMessage + "'", actualMessage.startsWith(expectedMessage));
|
||||
assertThat(actualMessage.startsWith(expectedMessage))
|
||||
.as("Error message did not start with '" + expectedMessage +
|
||||
"' but instead returned: '" + actualMessage + "'").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,9 @@ public class ChainElementsTests {
|
||||
fail("Expected a XmlBeanDefinitionStoreException to be thrown.");
|
||||
}
|
||||
catch (XmlBeanDefinitionStoreException e) {
|
||||
assertEquals("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" +
|
||||
" allowed to appear in element 'int-file:outbound-gateway'.", e.getCause().getMessage());
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("cvc-complex-type.3.2.2: Attribute 'input-channel' is " +
|
||||
"not" +
|
||||
" allowed to appear in element 'int-file:outbound-gateway'.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -53,31 +51,31 @@ public class DefaultConfigurationTests {
|
||||
@Test
|
||||
public void verifyErrorChannel() {
|
||||
Object errorChannel = context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
assertNotNull(errorChannel);
|
||||
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
|
||||
assertThat(errorChannel).isNotNull();
|
||||
assertThat(errorChannel.getClass()).isEqualTo(PublishSubscribeChannel.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyNullChannel() {
|
||||
Object nullChannel = context.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
|
||||
assertNotNull(nullChannel);
|
||||
assertEquals(NullChannel.class, nullChannel.getClass());
|
||||
assertThat(nullChannel).isNotNull();
|
||||
assertThat(nullChannel.getClass()).isEqualTo(NullChannel.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskScheduler() {
|
||||
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
|
||||
assertThat(taskScheduler.getClass()).isEqualTo(ThreadPoolTaskScheduler.class);
|
||||
ErrorHandler errorHandler = TestUtils.getPropertyValue(taskScheduler, "errorHandler", ErrorHandler.class);
|
||||
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
|
||||
assertThat(errorHandler.getClass()).isEqualTo(MessagePublishingErrorHandler.class);
|
||||
MessageChannel defaultErrorChannel = TestUtils.getPropertyValue(errorHandler,
|
||||
"messagingTemplate.defaultDestination", MessageChannel.class);
|
||||
assertNull(defaultErrorChannel);
|
||||
assertThat(defaultErrorChannel).isNull();
|
||||
errorHandler.handleError(new Throwable());
|
||||
defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "messagingTemplate.defaultDestination",
|
||||
MessageChannel.class);
|
||||
assertNotNull(defaultErrorChannel);
|
||||
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
|
||||
assertThat(defaultErrorChannel).isNotNull();
|
||||
assertThat(defaultErrorChannel).isEqualTo(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isOneOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
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.Comparator;
|
||||
@@ -85,25 +77,26 @@ public class FileInboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelName() throws Exception {
|
||||
public void channelName() {
|
||||
AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class);
|
||||
assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName());
|
||||
assertThat(channel.getComponentName()).as("Channel should be available under specified id")
|
||||
.isEqualTo("inputDirPoller");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void justFilter() throws Exception {
|
||||
public void justFilter() {
|
||||
Iterator<?> filterIterator = TestUtils
|
||||
.getPropertyValue(this.inboundWithJustFilterSource, "scanner.filter.fileFilters", Set.class).iterator();
|
||||
assertThat(filterIterator.next(), instanceOf(IgnoreHiddenFileListFilter.class));
|
||||
assertSame(this.filter, filterIterator.next());
|
||||
assertThat(filterIterator.next()).isInstanceOf(IgnoreHiddenFileListFilter.class);
|
||||
assertThat(filterIterator.next()).isSameAs(this.filter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputDirectory() {
|
||||
File expected = new File(System.getProperty("java.io.tmpdir"));
|
||||
File actual = (File) this.accessor.getPropertyValue("directory");
|
||||
assertEquals("'directory' should be set", expected, actual);
|
||||
assertThat(this.accessor.getPropertyValue("scanEachPoll"), is(Boolean.TRUE));
|
||||
assertThat(actual).as("'directory' should be set").isEqualTo(expected);
|
||||
assertThat(this.accessor.getPropertyValue("scanEachPoll")).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,26 +104,27 @@ public class FileInboundChannelAdapterParserTests {
|
||||
DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner");
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
|
||||
Object filter = scannerAccessor.getPropertyValue("filter");
|
||||
assertTrue("'filter' should be set and be of instance AcceptOnceFileListFilter but got "
|
||||
+ filter.getClass().getSimpleName(), filter instanceof AcceptOnceFileListFilter);
|
||||
assertThat(filter instanceof AcceptOnceFileListFilter)
|
||||
.as("'filter' should be set and be of instance AcceptOnceFileListFilter but got "
|
||||
+ filter.getClass().getSimpleName()).isTrue();
|
||||
|
||||
assertThat(scanner.getClass().getName(),
|
||||
containsString("FileReadingMessageSource$WatchServiceDirectoryScanner"));
|
||||
assertThat(scanner.getClass().getName()).contains("FileReadingMessageSource$WatchServiceDirectoryScanner");
|
||||
|
||||
FileReadingMessageSource.WatchEventType[] watchEvents =
|
||||
(FileReadingMessageSource.WatchEventType[]) this.accessor.getPropertyValue("watchEvents");
|
||||
assertEquals(2, watchEvents.length);
|
||||
assertThat(watchEvents.length).isEqualTo(2);
|
||||
for (FileReadingMessageSource.WatchEventType watchEvent : watchEvents) {
|
||||
assertNotEquals(FileReadingMessageSource.WatchEventType.CREATE, watchEvent);
|
||||
assertThat(watchEvent, isOneOf(FileReadingMessageSource.WatchEventType.MODIFY,
|
||||
FileReadingMessageSource.WatchEventType.DELETE));
|
||||
assertThat(watchEvent).isNotEqualTo(FileReadingMessageSource.WatchEventType.CREATE);
|
||||
assertThat(watchEvent)
|
||||
.isIn(FileReadingMessageSource.WatchEventType.MODIFY,
|
||||
FileReadingMessageSource.WatchEventType.DELETE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparator() throws Exception {
|
||||
public void comparator() {
|
||||
Object priorityQueue = accessor.getPropertyValue("toBeReceived");
|
||||
assertEquals(PriorityBlockingQueue.class, priorityQueue.getClass());
|
||||
assertThat(priorityQueue).isInstanceOf(PriorityBlockingQueue.class);
|
||||
Object expected = context.getBean("testComparator");
|
||||
DirectFieldAccessor queueAccessor = new DirectFieldAccessor(priorityQueue);
|
||||
Object innerQueue = queueAccessor.getPropertyValue("q");
|
||||
@@ -142,7 +136,7 @@ public class FileInboundChannelAdapterParserTests {
|
||||
// probably running under JDK 7
|
||||
actual = queueAccessor.getPropertyValue("comparator");
|
||||
}
|
||||
assertSame("comparator reference not set, ", expected, actual);
|
||||
assertThat(actual).as("comparator reference not set, ").isSameAs(expected);
|
||||
}
|
||||
|
||||
static class TestComparator implements Comparator<File> {
|
||||
@@ -151,5 +145,7 @@ public class FileInboundChannelAdapterParserTests {
|
||||
public int compare(File f1, File f2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.file.config;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
@@ -67,21 +64,21 @@ public class FileInboundChannelAdapterWithClasspathInPropertiesTests {
|
||||
public void inputDirectory() throws Exception {
|
||||
File expected = new ClassPathResource("").getFile();
|
||||
File actual = (File) accessor.getPropertyValue("directory");
|
||||
assertEquals("'directory' should be set", expected, actual);
|
||||
assertThat(actual).as("'directory' should be set").isEqualTo(expected);
|
||||
|
||||
FileListFilter<File> fileListFilter =
|
||||
TestUtils.getPropertyValue(this.source, "scanner.filter", FileListFilter.class);
|
||||
assertThat(fileListFilter, instanceOf(CompositeFileListFilter.class));
|
||||
assertThat(fileListFilter).isInstanceOf(CompositeFileListFilter.class);
|
||||
Set<FileListFilter<File>> fileFilters =
|
||||
TestUtils.getPropertyValue(fileListFilter, "fileFilters", Set.class);
|
||||
assertEquals(2, fileFilters.size());
|
||||
assertThat(fileFilters.size()).isEqualTo(2);
|
||||
Iterator<FileListFilter<File>> iterator = fileFilters.iterator();
|
||||
iterator.next();
|
||||
FileListFilter<File> expressionFilter = iterator.next();
|
||||
assertThat(expressionFilter, instanceOf(ExpressionFileListFilter.class));
|
||||
assertEquals("true",
|
||||
TestUtils.getPropertyValue(expressionFilter, "expression.expression", String.class));
|
||||
assertSame(this.beanFactory, TestUtils.getPropertyValue(expressionFilter, "beanFactory"));
|
||||
assertThat(expressionFilter).isInstanceOf(ExpressionFileListFilter.class);
|
||||
assertThat(TestUtils.getPropertyValue(expressionFilter, "expression.expression", String.class))
|
||||
.isEqualTo("true");
|
||||
assertThat(TestUtils.getPropertyValue(expressionFilter, "beanFactory")).isSameAs(this.beanFactory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
@@ -68,26 +65,26 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
@Test
|
||||
public void channelName() {
|
||||
AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class);
|
||||
assertEquals("adapterWithPattern", channel.getComponentName());
|
||||
assertThat(channel.getComponentName()).isEqualTo("adapterWithPattern");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoStartupDisabled() {
|
||||
assertFalse(this.endpoint.isRunning());
|
||||
assertEquals(Boolean.FALSE, new DirectFieldAccessor(endpoint).getPropertyValue("autoStartup"));
|
||||
assertThat(this.endpoint.isRunning()).isFalse();
|
||||
assertThat(new DirectFieldAccessor(endpoint).getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputDirectory() {
|
||||
File expected = new File(System.getProperty("java.io.tmpdir"));
|
||||
File actual = (File) accessor.getPropertyValue("directory");
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compositeFilterType() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter);
|
||||
assertThat(scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +93,7 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(
|
||||
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
|
||||
assertEquals(2, filters.size());
|
||||
assertThat(filters.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +108,7 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
hasAcceptOnceFilter = true;
|
||||
}
|
||||
}
|
||||
assertTrue("expected AcceptOnceFileListFilter", hasAcceptOnceFilter);
|
||||
assertThat(hasAcceptOnceFilter).as("expected AcceptOnceFileListFilter").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +123,8 @@ public class FileInboundChannelAdapterWithPatternParserTests {
|
||||
pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
|
||||
}
|
||||
}
|
||||
assertNotNull("expected SimplePatternFileListFilterTest", pattern);
|
||||
assertEquals("*.txt", pattern.toString());
|
||||
assertThat(pattern).as("expected SimplePatternFileListFilterTest").isNotNull();
|
||||
assertThat(pattern.toString()).isEqualTo("*.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,14 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
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,91 +57,91 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests {
|
||||
@Test
|
||||
public void filterAndNull() {
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndNull");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, filter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter).isSameAs(testFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAndTrue() {
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndTrue");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||
assertTrue(filters.contains(testFilter));
|
||||
assertThat(filters.iterator().next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
assertThat(filters.contains(testFilter)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterAndFalse() throws Exception {
|
||||
FileListFilter<?> filter = this.extractFilter("filterAndFalse");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, filter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter).isSameAs(testFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternAndNull() throws Exception {
|
||||
FileListFilter<?> filter = this.extractFilter("patternAndNull");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertThat(iterator.next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
assertThat(iterator.next()).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternAndTrue() throws Exception {
|
||||
FileListFilter<?> filter = this.extractFilter("patternAndTrue");
|
||||
assertTrue(filter instanceof CompositeFileListFilter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<FileListFilter<File>> filters = (Collection<FileListFilter<File>>)
|
||||
new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
|
||||
Iterator<FileListFilter<File>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertThat(iterator.next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
assertThat(iterator.next()).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternAndFalse() throws Exception {
|
||||
FileListFilter<File> filter = this.extractFilter("patternAndFalse");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertThat(filter, is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndNull() throws Exception {
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndNull");
|
||||
assertNotNull(filter);
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||
assertThat(filter).isNotNull();
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter instanceof AcceptOnceFileListFilter).isTrue();
|
||||
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndTrue() throws Exception {
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndTrue");
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertTrue(filter instanceof AcceptOnceFileListFilter);
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter instanceof AcceptOnceFileListFilter).isTrue();
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultAndFalse() throws Exception {
|
||||
FileListFilter<File> filter = this.extractFilter("defaultAndFalse");
|
||||
assertNotNull(filter);
|
||||
assertFalse(filter instanceof CompositeFileListFilter);
|
||||
assertFalse(filter instanceof AcceptOnceFileListFilter);
|
||||
assertThat(filter).isNotNull();
|
||||
assertThat(filter instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(filter instanceof AcceptOnceFileListFilter).isFalse();
|
||||
File testFile = new File("test");
|
||||
File[] files = new File[] { testFile, testFile, testFile };
|
||||
List<File> result = filter.filterFiles(files);
|
||||
assertEquals(3, result.size());
|
||||
assertThat(result.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -88,15 +88,15 @@ public class FileInboundChannelAdapterWithQueueSizeTests {
|
||||
HeadDirectoryScanner scanner1 = TestUtils.getPropertyValue(source1, "scanner", HeadDirectoryScanner.class);
|
||||
HeadDirectoryScanner scanner2 = TestUtils.getPropertyValue(source2, "scanner", HeadDirectoryScanner.class);
|
||||
List<File> files = scanner1.listFiles(new File(PATHNAME));
|
||||
assertEquals(2, files.size());
|
||||
assertThat(files.size()).isEqualTo(2);
|
||||
files = scanner2.listFiles(new File(PATHNAME));
|
||||
assertEquals(2, files.size());
|
||||
assertThat(files.size()).isEqualTo(2);
|
||||
files.get(0).delete();
|
||||
files.get(1).delete();
|
||||
files = scanner1.listFiles(new File(PATHNAME));
|
||||
assertEquals(1, files.size());
|
||||
assertThat(files.size()).isEqualTo(1);
|
||||
files = scanner2.listFiles(new File(PATHNAME));
|
||||
assertEquals(1, files.size());
|
||||
assertThat(files.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -60,7 +56,7 @@ public class FileInboundChannelAdapterWithRegexPatternParserTests {
|
||||
public void regexFilter() {
|
||||
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
|
||||
Object extractedFilter = scannerAccessor.getPropertyValue("filter");
|
||||
assertThat(extractedFilter, is(instanceOf(CompositeFileListFilter.class)));
|
||||
assertThat(extractedFilter).isInstanceOf(CompositeFileListFilter.class);
|
||||
Set<FileListFilter<?>> filters = (Set<FileListFilter<?>>) new DirectFieldAccessor(
|
||||
extractedFilter).getPropertyValue("fileFilters");
|
||||
Pattern pattern = null;
|
||||
@@ -69,8 +65,8 @@ public class FileInboundChannelAdapterWithRegexPatternParserTests {
|
||||
pattern = (Pattern) new DirectFieldAccessor(filter).getPropertyValue("pattern");
|
||||
}
|
||||
}
|
||||
assertNotNull("expected PatternMatchingFileListFilter", pattern);
|
||||
assertEquals("^.*\\.txt$", pattern.pattern());
|
||||
assertThat(pattern).as("expected PatternMatchingFileListFilter").isNotNull();
|
||||
assertThat(pattern.pattern()).isEqualTo("^.*\\.txt$");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
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;
|
||||
@@ -60,8 +55,8 @@ public class FileListFilterFactoryBeanTests {
|
||||
TestFilter testFilter = new TestFilter();
|
||||
factory.setFilter(testFilter);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, result);
|
||||
assertThat(result instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(result).isSameAs(testFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,10 +67,10 @@ public class FileListFilterFactoryBeanTests {
|
||||
factory.setFilter(testFilter);
|
||||
factory.setPreventDuplicates(Boolean.TRUE);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
assertThat(result instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<?> filters = (Collection<?>) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
assertTrue(filters.iterator().next() instanceof AcceptOnceFileListFilter);
|
||||
assertTrue(filters.contains(testFilter));
|
||||
assertThat(filters.iterator().next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
assertThat(filters.contains(testFilter)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +81,8 @@ public class FileListFilterFactoryBeanTests {
|
||||
factory.setFilter(testFilter);
|
||||
factory.setPreventDuplicates(Boolean.FALSE);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertSame(testFilter, result);
|
||||
assertThat(result instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(result).isSameAs(testFilter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,12 +92,12 @@ public class FileListFilterFactoryBeanTests {
|
||||
factory.setIgnoreHidden(false);
|
||||
factory.setFilenamePattern("foo");
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
assertThat(result instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next(), is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertThat(iterator.next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
assertThat(iterator.next()).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,14 +108,14 @@ public class FileListFilterFactoryBeanTests {
|
||||
factory.setFilenamePattern(("foo"));
|
||||
factory.setPreventDuplicates(Boolean.TRUE);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertTrue(result instanceof CompositeFileListFilter);
|
||||
assertThat(result instanceof CompositeFileListFilter).isTrue();
|
||||
Collection<FileListFilter<?>> filters = (Collection<FileListFilter<?>>)
|
||||
new DirectFieldAccessor(result).getPropertyValue("fileFilters");
|
||||
Iterator<FileListFilter<?>> iterator = filters.iterator();
|
||||
assertTrue(iterator.next() instanceof AcceptOnceFileListFilter);
|
||||
assertThat(iterator.next() instanceof AcceptOnceFileListFilter).isTrue();
|
||||
FileListFilter<?> patternFilter = iterator.next();
|
||||
assertThat(patternFilter, is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertFalse(TestUtils.getPropertyValue(patternFilter, "alwaysAcceptDirectories", Boolean.class));
|
||||
assertThat(patternFilter).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
assertThat(TestUtils.getPropertyValue(patternFilter, "alwaysAcceptDirectories", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,9 +126,9 @@ public class FileListFilterFactoryBeanTests {
|
||||
factory.setAlwaysAcceptDirectories(true);
|
||||
factory.setPreventDuplicates(Boolean.FALSE);
|
||||
FileListFilter<File> result = factory.getObject();
|
||||
assertFalse(result instanceof CompositeFileListFilter);
|
||||
assertThat(result, is(instanceOf(SimplePatternFileListFilter.class)));
|
||||
assertTrue(TestUtils.getPropertyValue(result, "alwaysAcceptDirectories", Boolean.class));
|
||||
assertThat(result instanceof CompositeFileListFilter).isFalse();
|
||||
assertThat(result).isInstanceOf(SimplePatternFileListFilter.class);
|
||||
assertThat(TestUtils.getPropertyValue(result, "alwaysAcceptDirectories", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
private static class TestFilter extends AbstractFileListFilter<File> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -58,12 +54,12 @@ public class FileMessageHistoryTests {
|
||||
|
||||
PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class);
|
||||
Message<?> message = outChannel.receive(10000);
|
||||
assertThat(message, is(notNullValue()));
|
||||
assertThat(message).isNotNull();
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
assertThat(history, is(notNullValue()));
|
||||
assertThat(history).isNotNull();
|
||||
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "fileAdapter", 0);
|
||||
assertNotNull(componentHistoryRecord);
|
||||
assertEquals("file:inbound-channel-adapter", componentHistoryRecord.get("type"));
|
||||
assertThat(componentHistoryRecord).isNotNull();
|
||||
assertThat(componentHistoryRecord.get("type")).isEqualTo("file:inbound-channel-adapter");
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -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.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class FileOutboundAdaptersWithClasspathInPropertiesTests {
|
||||
Expression destinationDirectoryExpression = (Expression) accessor.getPropertyValue("destinationDirectoryExpression");
|
||||
File actual = new File(destinationDirectoryExpression.getExpressionString());
|
||||
|
||||
assertEquals("'destinationDirectory' should be set", expected, actual);
|
||||
assertThat(actual).as("'destinationDirectory' should be set").isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class FileOutboundAdaptersWithClasspathInPropertiesTests {
|
||||
Expression destinationDirectoryExpression = (Expression) accessor.getPropertyValue("destinationDirectoryExpression");
|
||||
File actual = new File(destinationDirectoryExpression.getExpressionString());
|
||||
|
||||
assertEquals("'destinationDirectory' should be set", expected, actual);
|
||||
assertThat(actual).as("'destinationDirectory' should be set").isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
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.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -32,7 +26,6 @@ import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -134,20 +127,20 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
Expression destinationDirectoryExpression =
|
||||
(Expression) handlerAccessor.getPropertyValue("destinationDirectoryExpression");
|
||||
File actual = new File(destinationDirectoryExpression.getExpressionString());
|
||||
assertEquals(".foo", TestUtils.getPropertyValue(handler, "temporaryFileSuffix", String.class));
|
||||
assertThat(actual, is(expected));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "temporaryFileSuffix", String.class)).isEqualTo(".foo");
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
DefaultFileNameGenerator fileNameGenerator =
|
||||
(DefaultFileNameGenerator) handlerAccessor.getPropertyValue("fileNameGenerator");
|
||||
assertNotNull(fileNameGenerator);
|
||||
assertThat(fileNameGenerator).isNotNull();
|
||||
Expression expression = TestUtils.getPropertyValue(fileNameGenerator, "expression", Expression.class);
|
||||
assertNotNull(expression);
|
||||
assertEquals("'foo.txt'", expression.getExpressionString());
|
||||
assertEquals(Boolean.FALSE, handlerAccessor.getPropertyValue("deleteSourceFiles"));
|
||||
assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("flushWhenIdle"));
|
||||
assertThat(expression).isNotNull();
|
||||
assertThat(expression.getExpressionString()).isEqualTo("'foo.txt'");
|
||||
assertThat(handlerAccessor.getPropertyValue("deleteSourceFiles")).isEqualTo(Boolean.FALSE);
|
||||
assertThat(handlerAccessor.getPropertyValue("flushWhenIdle")).isEqualTo(Boolean.TRUE);
|
||||
if (FileUtils.IS_POSIX) {
|
||||
assertThat(TestUtils.getPropertyValue(handler, "permissions", Set.class).size(), equalTo(9));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "permissions", Set.class).size()).isEqualTo(9);
|
||||
}
|
||||
assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("preserveTimestamp"));
|
||||
assertThat(handlerAccessor.getPropertyValue("preserveTimestamp")).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,10 +155,10 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
(Expression) handlerAccessor.getPropertyValue("destinationDirectoryExpression");
|
||||
File actual = new File(destinationDirectoryExpression.getExpressionString());
|
||||
|
||||
assertEquals(expected, actual);
|
||||
assertTrue(handlerAccessor.getPropertyValue("fileNameGenerator") instanceof CustomFileNameGenerator);
|
||||
assertEquals(".writing", handlerAccessor.getPropertyValue("temporaryFileSuffix"));
|
||||
assertEquals(Boolean.FALSE, handlerAccessor.getPropertyValue("flushWhenIdle"));
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(handlerAccessor.getPropertyValue("fileNameGenerator") instanceof CustomFileNameGenerator).isTrue();
|
||||
assertThat(handlerAccessor.getPropertyValue("temporaryFileSuffix")).isEqualTo(".writing");
|
||||
assertThat(handlerAccessor.getPropertyValue("flushWhenIdle")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +167,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("deleteSourceFiles"));
|
||||
assertThat(handlerAccessor.getPropertyValue("deleteSourceFiles")).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +176,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
assertEquals(555, handlerAccessor.getPropertyValue("order"));
|
||||
assertThat(handlerAccessor.getPropertyValue("order")).isEqualTo(555);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,16 +185,16 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
assertEquals(4096, handlerAccessor.getPropertyValue("bufferSize"));
|
||||
assertEquals(12345L, handlerAccessor.getPropertyValue("flushInterval"));
|
||||
assertEquals(FileExistsMode.APPEND_NO_FLUSH, handlerAccessor.getPropertyValue("fileExistsMode"));
|
||||
assertSame(this.predicate, handlerAccessor.getPropertyValue("flushPredicate"));
|
||||
assertThat(handlerAccessor.getPropertyValue("bufferSize")).isEqualTo(4096);
|
||||
assertThat(handlerAccessor.getPropertyValue("flushInterval")).isEqualTo(12345L);
|
||||
assertThat(handlerAccessor.getPropertyValue("fileExistsMode")).isEqualTo(FileExistsMode.APPEND_NO_FLUSH);
|
||||
assertThat(handlerAccessor.getPropertyValue("flushPredicate")).isSameAs(this.predicate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterWithAutoStartupFalse() {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapterWithOrder);
|
||||
assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
|
||||
assertThat(adapterAccessor.getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,7 +203,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
adapterAccessor.getPropertyValue("handler");
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
|
||||
assertThat(handlerAccessor.getPropertyValue("charset")).isEqualTo(Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,12 +213,12 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
TestUtils.getPropertyValue(adapterWithDirectoryExpression, "handler", FileWritingMessageHandler.class);
|
||||
Method m = ReflectionUtils.findMethod(FileWritingMessageHandler.class, "getTemporaryFileSuffix");
|
||||
ReflectionUtils.makeAccessible(m);
|
||||
assertEquals(".writing", ReflectionUtils.invokeMethod(m, handler));
|
||||
assertThat(ReflectionUtils.invokeMethod(m, handler)).isEqualTo(".writing");
|
||||
String expectedExpressionString = "'foo/bar'";
|
||||
String actualExpressionString =
|
||||
TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class)
|
||||
.getExpressionString();
|
||||
assertEquals(expectedExpressionString, actualExpressionString);
|
||||
assertThat(actualExpressionString).isEqualTo(expectedExpressionString);
|
||||
|
||||
}
|
||||
|
||||
@@ -244,14 +237,15 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
usageChannel.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertEquals(4, adviceCalled);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
assertThat(adviceCalled).isEqualTo(4);
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterUsageWithAppendAndAppendNewLineTrue() throws Exception {
|
||||
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(this.adapterWithAppendNewLine, "handler.appendNewLine"));
|
||||
assertThat(TestUtils.getPropertyValue(this.adapterWithAppendNewLine, "handler.appendNewLine"))
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
String newLine = System.getProperty("line.separator");
|
||||
String expectedFileContent = "Initial File Content:" + newLine + "String content:" + newLine +
|
||||
"byte[] content:" + newLine + "File content" + newLine;
|
||||
@@ -266,7 +260,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
@@ -284,7 +278,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
@@ -302,12 +296,12 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
usageChannelWithFailMode.send(new GenericMessage<>("String content:"));
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), containsString("The destination file already exists at"));
|
||||
assertThat(e.getMessage()).contains("The destination file already exists at");
|
||||
testFile.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.fail("Was expecting an Exception to be thrown.");
|
||||
fail("Was expecting an Exception to be thrown.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -325,7 +319,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
usageChannelWithIgnoreMode.send(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
testFile.delete();
|
||||
|
||||
}
|
||||
@@ -352,7 +346,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
usageChannelConcurrent.send(new GenericMessage<>(bString));
|
||||
}
|
||||
|
||||
assertTrue(this.fileWriteLatch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(this.fileWriteLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
int beginningIndex = 0;
|
||||
@@ -367,7 +361,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
char[] characters = substring.toCharArray();
|
||||
char c = characters[0];
|
||||
for (char character : characters) {
|
||||
assertEquals(c, character);
|
||||
assertThat(character).isEqualTo(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -40,11 +40,11 @@ public class FileOutboundChannelAdapterParserWithErrorsTests {
|
||||
getClass()).close();
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertEquals("Configuration problem: Either directory or " +
|
||||
assertThat(e.getMessage()).isEqualTo("Configuration problem: Either directory or " +
|
||||
"directory-expression must be provided but not both\nOffending " +
|
||||
"resource: class path " +
|
||||
"resource [org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrorsTests-context.xml]",
|
||||
e.getMessage());
|
||||
"resource [org/springframework/integration/file/config" +
|
||||
"/FileOutboundChannelAdapterParserWithErrorsTests-context.xml]");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,10 +60,9 @@ public class FileOutboundChannelAdapterParserWithErrorsTests {
|
||||
getClass()).close();
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertEquals("Configuration problem: directory or directory-expression " +
|
||||
assertThat(e.getMessage()).isEqualTo("Configuration problem: directory or directory-expression " +
|
||||
"is required\nOffending resource: class path resource " +
|
||||
"[org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrors2Tests-context.xml]",
|
||||
e.getMessage());
|
||||
"[org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrors2Tests-context.xml]");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -93,19 +88,19 @@ public class FileOutboundGatewayParserTests {
|
||||
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(ordered);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
gatewayAccessor.getPropertyValue("handler");
|
||||
assertEquals(Boolean.FALSE, gatewayAccessor.getPropertyValue("autoStartup"));
|
||||
assertThat(gatewayAccessor.getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
assertEquals(777, handlerAccessor.getPropertyValue("order"));
|
||||
assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("requiresReply"));
|
||||
assertThat(handlerAccessor.getPropertyValue("order")).isEqualTo(777);
|
||||
assertThat(handlerAccessor.getPropertyValue("requiresReply")).isEqualTo(Boolean.TRUE);
|
||||
DefaultFileNameGenerator fileNameGenerator =
|
||||
(DefaultFileNameGenerator) handlerAccessor.getPropertyValue("fileNameGenerator");
|
||||
assertNotNull(fileNameGenerator);
|
||||
assertThat(fileNameGenerator).isNotNull();
|
||||
Expression expression = TestUtils.getPropertyValue(fileNameGenerator, "expression", Expression.class);
|
||||
assertNotNull(expression);
|
||||
assertEquals("'foo.txt'", expression.getExpressionString());
|
||||
assertThat(expression).isNotNull();
|
||||
assertThat(expression.getExpressionString()).isEqualTo("'foo.txt'");
|
||||
|
||||
Long sendTimeout = TestUtils.getPropertyValue(handler, "messagingTemplate.sendTimeout", Long.class);
|
||||
assertEquals(Long.valueOf(777), sendTimeout);
|
||||
assertThat(sendTimeout).isEqualTo(Long.valueOf(777));
|
||||
|
||||
}
|
||||
|
||||
@@ -113,11 +108,10 @@ public class FileOutboundGatewayParserTests {
|
||||
public void testOutboundGatewayWithDirectoryExpression() {
|
||||
FileWritingMessageHandler handler =
|
||||
TestUtils.getPropertyValue(gatewayWithDirectoryExpression, "handler", FileWritingMessageHandler.class);
|
||||
assertEquals("'build/foo'",
|
||||
TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class)
|
||||
.getExpressionString());
|
||||
assertThat(TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class)
|
||||
.getExpressionString()).isEqualTo("'build/foo'");
|
||||
handler.handleMessage(new GenericMessage<>("foo"));
|
||||
assertEquals(1, adviceCalled);
|
||||
assertThat(adviceCalled).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,13 +140,13 @@ public class FileOutboundGatewayParserTests {
|
||||
Message<?> replyMessage = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
|
||||
assertTrue(replyMessage.getPayload() instanceof File);
|
||||
assertThat(replyMessage.getPayload() instanceof File).isTrue();
|
||||
|
||||
File replyPayload = (File) replyMessage.getPayload();
|
||||
|
||||
assertEquals(expectedFileContent, new String(FileCopyUtils.copyToByteArray(replyPayload)));
|
||||
assertThat(new String(FileCopyUtils.copyToByteArray(replyPayload))).isEqualTo(expectedFileContent);
|
||||
|
||||
}
|
||||
|
||||
@@ -180,7 +174,7 @@ public class FileOutboundGatewayParserTests {
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
final String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
|
||||
try {
|
||||
|
||||
@@ -188,7 +182,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getMessage(), startsWith("The destination file already exists at '"));
|
||||
assertThat(e.getMessage()).startsWith("The destination file already exists at '");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -221,7 +215,7 @@ public class FileOutboundGatewayParserTests {
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
final String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
|
||||
try {
|
||||
|
||||
@@ -229,7 +223,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getMessage(), startsWith("The destination file already exists at '"));
|
||||
assertThat(e.getMessage()).startsWith("The destination file already exists at '");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -265,12 +259,12 @@ public class FileOutboundGatewayParserTests {
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
|
||||
assertTrue(m.getPayload() instanceof File);
|
||||
assertThat(m.getPayload() instanceof File).isTrue();
|
||||
|
||||
File replyPayload = (File) m.getPayload();
|
||||
assertEquals(expectedFileContent, new String(FileCopyUtils.copyToByteArray(replyPayload)));
|
||||
assertThat(new String(FileCopyUtils.copyToByteArray(replyPayload))).isEqualTo(expectedFileContent);
|
||||
|
||||
}
|
||||
|
||||
@@ -287,7 +281,8 @@ public class FileOutboundGatewayParserTests {
|
||||
@Test
|
||||
public void gatewayWithReplaceMode() throws Exception {
|
||||
|
||||
assertFalse(TestUtils.getPropertyValue(this.gatewayWithReplaceModeHandler, "requiresReply", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.gatewayWithReplaceModeHandler, "requiresReply", Boolean.class))
|
||||
.isFalse();
|
||||
|
||||
final MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
messagingTemplate.setDefaultDestination(this.gatewayWithReplaceModeChannel);
|
||||
@@ -304,12 +299,12 @@ public class FileOutboundGatewayParserTests {
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
assertThat(actualFileContent).isEqualTo(expectedFileContent);
|
||||
|
||||
assertTrue(m.getPayload() instanceof File);
|
||||
assertThat(m.getPayload() instanceof File).isTrue();
|
||||
|
||||
File replyPayload = (File) m.getPayload();
|
||||
assertEquals(expectedFileContent, new String(FileCopyUtils.copyToByteArray(replyPayload)));
|
||||
assertThat(new String(FileCopyUtils.copyToByteArray(replyPayload))).isEqualTo(expectedFileContent);
|
||||
|
||||
}
|
||||
|
||||
@@ -320,7 +315,8 @@ public class FileOutboundGatewayParserTests {
|
||||
*/
|
||||
@Test
|
||||
public void gatewayWithAppendNewLine() {
|
||||
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(this.gatewayWithAppendNewLine, "handler.appendNewLine"));
|
||||
assertThat(TestUtils.getPropertyValue(this.gatewayWithAppendNewLine, "handler.appendNewLine"))
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@@ -60,19 +58,19 @@ public class FileSplitterParserTests {
|
||||
|
||||
@Test
|
||||
public void testComplete() {
|
||||
assertFalse(TestUtils.getPropertyValue(this.splitter, "returnIterator", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.splitter, "markers", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.splitter, "markersJson", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.splitter, "requiresReply", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.splitter, "applySequence", Boolean.class));
|
||||
assertEquals(Charset.forName("UTF-8"), TestUtils.getPropertyValue(this.splitter, "charset"));
|
||||
assertEquals(5L, TestUtils.getPropertyValue(this.splitter, "messagingTemplate.sendTimeout"));
|
||||
assertEquals(this.out, TestUtils.getPropertyValue(this.splitter, "outputChannel"));
|
||||
assertEquals(2, TestUtils.getPropertyValue(this.splitter, "order"));
|
||||
assertEquals("foo", TestUtils.getPropertyValue(this.splitter, "firstLineHeaderName"));
|
||||
assertEquals(this.in, TestUtils.getPropertyValue(this.fullBoat, "inputChannel"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.fullBoat, "autoStartup", Boolean.class));
|
||||
assertEquals(1, TestUtils.getPropertyValue(this.fullBoat, "phase"));
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "returnIterator", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "markers", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "markersJson", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "requiresReply", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "applySequence", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "charset")).isEqualTo(Charset.forName("UTF-8"));
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "messagingTemplate.sendTimeout")).isEqualTo(5L);
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "outputChannel")).isEqualTo(this.out);
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "order")).isEqualTo(2);
|
||||
assertThat(TestUtils.getPropertyValue(this.splitter, "firstLineHeaderName")).isEqualTo("foo");
|
||||
assertThat(TestUtils.getPropertyValue(this.fullBoat, "inputChannel")).isEqualTo(this.in);
|
||||
assertThat(TestUtils.getPropertyValue(this.fullBoat, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.fullBoat, "phase")).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -79,60 +76,60 @@ public class FileTailInboundChannelAdapterParserTests {
|
||||
public void testDefault() {
|
||||
String fileName = TestUtils.getPropertyValue(defaultAdapter, "file", File.class).getAbsolutePath();
|
||||
String normalizedName = getNormalizedPath(fileName);
|
||||
assertEquals("/tmp/baz", normalizedName);
|
||||
assertEquals("tail -F -n 0 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command"));
|
||||
assertSame(exec, TestUtils.getPropertyValue(defaultAdapter, "taskExecutor"));
|
||||
assertTrue(TestUtils.getPropertyValue(defaultAdapter, "autoStartup", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(defaultAdapter, "enableStatusReader", Boolean.class));
|
||||
assertEquals(123, TestUtils.getPropertyValue(defaultAdapter, "phase"));
|
||||
assertSame(this.tailErrorChannel, TestUtils.getPropertyValue(defaultAdapter, "errorChannel"));
|
||||
assertThat(normalizedName).isEqualTo("/tmp/baz");
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "command")).isEqualTo("tail -F -n 0 " + fileName);
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "taskExecutor")).isSameAs(exec);
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "autoStartup", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "enableStatusReader", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "phase")).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "errorChannel")).isSameAs(this.tailErrorChannel);
|
||||
this.defaultAdapter.stop();
|
||||
this.defaultAdapter.setOptions("-F -n 6");
|
||||
this.defaultAdapter.start();
|
||||
assertEquals("tail -F -n 6 " + fileName, TestUtils.getPropertyValue(defaultAdapter, "command"));
|
||||
assertThat(TestUtils.getPropertyValue(defaultAdapter, "command")).isEqualTo("tail -F -n 6 " + fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNative() {
|
||||
String fileName = TestUtils.getPropertyValue(nativeAdapter, "file", File.class).getAbsolutePath();
|
||||
String normalizedName = getNormalizedPath(fileName);
|
||||
assertEquals("/tmp/foo", normalizedName);
|
||||
assertEquals("tail -F -n 6 " + fileName, TestUtils.getPropertyValue(nativeAdapter, "command"));
|
||||
assertSame(exec, TestUtils.getPropertyValue(nativeAdapter, "taskExecutor"));
|
||||
assertSame(sched, TestUtils.getPropertyValue(nativeAdapter, "taskScheduler"));
|
||||
assertTrue(TestUtils.getPropertyValue(nativeAdapter, "autoStartup", Boolean.class));
|
||||
assertFalse(TestUtils.getPropertyValue(nativeAdapter, "enableStatusReader", Boolean.class));
|
||||
assertEquals(123, TestUtils.getPropertyValue(nativeAdapter, "phase"));
|
||||
assertEquals(456L, TestUtils.getPropertyValue(nativeAdapter, "tailAttemptsDelay"));
|
||||
assertThat(normalizedName).isEqualTo("/tmp/foo");
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "command")).isEqualTo("tail -F -n 6 " + fileName);
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "taskExecutor")).isSameAs(exec);
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "taskScheduler")).isSameAs(sched);
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "autoStartup", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "enableStatusReader", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "phase")).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(nativeAdapter, "tailAttemptsDelay")).isEqualTo(456L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApacheDefault() {
|
||||
String fileName = TestUtils.getPropertyValue(apacheDefault, "file", File.class).getAbsolutePath();
|
||||
String normalizedName = getNormalizedPath(fileName);
|
||||
assertEquals("/tmp/bar", normalizedName);
|
||||
assertSame(exec, TestUtils.getPropertyValue(apacheDefault, "taskExecutor"));
|
||||
assertEquals(2000L, TestUtils.getPropertyValue(apacheDefault, "pollingDelay"));
|
||||
assertEquals(10000L, TestUtils.getPropertyValue(apacheDefault, "tailAttemptsDelay"));
|
||||
assertEquals(10000L, TestUtils.getPropertyValue(apacheDefault, "idleEventInterval"));
|
||||
assertFalse(TestUtils.getPropertyValue(apacheDefault, "autoStartup", Boolean.class));
|
||||
assertEquals(123, TestUtils.getPropertyValue(apacheDefault, "phase"));
|
||||
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(apacheDefault, "end"));
|
||||
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(apacheDefault, "reopen"));
|
||||
assertThat(normalizedName).isEqualTo("/tmp/bar");
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "taskExecutor")).isSameAs(exec);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "pollingDelay")).isEqualTo(2000L);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "tailAttemptsDelay")).isEqualTo(10000L);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "idleEventInterval")).isEqualTo(10000L);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "phase")).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "end")).isEqualTo(Boolean.TRUE);
|
||||
assertThat(TestUtils.getPropertyValue(apacheDefault, "reopen")).isEqualTo(Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApacheEndReopen() {
|
||||
String fileName = TestUtils.getPropertyValue(apacheEndReopen, "file", File.class).getAbsolutePath();
|
||||
String normalizedName = getNormalizedPath(fileName);
|
||||
assertEquals("/tmp/qux", normalizedName);
|
||||
assertSame(exec, TestUtils.getPropertyValue(apacheEndReopen, "taskExecutor"));
|
||||
assertEquals(2000L, TestUtils.getPropertyValue(apacheEndReopen, "pollingDelay"));
|
||||
assertEquals(10000L, TestUtils.getPropertyValue(apacheEndReopen, "tailAttemptsDelay"));
|
||||
assertFalse(TestUtils.getPropertyValue(apacheEndReopen, "autoStartup", Boolean.class));
|
||||
assertEquals(123, TestUtils.getPropertyValue(apacheEndReopen, "phase"));
|
||||
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(apacheEndReopen, "end"));
|
||||
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(apacheEndReopen, "reopen"));
|
||||
assertThat(normalizedName).isEqualTo("/tmp/qux");
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "taskExecutor")).isSameAs(exec);
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "pollingDelay")).isEqualTo(2000L);
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "tailAttemptsDelay")).isEqualTo(10000L);
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "phase")).isEqualTo(123);
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "end")).isEqualTo(Boolean.FALSE);
|
||||
assertThat(TestUtils.getPropertyValue(apacheEndReopen, "reopen")).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -54,7 +54,7 @@ public class FileToStringTransformerParserTests {
|
||||
FileToStringTransformer transformer = (FileToStringTransformer)
|
||||
handlerAccessor.getPropertyValue("transformer");
|
||||
DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer);
|
||||
assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles"));
|
||||
assertThat(transformerAccessor.getPropertyValue("deleteFiles")).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -42,13 +41,13 @@ public class InboundAdapterWithLockersTests {
|
||||
|
||||
@Test
|
||||
public void testAdaptersWithLockers() {
|
||||
assertEquals(context.getBean("locker"),
|
||||
TestUtils.getPropertyValue(context.getBean("inputWithLockerA"), "source.scanner.locker"));
|
||||
assertEquals(context.getBean("locker"),
|
||||
TestUtils.getPropertyValue(context.getBean("inputWithLockerB"), "source.scanner.locker"));
|
||||
assertTrue(TestUtils.getPropertyValue(context.getBean("inputWithLockerC"), "source.scanner.locker")
|
||||
instanceof NioFileLocker);
|
||||
assertTrue(TestUtils.getPropertyValue(context.getBean("inputWithLockerD"), "source.scanner.locker")
|
||||
instanceof NioFileLocker);
|
||||
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerA"), "source.scanner.locker"))
|
||||
.isEqualTo(context.getBean("locker"));
|
||||
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerB"), "source.scanner.locker"))
|
||||
.isEqualTo(context.getBean("locker"));
|
||||
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerC"), "source.scanner.locker")
|
||||
instanceof NioFileLocker).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerD"), "source.scanner.locker")
|
||||
instanceof NioFileLocker).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,16 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.dsl;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -157,8 +149,8 @@ public class FileTests {
|
||||
fail("NullPointerException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(MessageHandlingException.class));
|
||||
assertThat(e.getCause(), instanceOf(NullPointerException.class));
|
||||
assertThat(e).isInstanceOf(MessageHandlingException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(NullPointerException.class);
|
||||
}
|
||||
DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
|
||||
fileNameGenerator.setBeanFactory(this.beanFactory);
|
||||
@@ -170,15 +162,15 @@ public class FileTests {
|
||||
}
|
||||
}
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(targetFileWritingMessageHandler);
|
||||
assertEquals(Boolean.FALSE, dfa.getPropertyValue("flushWhenIdle"));
|
||||
assertEquals(60000L, dfa.getPropertyValue("flushInterval"));
|
||||
assertThat(dfa.getPropertyValue("flushWhenIdle")).isEqualTo(Boolean.FALSE);
|
||||
assertThat(dfa.getPropertyValue("flushInterval")).isEqualTo(60000L);
|
||||
dfa.setPropertyValue("fileNameGenerator", fileNameGenerator);
|
||||
this.fileFlow1Input.send(message);
|
||||
|
||||
assertTrue(new File(tmpDir.getRoot(), "foo").exists());
|
||||
assertThat(new File(tmpDir.getRoot(), "foo").exists()).isTrue();
|
||||
|
||||
this.fileTriggerFlowInput.send(new GenericMessage<>("trigger"));
|
||||
assertTrue(this.flushPredicateCalled.await(10, TimeUnit.SECONDS));
|
||||
assertThat(this.flushPredicateCalled.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,10 +182,10 @@ public class FileTests {
|
||||
this.tailer.start();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
Message<?> message = this.tailChannel.receive(5000);
|
||||
assertNotNull(message);
|
||||
assertEquals("hello " + i, message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("hello " + i);
|
||||
}
|
||||
assertNull(this.tailChannel.receive(1));
|
||||
assertThat(this.tailChannel.receive(1)).isNull();
|
||||
|
||||
this.controlBus.send("@tailer.stop()");
|
||||
file.close();
|
||||
@@ -218,18 +210,18 @@ public class FileTests {
|
||||
}
|
||||
|
||||
Message<?> message = fileReadingResultChannel.receive(60000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
Object payload = message.getPayload();
|
||||
assertThat(payload, instanceOf(List.class));
|
||||
assertThat(payload).isInstanceOf(List.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> result = (List<String>) payload;
|
||||
assertEquals(25, result.size());
|
||||
result.forEach(s -> assertTrue(evens.contains(Integer.parseInt(s))));
|
||||
assertThat(result.size()).isEqualTo(25);
|
||||
result.forEach(s -> assertThat(evens.contains(Integer.parseInt(s))).isTrue());
|
||||
|
||||
new File(tmpDir.getRoot(), "a.sitest").createNewFile();
|
||||
Message<?> receive = this.filePollingErrorChannel.receive(60000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive, instanceOf(ErrorMessage.class));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive).isInstanceOf(ErrorMessage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,15 +229,15 @@ public class FileTests {
|
||||
String payload = "Spring Integration";
|
||||
this.fileWritingInput.send(new GenericMessage<>(payload));
|
||||
Message<?> receive = this.fileWritingResultChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive.getPayload(), instanceOf(File.class));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isInstanceOf(File.class);
|
||||
File resultFile = (File) receive.getPayload();
|
||||
assertThat(resultFile.getAbsolutePath(),
|
||||
endsWith(TestUtils.applySystemFileSeparator("fileWritingFlow/foo.write")));
|
||||
assertThat(resultFile.getAbsolutePath())
|
||||
.endsWith(TestUtils.applySystemFileSeparator("fileWritingFlow/foo.write"));
|
||||
String fileContent = FileCopyUtils.copyToString(new FileReader(resultFile));
|
||||
assertEquals(payload, fileContent);
|
||||
assertThat(fileContent).isEqualTo(payload);
|
||||
if (FileUtils.IS_POSIX) {
|
||||
assertThat(java.nio.file.Files.getPosixFilePermissions(resultFile.toPath()).size(), equalTo(9));
|
||||
assertThat(java.nio.file.Files.getPosixFilePermissions(resultFile.toPath()).size()).isEqualTo(9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,19 +253,19 @@ public class FileTests {
|
||||
file.close();
|
||||
|
||||
Message<?> receive = this.fileSplittingResultChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive.getPayload(), instanceOf(FileSplitter.FileMarker.class)); // FileMarker.Mark.START
|
||||
assertEquals(0, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isInstanceOf(FileSplitter.FileMarker.class); // FileMarker.Mark.START
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(0);
|
||||
receive = this.fileSplittingResultChannel.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
receive = this.fileSplittingResultChannel.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertThat(receive).isNotNull(); //äöüß
|
||||
receive = this.fileSplittingResultChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive.getPayload(), instanceOf(FileSplitter.FileMarker.class)); // FileMarker.Mark.END
|
||||
assertNull(this.fileSplittingResultChannel.receive(1));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isInstanceOf(FileSplitter.FileMarker.class); // FileMarker.Mark.END
|
||||
assertThat(this.fileSplittingResultChannel.receive(1)).isNull();
|
||||
|
||||
assertEquals(StandardCharsets.US_ASCII, TestUtils.getPropertyValue(this.fileSplitter, "charset"));
|
||||
assertThat(TestUtils.getPropertyValue(this.fileSplitter, "charset")).isEqualTo(StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -301,13 +293,13 @@ public class FileTests {
|
||||
|
||||
Set<String> payloads = new TreeSet<>();
|
||||
Message<?> receive = this.dynamicAdaptersResult.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
payloads.add((String) receive.getPayload());
|
||||
receive = this.dynamicAdaptersResult.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
payloads.add((String) receive.getPayload());
|
||||
|
||||
assertArrayEquals(new String[] { "bar", "foo" }, payloads.toArray());
|
||||
assertThat(payloads.toArray()).isEqualTo(new String[] { "bar", "foo" });
|
||||
}
|
||||
|
||||
@MessagingGateway(defaultRequestChannel = "controlBus.input")
|
||||
|
||||
@@ -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,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -38,8 +37,8 @@ public class AbstractMarkerFilePresentFileListFilterTests {
|
||||
StringMarkerFilePresentFileListFilter filter = new StringMarkerFilePresentFileListFilter(
|
||||
new StringSimplePatternFilter("*.txt"));
|
||||
List<String> filtered = filter.filterFiles(new String[] { "foo.txt", "foo.txt.complete", "bar.txt" });
|
||||
assertThat(filtered.size(), equalTo(1));
|
||||
assertThat(filtered.get(0), equalTo("foo.txt"));
|
||||
assertThat(filtered.size()).isEqualTo(1);
|
||||
assertThat(filtered.get(0)).isEqualTo("foo.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,8 +46,8 @@ public class AbstractMarkerFilePresentFileListFilterTests {
|
||||
StringMarkerFilePresentFileListFilter filter = new StringMarkerFilePresentFileListFilter(
|
||||
new StringSimplePatternFilter("*.txt"), ".done");
|
||||
List<String> filtered = filter.filterFiles(new String[] { "foo.txt", "foo.txt.done", "bar.txt", "baz.txt" });
|
||||
assertThat(filtered.size(), equalTo(1));
|
||||
assertThat(filtered.get(0), equalTo("foo.txt"));
|
||||
assertThat(filtered.size()).isEqualTo(1);
|
||||
assertThat(filtered.get(0)).isEqualTo("foo.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,10 +55,10 @@ public class AbstractMarkerFilePresentFileListFilterTests {
|
||||
StringMarkerFilePresentFileListFilter filter = new StringMarkerFilePresentFileListFilter(
|
||||
new StringSimplePatternFilter("*.txt"), s -> "allFilesDone");
|
||||
List<String> filtered = filter.filterFiles(new String[] { "foo.txt", "bar.txt" });
|
||||
assertThat(filtered.size(), equalTo(0));
|
||||
assertThat(filtered.size()).isEqualTo(0);
|
||||
filtered = filter.filterFiles(new String[] { "foo.txt", "bar.txt", "allFilesDone" });
|
||||
assertThat(filtered.get(0), equalTo("foo.txt"));
|
||||
assertThat(filtered.get(1), equalTo("bar.txt"));
|
||||
assertThat(filtered.get(0)).isEqualTo("foo.txt");
|
||||
assertThat(filtered.get(1)).isEqualTo("bar.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,9 +71,9 @@ public class AbstractMarkerFilePresentFileListFilterTests {
|
||||
StringMarkerFilePresentFileListFilter filter = new StringMarkerFilePresentFileListFilter(map);
|
||||
List<String> filtered = filter
|
||||
.filterFiles(new String[] { "foo.txt", "foo.txt.done", "bar.xml", "bar.xml.complete", "baz.txt" });
|
||||
assertThat(filtered.size(), equalTo(2));
|
||||
assertThat(filtered.get(0), equalTo("foo.txt"));
|
||||
assertThat(filtered.get(1), equalTo("bar.xml"));
|
||||
assertThat(filtered.size()).isEqualTo(2);
|
||||
assertThat(filtered.get(0)).isEqualTo("foo.txt");
|
||||
assertThat(filtered.get(1)).isEqualTo("bar.xml");
|
||||
}
|
||||
|
||||
private static class StringSimplePatternFilter extends AbstractSimplePatternFileListFilter<String> {
|
||||
|
||||
@@ -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,12 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
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.Collections;
|
||||
@@ -36,6 +31,8 @@ import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.0.4
|
||||
*
|
||||
*/
|
||||
@@ -46,58 +43,57 @@ public class AcceptOnceFileListFilterTests {
|
||||
public void testPerformance_INT3572() {
|
||||
StopWatch watch = new StopWatch();
|
||||
watch.start();
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>();
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<>();
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
filter.accept("" + i);
|
||||
}
|
||||
watch.stop();
|
||||
assertTrue(watch.getTotalTimeMillis() < 5000);
|
||||
assertThat(watch.getTotalTimeMillis()).isLessThan(5000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCapacity() {
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>(2);
|
||||
assertTrue(filter.accept("foo"));
|
||||
assertTrue(filter.accept("bar"));
|
||||
assertFalse(filter.accept("foo"));
|
||||
assertTrue(filter.accept("baz"));
|
||||
assertTrue(filter.accept("foo"));
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<>(2);
|
||||
assertThat(filter.accept("foo")).isTrue();
|
||||
assertThat(filter.accept("bar")).isTrue();
|
||||
assertThat(filter.accept("foo")).isFalse();
|
||||
assertThat(filter.accept("baz")).isTrue();
|
||||
assertThat(filter.accept("foo")).isTrue();
|
||||
Queue<String> seen = TestUtils.getPropertyValue(filter, "seen", Queue.class);
|
||||
assertEquals(2, seen.size());
|
||||
assertThat(seen.size()).isEqualTo(2);
|
||||
Set<String> seenSet = TestUtils.getPropertyValue(filter, "seenSet", Set.class);
|
||||
assertEquals(2, seenSet.size());
|
||||
assertThat(seen, contains("baz", "foo"));
|
||||
assertThat(seenSet, containsInAnyOrder("foo", "baz"));
|
||||
assertThat(seenSet.size()).isEqualTo(2);
|
||||
assertThat(seen).containsExactly("baz", "foo");
|
||||
assertThat(seenSet).contains("foo", "baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollback() {
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>();
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<>();
|
||||
doTestRollback(filter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollbackComposite() {
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>();
|
||||
CompositeFileListFilter<String> composite = new CompositeFileListFilter<String>(
|
||||
Collections.singletonList(filter));
|
||||
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<>();
|
||||
CompositeFileListFilter<String> composite = new CompositeFileListFilter<>(Collections.singletonList(filter));
|
||||
doTestRollback(composite);
|
||||
}
|
||||
|
||||
protected void doTestRollback(ReversibleFileListFilter<String> filter) {
|
||||
String[] files = new String[] {"foo", "bar", "baz"};
|
||||
String[] files = new String[] { "foo", "bar", "baz" };
|
||||
List<String> passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
List<String> 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));
|
||||
assertEquals("baz", now.get(1));
|
||||
assertThat(now.size()).isEqualTo(2);
|
||||
assertThat(now.get(0)).isEqualTo("bar");
|
||||
assertThat(now.get(1)).isEqualTo("baz");
|
||||
now = filter.filterFiles(files);
|
||||
assertEquals(0, now.size());
|
||||
assertThat(now.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -44,7 +44,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
try (ChainFileListFilter<File> chain = new ChainFileListFilter<>()) {
|
||||
chain.addFilter(new LastModifiedFileListFilter());
|
||||
List<File> result = chain.filterFiles(noFiles);
|
||||
assertEquals(0, result.size());
|
||||
assertThat(result.size()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
try (ChainFileListFilter<File> chain = new ChainFileListFilter<>()) {
|
||||
chain.addFilter(new SimplePatternFileListFilter(PATTERN_ANY_TEXT_FILES));
|
||||
List<File> result = chain.filterFiles(oneFile);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
try (ChainFileListFilter<File> chain = new ChainFileListFilter<>()) {
|
||||
chain.addFilter(new LastModifiedFileListFilter());
|
||||
List<File> result = chain.filterFiles(oneFile);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
chain.addFilter(new SimplePatternFileListFilter(PATTERN_ANY_TEXT_FILES));
|
||||
chain.addFilter(new LastModifiedFileListFilter());
|
||||
List<File> result = chain.filterFiles(oneFile);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
chain.addFilter(new LastModifiedFileListFilter());
|
||||
chain.addFilter(new SimplePatternFileListFilter(PATTERN_ANY_TEXT_FILES));
|
||||
List<File> result = chain.filterFiles(oneFile);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ChainFileListFilterIntegrationTests {
|
||||
public void initializeFilterByConstructor() throws IOException {
|
||||
try (ChainFileListFilter<File> chain = new ChainFileListFilter<>(Arrays.asList(new SimplePatternFileListFilter(PATTERN_ANY_TEXT_FILES)))) {
|
||||
List<File> result = chain.filterFiles(oneFile);
|
||||
assertEquals(1, result.size());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,15 +16,12 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -51,13 +48,13 @@ public class CompositeFileListFilterTests {
|
||||
|
||||
@Test
|
||||
public void forwardedToFilters() throws Exception {
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<>();
|
||||
compositeFileFilter.addFilter(fileFilterMock1);
|
||||
compositeFileFilter.addFilter(fileFilterMock2);
|
||||
List<File> returnedFiles = Collections.singletonList(fileMock);
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[] { fileMock }));
|
||||
assertThat(compositeFileFilter.filterFiles(new File[] { fileMock })).isEqualTo(returnedFiles);
|
||||
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||
compositeFileFilter.close();
|
||||
@@ -65,13 +62,13 @@ public class CompositeFileListFilterTests {
|
||||
|
||||
@Test
|
||||
public void forwardedToAddedFilters() throws Exception {
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<>();
|
||||
compositeFileFilter.addFilter(fileFilterMock1);
|
||||
compositeFileFilter.addFilter(fileFilterMock2);
|
||||
List<File> returnedFiles = Collections.singletonList(fileMock);
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
|
||||
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[] { fileMock }));
|
||||
assertThat(compositeFileFilter.filterFiles(new File[] { fileMock })).isEqualTo(returnedFiles);
|
||||
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||
verify(fileFilterMock2).filterFiles(isA(File[].class));
|
||||
compositeFileFilter.close();
|
||||
@@ -79,13 +76,13 @@ public class CompositeFileListFilterTests {
|
||||
|
||||
@Test
|
||||
public void negative() throws Exception {
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<File>();
|
||||
CompositeFileListFilter<File> compositeFileFilter = new CompositeFileListFilter<>();
|
||||
compositeFileFilter.addFilter(fileFilterMock1);
|
||||
compositeFileFilter.addFilter(fileFilterMock2);
|
||||
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
|
||||
assertTrue(compositeFileFilter.filterFiles(new File[] { fileMock }).isEmpty());
|
||||
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<>());
|
||||
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<>());
|
||||
assertThat(compositeFileFilter.filterFiles(new File[] { fileMock }).isEmpty()).isTrue();
|
||||
compositeFileFilter.close();
|
||||
}
|
||||
|
||||
@@ -96,9 +93,9 @@ public class CompositeFileListFilterTests {
|
||||
compositeFileFilter.addFilter(this.fileFilterMock2);
|
||||
List<File> noFiles = new ArrayList<>();
|
||||
when(this.fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(noFiles);
|
||||
assertEquals(noFiles, compositeFileFilter.filterFiles(new File[] { this.fileMock }));
|
||||
assertThat(compositeFileFilter.filterFiles(new File[] { this.fileMock })).isEqualTo(noFiles);
|
||||
|
||||
verify(fileFilterMock1).filterFiles(argThat(arrayWithSize(1)));
|
||||
verify(fileFilterMock1).filterFiles(isA(File[].class));
|
||||
verify(fileFilterMock2, never()).filterFiles(isA(File[].class));
|
||||
|
||||
compositeFileFilter.close();
|
||||
|
||||
@@ -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,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -42,12 +41,12 @@ public class FileSystemMarkerFilePresentFileListFilterTests {
|
||||
new SimplePatternFileListFilter("*.txt"));
|
||||
File foo = this.folder.newFile("foo.txt");
|
||||
foo.createNewFile();
|
||||
assertThat(filter.filterFiles(new File[] { foo }).size(), equalTo(0));
|
||||
assertThat(filter.filterFiles(new File[] { foo }).size()).isEqualTo(0);
|
||||
File complete = this.folder.newFile("foo.txt.complete");
|
||||
complete.createNewFile();
|
||||
List<File> filtered = filter.filterFiles(new File[] { foo, complete });
|
||||
assertThat(filtered.size(), equalTo(1));
|
||||
assertThat(filtered.get(0).getName(), equalTo("foo.txt"));
|
||||
assertThat(filtered.size()).isEqualTo(1);
|
||||
assertThat(filtered.get(0).getName()).isEqualTo("foo.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -45,10 +45,10 @@ public class LastModifiedFileListFilterTests {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(foo);
|
||||
fileOutputStream.write("x".getBytes());
|
||||
fileOutputStream.close();
|
||||
assertEquals(0, filter.filterFiles(new File[] { foo }).size());
|
||||
assertThat(filter.filterFiles(new File[] { foo }).size()).isEqualTo(0);
|
||||
// Make a file as of yesterday's
|
||||
foo.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24);
|
||||
assertEquals(1, filter.filterFiles(new File[] { foo }).size());
|
||||
assertThat(filter.filterFiles(new File[] { foo }).size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
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.List;
|
||||
@@ -96,8 +95,8 @@ public class PersistentAcceptOnceFileListFilterExternalStoreTests extends RedisA
|
||||
List<Map<String, Object>> metaData = new JdbcTemplate(dataSource)
|
||||
.queryForList("SELECT * FROM INT_METADATA_STORE");
|
||||
|
||||
assertEquals(1, metaData.size());
|
||||
assertEquals("43", metaData.get(0).get("METADATA_VALUE"));
|
||||
assertThat(metaData.size()).isEqualTo(1);
|
||||
assertThat(metaData.get(0).get("METADATA_VALUE")).isEqualTo("43");
|
||||
}
|
||||
finally {
|
||||
dataSource.shutdown();
|
||||
@@ -128,26 +127,26 @@ public class PersistentAcceptOnceFileListFilterExternalStoreTests extends RedisA
|
||||
final FileSystemPersistentAcceptOnceFileListFilter filter =
|
||||
new FileSystemPersistentAcceptOnceFileListFilter(store, "foo:");
|
||||
final File file = File.createTempFile("foo", ".txt");
|
||||
assertEquals(1, filter.filterFiles(new File[] { file }).size());
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(1);
|
||||
String ts = store.get("foo:" + file.getAbsolutePath());
|
||||
assertEquals(String.valueOf(file.lastModified()), ts);
|
||||
assertEquals(0, filter.filterFiles(new File[] { file }).size());
|
||||
assertThat(ts).isEqualTo(String.valueOf(file.lastModified()));
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(0);
|
||||
file.setLastModified(file.lastModified() + 5000L);
|
||||
assertEquals(1, filter.filterFiles(new File[] { file }).size());
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(1);
|
||||
ts = store.get("foo:" + file.getAbsolutePath());
|
||||
assertEquals(String.valueOf(file.lastModified()), ts);
|
||||
assertEquals(0, filter.filterFiles(new File[] { file }).size());
|
||||
assertThat(ts).isEqualTo(String.valueOf(file.lastModified()));
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(0);
|
||||
|
||||
suspend.set(true);
|
||||
file.setLastModified(file.lastModified() + 5000L);
|
||||
|
||||
Future<Integer> result = Executors.newSingleThreadExecutor()
|
||||
.submit(() -> filter.filterFiles(new File[] { file }).size());
|
||||
assertTrue(latch2.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
store.put("foo:" + file.getAbsolutePath(), "43");
|
||||
latch1.countDown();
|
||||
Integer theResult = result.get(10, TimeUnit.SECONDS);
|
||||
assertEquals(Integer.valueOf(0), theResult); // lost the race, key changed
|
||||
assertThat(theResult).isEqualTo(Integer.valueOf(0)); // lost the race, key changed
|
||||
|
||||
file.delete();
|
||||
filter.close();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@@ -71,15 +69,15 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
final FileSystemPersistentAcceptOnceFileListFilter filter =
|
||||
new FileSystemPersistentAcceptOnceFileListFilter(store, "foo:");
|
||||
final File file = File.createTempFile("foo", ".txt");
|
||||
assertEquals(1, filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(1);
|
||||
String ts = store.get("foo:" + file.getAbsolutePath());
|
||||
assertEquals(String.valueOf(file.lastModified()), ts);
|
||||
assertEquals(0, filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(ts).isEqualTo(String.valueOf(file.lastModified()));
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(0);
|
||||
file.setLastModified(file.lastModified() + 5000L);
|
||||
assertEquals(1, filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(1);
|
||||
ts = store.get("foo:" + file.getAbsolutePath());
|
||||
assertEquals(String.valueOf(file.lastModified()), ts);
|
||||
assertEquals(0, filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(ts).isEqualTo(String.valueOf(file.lastModified()));
|
||||
assertThat(filter.filterFiles(new File[] { file }).size()).isEqualTo(0);
|
||||
|
||||
suspend.set(true);
|
||||
file.setLastModified(file.lastModified() + 5000L);
|
||||
@@ -91,11 +89,11 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
return filter.filterFiles(new File[] {file}).size();
|
||||
}
|
||||
});
|
||||
assertTrue(latch2.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
store.put("foo:" + file.getAbsolutePath(), "43");
|
||||
latch1.countDown();
|
||||
Integer theResult = result.get(10, TimeUnit.SECONDS);
|
||||
assertEquals(Integer.valueOf(0), theResult); // lost the race, key changed
|
||||
assertThat(theResult).isEqualTo(Integer.valueOf(0)); // lost the race, key changed
|
||||
|
||||
file.delete();
|
||||
filter.close();
|
||||
@@ -126,21 +124,21 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
new SimpleMetadataStore(), "rollback:");
|
||||
File[] files = new File[] {new File("foo"), new File("bar"), new File("baz")};
|
||||
List<File> passed = filter.filterFiles(files);
|
||||
assertEquals(0, passed.size());
|
||||
assertThat(passed.size()).isEqualTo(0);
|
||||
for (File file : files) {
|
||||
file.createNewFile();
|
||||
}
|
||||
passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
List<File> now = filter.filterFiles(files);
|
||||
assertEquals(0, now.size());
|
||||
assertThat(now.size()).isEqualTo(0);
|
||||
filter.rollback(passed.get(1), passed);
|
||||
now = filter.filterFiles(files);
|
||||
assertEquals(2, now.size());
|
||||
assertEquals("bar", now.get(0).getName());
|
||||
assertEquals("baz", now.get(1).getName());
|
||||
assertThat(now.size()).isEqualTo(2);
|
||||
assertThat(now.get(0).getName()).isEqualTo("bar");
|
||||
assertThat(now.get(1).getName()).isEqualTo("baz");
|
||||
now = filter.filterFiles(files);
|
||||
assertEquals(0, now.size());
|
||||
assertThat(now.size()).isEqualTo(0);
|
||||
filter.close();
|
||||
for (File file : files) {
|
||||
file.delete();
|
||||
@@ -180,30 +178,30 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
final File file = File.createTempFile("foo", ".txt");
|
||||
File[] files = new File[] { file };
|
||||
List<File> passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
filter.rollback(passed.get(0), passed);
|
||||
assertEquals(0, flushes.get());
|
||||
assertThat(flushes.get()).isEqualTo(0);
|
||||
filter.setFlushOnUpdate(true);
|
||||
passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertEquals(1, flushes.get());
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
assertThat(flushes.get()).isEqualTo(1);
|
||||
filter.rollback(passed.get(0), passed);
|
||||
assertEquals(2, flushes.get());
|
||||
assertThat(flushes.get()).isEqualTo(2);
|
||||
passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertEquals(3, flushes.get());
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
assertThat(flushes.get()).isEqualTo(3);
|
||||
passed = filter.filterFiles(files);
|
||||
assertEquals(0, passed.size());
|
||||
assertEquals(3, flushes.get());
|
||||
assertFalse(replaced.get());
|
||||
assertThat(passed.size()).isEqualTo(0);
|
||||
assertThat(flushes.get()).isEqualTo(3);
|
||||
assertThat(replaced.get()).isFalse();
|
||||
store.put(prefix + file.getAbsolutePath(), "1");
|
||||
passed = filter.filterFiles(files);
|
||||
assertTrue(Arrays.equals(files, passed.toArray()));
|
||||
assertEquals(4, flushes.get());
|
||||
assertTrue(replaced.get());
|
||||
assertThat(Arrays.equals(files, passed.toArray())).isTrue();
|
||||
assertThat(flushes.get()).isEqualTo(4);
|
||||
assertThat(replaced.get()).isTrue();
|
||||
file.delete();
|
||||
filter.close();
|
||||
assertEquals(5, flushes.get());
|
||||
assertThat(flushes.get()).isEqualTo(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -32,17 +31,17 @@ public class SimplePatternFileListFilterTests {
|
||||
|
||||
@Test
|
||||
public void shouldMatchExactly() {
|
||||
assertThat(new SimplePatternFileListFilter("bar").accept(new File("bar")), is(true));
|
||||
assertThat(new SimplePatternFileListFilter("bar").accept(new File("bar"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMatchQuestionMark() {
|
||||
assertThat(new SimplePatternFileListFilter("*bar").accept(new File("bar")), is(true));
|
||||
assertThat(new SimplePatternFileListFilter("*bar").accept(new File("bar"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMatchWildcard() {
|
||||
assertThat(new SimplePatternFileListFilter("ba?").accept(new File("bar")), is(true));
|
||||
assertThat(new SimplePatternFileListFilter("ba?").accept(new File("bar"))).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -68,8 +66,8 @@ public class FileLockingNamespaceTests {
|
||||
|
||||
@Test
|
||||
public void shouldSetCustomLockerProperly() {
|
||||
assertThat(extractFromScanner("locker", customLockingSource), is(instanceOf(StubLocker.class)));
|
||||
assertThat(extractFromScanner("filter", customLockingSource), is(instanceOf(CompositeFileListFilter.class)));
|
||||
assertThat(extractFromScanner("locker", customLockingSource)).isInstanceOf(StubLocker.class);
|
||||
assertThat(extractFromScanner("filter", customLockingSource)).isInstanceOf(CompositeFileListFilter.class);
|
||||
}
|
||||
|
||||
private Object extractFromScanner(String propertyName, FileReadingMessageSource source) {
|
||||
@@ -78,8 +76,8 @@ public class FileLockingNamespaceTests {
|
||||
|
||||
@Test
|
||||
public void shouldSetNioLockerProperly() {
|
||||
assertThat(extractFromScanner("locker", nioLockingSource), is(instanceOf(NioFileLocker.class)));
|
||||
assertThat(extractFromScanner("filter", nioLockingSource), is(instanceOf(CompositeFileListFilter.class)));
|
||||
assertThat(extractFromScanner("locker", nioLockingSource)).isInstanceOf(NioFileLocker.class);
|
||||
assertThat(extractFromScanner("filter", nioLockingSource)).isInstanceOf(CompositeFileListFilter.class);
|
||||
}
|
||||
|
||||
public static class StubLocker extends AbstractFileLockerFilter {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.locking;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -31,6 +29,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
@@ -72,8 +71,11 @@ public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||
public void filePickedUpOnceWithDistinctFilters() throws IOException {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource2.receive(), nullValue());
|
||||
assertThat(this.fileSource1.receive())
|
||||
.isNotNull()
|
||||
.extracting(Message::getPayload)
|
||||
.isEqualTo(testFile);
|
||||
assertThat(this.fileSource2.receive()).isNull();
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
|
||||
@@ -81,8 +83,14 @@ public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||
public void filePickedUpTwiceWithSharedFilter() throws Exception {
|
||||
File testFile = new File(workdir, "test");
|
||||
testFile.createNewFile();
|
||||
assertThat(fileSource1.receive(), hasPayload(testFile));
|
||||
assertThat(fileSource3.receive(), hasPayload(testFile));
|
||||
assertThat(this.fileSource1.receive())
|
||||
.isNotNull()
|
||||
.extracting(Message::getPayload)
|
||||
.isEqualTo(testFile);
|
||||
assertThat(this.fileSource3.receive())
|
||||
.isNotNull()
|
||||
.extracting(Message::getPayload)
|
||||
.isEqualTo(testFile);
|
||||
FileChannelCache.closeChannelFor(testFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.file.locking;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -52,9 +51,9 @@ public class NioFileLockerTests {
|
||||
NioFileLocker filter = new NioFileLocker();
|
||||
File testFile = new File(workdir, "test0");
|
||||
testFile.createNewFile();
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0)).isEqualTo(testFile);
|
||||
filter.lock(testFile);
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter.filterFiles(workdir.listFiles()).get(0)).isEqualTo(testFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,9 +62,9 @@ public class NioFileLockerTests {
|
||||
FileListFilter<File> filter2 = new NioFileLocker();
|
||||
File testFile = new File(workdir, "test1");
|
||||
testFile.createNewFile();
|
||||
assertThat(filter1.filterFiles(workdir.listFiles()).get(0), is(testFile));
|
||||
assertThat(filter1.filterFiles(workdir.listFiles()).get(0)).isEqualTo(testFile);
|
||||
filter1.lock(testFile);
|
||||
assertThat(filter2.filterFiles(workdir.listFiles()), is((List<File>) new ArrayList<File>()));
|
||||
assertThat(filter2.filterFiles(workdir.listFiles())).isEqualTo((List<File>) new ArrayList<File>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,10 @@
|
||||
|
||||
package org.springframework.integration.file.remote;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
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.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -26,12 +28,10 @@ import static org.mockito.Mockito.when;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
@@ -43,6 +43,8 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1.7
|
||||
*
|
||||
*/
|
||||
@@ -61,7 +63,7 @@ public class RemoteFileTemplateTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
SessionFactory<Object> sessionFactory = mock(SessionFactory.class);
|
||||
this.template = new RemoteFileTemplate<Object>(sessionFactory);
|
||||
this.template = new RemoteFileTemplate<>(sessionFactory);
|
||||
this.template.setRemoteDirectoryExpression(new LiteralExpression("/foo"));
|
||||
this.template.setBeanFactory(mock(BeanFactory.class));
|
||||
this.template.afterPropertiesSet();
|
||||
@@ -72,49 +74,49 @@ public class RemoteFileTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testReplace() throws Exception {
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.REPLACE);
|
||||
verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.REPLACE);
|
||||
verify(this.session).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppend() throws Exception {
|
||||
this.template.setUseTemporaryFileName(false);
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.APPEND);
|
||||
verify(this.session).append(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.APPEND);
|
||||
verify(this.session).append(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailExists() throws Exception {
|
||||
when(session.exists(Mockito.anyString())).thenReturn(true);
|
||||
when(session.exists(anyString())).thenReturn(true);
|
||||
try {
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.FAIL);
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.FAIL);
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), Matchers.containsString("The destination file already exists"));
|
||||
assertThat(e.getMessage()).contains("The destination file already exists");
|
||||
}
|
||||
verify(this.session, never()).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
verify(this.session, never()).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreExists() throws Exception {
|
||||
when(session.exists(Mockito.anyString())).thenReturn(true);
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.IGNORE);
|
||||
verify(this.session, never()).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
when(session.exists(anyString())).thenReturn(true);
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.IGNORE);
|
||||
verify(this.session, never()).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailNotExists() throws Exception {
|
||||
when(session.exists(Mockito.anyString())).thenReturn(false);
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.FAIL);
|
||||
verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
when(session.exists(anyString())).thenReturn(false);
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.FAIL);
|
||||
verify(this.session).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreNotExists() throws Exception {
|
||||
when(session.exists(Mockito.anyString())).thenReturn(false);
|
||||
this.template.send(new GenericMessage<File>(this.file), FileExistsMode.IGNORE);
|
||||
verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
when(session.exists(anyString())).thenReturn(false);
|
||||
this.template.send(new GenericMessage<>(this.file), FileExistsMode.IGNORE);
|
||||
verify(this.session).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,10 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.remote;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willReturn;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
@@ -35,9 +33,7 @@ import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
@@ -54,14 +50,13 @@ import org.springframework.messaging.MessagingException;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.3
|
||||
*
|
||||
*/
|
||||
public class StreamingInboundTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private final StreamTransformer transformer = new StreamTransformer();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -73,33 +68,33 @@ public class StreamingInboundTests {
|
||||
streamer.setRemoteDirectory("/foo");
|
||||
streamer.afterPropertiesSet();
|
||||
Message<byte[]> received = (Message<byte[]>) this.transformer.transform(streamer.receive());
|
||||
assertEquals("foo\nbar", new String(received.getPayload()));
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(received.getPayload()).isEqualTo("foo\nbar".getBytes());
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
String fileInfo = (String) received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO);
|
||||
assertThat(fileInfo, containsString("remoteDirectory\":\"/foo"));
|
||||
assertThat(fileInfo, containsString("permissions\":\"-rw-rw-rw"));
|
||||
assertThat(fileInfo, containsString("size\":42"));
|
||||
assertThat(fileInfo, containsString("directory\":false"));
|
||||
assertThat(fileInfo, containsString("filename\":\"foo"));
|
||||
assertThat(fileInfo, containsString("modified\":42000"));
|
||||
assertThat(fileInfo, containsString("link\":false"));
|
||||
assertThat(fileInfo).contains("remoteDirectory\":\"/foo");
|
||||
assertThat(fileInfo).contains("permissions\":\"-rw-rw-rw");
|
||||
assertThat(fileInfo).contains("size\":42");
|
||||
assertThat(fileInfo).contains("directory\":false");
|
||||
assertThat(fileInfo).contains("filename\":\"foo");
|
||||
assertThat(fileInfo).contains("modified\":42000");
|
||||
assertThat(fileInfo).contains("link\":false");
|
||||
|
||||
// close after list, transform
|
||||
verify(StaticMessageHeaderAccessor.getCloseableResource(received), times(2)).close();
|
||||
|
||||
received = (Message<byte[]>) this.transformer.transform(streamer.receive());
|
||||
assertEquals("baz\nqux", new String(received.getPayload()));
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(received.getPayload()).isEqualTo("baz\nqux".getBytes());
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("bar");
|
||||
fileInfo = (String) received.getHeaders().get(FileHeaders.REMOTE_FILE_INFO);
|
||||
assertThat(fileInfo, containsString("remoteDirectory\":\"/foo"));
|
||||
assertThat(fileInfo, containsString("permissions\":\"-rw-rw-rw"));
|
||||
assertThat(fileInfo, containsString("size\":42"));
|
||||
assertThat(fileInfo, containsString("directory\":false"));
|
||||
assertThat(fileInfo, containsString("filename\":\"bar"));
|
||||
assertThat(fileInfo, containsString("modified\":42000"));
|
||||
assertThat(fileInfo, containsString("link\":false"));
|
||||
assertThat(fileInfo).contains("remoteDirectory\":\"/foo");
|
||||
assertThat(fileInfo).contains("permissions\":\"-rw-rw-rw");
|
||||
assertThat(fileInfo).contains("size\":42");
|
||||
assertThat(fileInfo).contains("directory\":false");
|
||||
assertThat(fileInfo).contains("filename\":\"bar");
|
||||
assertThat(fileInfo).contains("modified\":42000");
|
||||
assertThat(fileInfo).contains("link\":false");
|
||||
|
||||
// close after transform
|
||||
verify(StaticMessageHeaderAccessor.getCloseableResource(received), times(3)).close();
|
||||
@@ -118,17 +113,17 @@ public class StreamingInboundTests {
|
||||
streamer.setFilter(new AcceptOnceFileListFilter<>());
|
||||
streamer.afterPropertiesSet();
|
||||
Message<byte[]> received = (Message<byte[]>) this.transformer.transform(streamer.receive());
|
||||
assertEquals("foo\nbar", new String(received.getPayload()));
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(received.getPayload()).isEqualTo("foo\nbar".getBytes());
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
|
||||
// close after list, transform
|
||||
verify(StaticMessageHeaderAccessor.getCloseableResource(received), times(2)).close();
|
||||
|
||||
received = (Message<byte[]>) this.transformer.transform(streamer.receive());
|
||||
assertEquals("baz\nqux", new String(received.getPayload()));
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(received.getPayload()).isEqualTo("baz\nqux".getBytes());
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("bar");
|
||||
|
||||
// close after list, transform
|
||||
verify(new IntegrationMessageHeaderAccessor(received).getCloseableResource(), times(4)).close();
|
||||
@@ -138,13 +133,13 @@ public class StreamingInboundTests {
|
||||
|
||||
@Test
|
||||
public void testExceptionOnFetch() throws Exception {
|
||||
exception.expect(MessagingException.class);
|
||||
StringSessionFactory sessionFactory = new StringSessionFactory();
|
||||
Streamer streamer = new Streamer(new StringRemoteFileTemplate(sessionFactory), null);
|
||||
streamer.setBeanFactory(mock(BeanFactory.class));
|
||||
streamer.setRemoteDirectory("/bad");
|
||||
streamer.afterPropertiesSet();
|
||||
streamer.receive();
|
||||
assertThatThrownBy(streamer::receive)
|
||||
.isInstanceOf(MessagingException.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -161,30 +156,30 @@ public class StreamingInboundTests {
|
||||
splitter.afterPropertiesSet();
|
||||
Message<InputStream> receivedStream = streamer.receive();
|
||||
splitter.handleMessage(receivedStream);
|
||||
Message<byte[]> received = (Message<byte[]>) out.receive(0);
|
||||
assertEquals("foo", received.getPayload());
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
Message<?> received = out.receive(0);
|
||||
assertThat(received.getPayload()).isEqualTo("foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
received = (Message<byte[]>) out.receive(0);
|
||||
assertEquals("bar", received.getPayload());
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertNull(out.receive(0));
|
||||
assertThat(received.getPayload()).isEqualTo("bar");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
assertThat(out.receive(0)).isNull();
|
||||
|
||||
// close by list, splitter
|
||||
verify(new IntegrationMessageHeaderAccessor(receivedStream).getCloseableResource(), times(3)).close();
|
||||
|
||||
receivedStream = streamer.receive();
|
||||
splitter.handleMessage(receivedStream);
|
||||
received = (Message<byte[]>) out.receive(0);
|
||||
assertEquals("baz", received.getPayload());
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
received = (Message<byte[]>) out.receive(0);
|
||||
assertEquals("qux", received.getPayload());
|
||||
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertNull(out.receive(0));
|
||||
received = out.receive(0);
|
||||
assertThat(received.getPayload()).isEqualTo("baz");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("bar");
|
||||
received = out.receive(0);
|
||||
assertThat(received.getPayload()).isEqualTo("qux");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("/foo");
|
||||
assertThat(received.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("bar");
|
||||
assertThat(out.receive(0)).isNull();
|
||||
|
||||
// close by splitter
|
||||
verify(new IntegrationMessageHeaderAccessor(receivedStream).getCloseableResource(), times(5)).close();
|
||||
@@ -203,7 +198,7 @@ public class StreamingInboundTests {
|
||||
|
||||
@Override
|
||||
protected List<AbstractFileInfo<String>> asFileInfoList(Collection<String> files) {
|
||||
List<AbstractFileInfo<String>> infos = new ArrayList<AbstractFileInfo<String>>();
|
||||
List<AbstractFileInfo<String>> infos = new ArrayList<>();
|
||||
for (String file : files) {
|
||||
infos.add(new StringFileInfo(file));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,18 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.remote.gateway;
|
||||
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -92,14 +82,14 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBad() throws Exception {
|
||||
public void testBad() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "bad", "payload");
|
||||
gw.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadFilterGet() throws Exception {
|
||||
public void testBadFilterGet() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "get", "payload");
|
||||
gw.setFilter(new TestPatternFilter(""));
|
||||
@@ -108,12 +98,12 @@ public class RemoteFileOutboundGatewayTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().startsWith("Filters are not supported"));
|
||||
assertThat(e.getMessage().startsWith("Filters are not supported")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadFilterRm() throws Exception {
|
||||
public void testBadFilterRm() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "rm", "payload");
|
||||
gw.setFilter(new TestPatternFilter(""));
|
||||
@@ -122,7 +112,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().startsWith("Filters are not supported"));
|
||||
assertThat(e.getMessage().startsWith("Filters are not supported")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,15 +128,14 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/x"));
|
||||
assertEquals(2, out.getPayload().size());
|
||||
assertSame(files[1], out.getPayload().get(0)); // sort by default
|
||||
assertSame(files[0], out.getPayload().get(1));
|
||||
assertEquals("testremote/x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(2);
|
||||
assertThat(out.getPayload().get(0)).isSameAs(files[1]); // sort by default
|
||||
assertThat(out.getPayload().get(1)).isSameAs(files[0]);
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/x/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMGetWild() throws Exception {
|
||||
public void testMGetWild() {
|
||||
testMGetWildGuts("f1", "f2");
|
||||
}
|
||||
|
||||
@@ -156,7 +145,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testMGetWildFullPath() throws Exception {
|
||||
public void testMGetWildFullPath() {
|
||||
testMGetWildGuts("testremote/f1", "testremote/f2");
|
||||
}
|
||||
|
||||
@@ -175,34 +164,34 @@ public class RemoteFileOutboundGatewayTests {
|
||||
public void read(String source, OutputStream outputStream)
|
||||
throws IOException {
|
||||
if (n++ == 0) {
|
||||
assertEquals("testremote/f1", source);
|
||||
assertThat(source).isEqualTo("testremote/f1");
|
||||
}
|
||||
else {
|
||||
assertEquals("testremote/f2", source);
|
||||
assertThat(source).isEqualTo("testremote/f2");
|
||||
}
|
||||
outputStream.write("testData".getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry(path1.replaceFirst("testremote/", ""), 123, false, false, 1234, "-r--r--r--"),
|
||||
new TestLsEntry(path2.replaceFirst("testremote/", ""), 123, false, false, 1234, "-r--r--r--") };
|
||||
new TestLsEntry(path2.replaceFirst("testremote/", ""), 123, false, false, 1234,
|
||||
"-r--r--r--") };
|
||||
}
|
||||
|
||||
});
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<File>> out = (MessageBuilder<List<File>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/*"));
|
||||
assertEquals(2, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0).getName());
|
||||
assertEquals("f2", out.getPayload().get(1).getName());
|
||||
assertEquals("testremote/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(2);
|
||||
assertThat(out.getPayload().get(0).getName()).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1).getName()).isEqualTo("f2");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMGetSingle() throws Exception {
|
||||
public void testMGetSingle() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mget", "payload");
|
||||
gw.setLocalDirectory(new File(this.tmpDir));
|
||||
@@ -217,7 +206,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] { new TestLsEntry("f1", 123, false, false, 1234, "-r--r--r--") };
|
||||
}
|
||||
|
||||
@@ -225,14 +214,13 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<File>> out = (MessageBuilder<List<File>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/f1"));
|
||||
assertEquals(1, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0).getName());
|
||||
assertEquals("testremote/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(1);
|
||||
assertThat(out.getPayload().get(0).getName()).isEqualTo("f1");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/");
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void testMGetEmpty() throws Exception {
|
||||
public void testMGetEmpty() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mget", "payload");
|
||||
gw.setLocalDirectory(new File(this.tmpDir));
|
||||
@@ -249,7 +237,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}
|
||||
|
||||
});
|
||||
gw.handleRequestMessage(new GenericMessage<String>("testremote/*"));
|
||||
gw.handleRequestMessage(new GenericMessage<>("testremote/*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,10 +246,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mv", "payload");
|
||||
gw.afterPropertiesSet();
|
||||
Session<?> session = mock(Session.class);
|
||||
final AtomicReference<String> args = new AtomicReference<String>();
|
||||
final AtomicReference<String> args = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
args.set((String) arguments[0] + (String) arguments[1]);
|
||||
args.set((String) arguments[0] + arguments[1]);
|
||||
return null;
|
||||
}).when(session).rename(anyString(), anyString());
|
||||
when(sessionFactory.getSession()).thenReturn(session);
|
||||
@@ -269,9 +257,9 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.setHeader(FileHeaders.RENAME_TO, "bar")
|
||||
.build();
|
||||
MessageBuilder<?> out = (MessageBuilder<?>) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo", out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertEquals("foobar", args.get());
|
||||
assertEquals(Boolean.TRUE, out.getPayload());
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
assertThat(args.get()).isEqualTo("foobar");
|
||||
assertThat(out.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,7 +269,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
gw.setRenameExpression(PARSER.parseExpression("payload.substring(1)"));
|
||||
gw.afterPropertiesSet();
|
||||
Session<?> session = mock(Session.class);
|
||||
final AtomicReference<String> args = new AtomicReference<String>();
|
||||
final AtomicReference<String> args = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
args.set((String) arguments[0] + arguments[1]);
|
||||
@@ -289,10 +277,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}).when(session).rename(anyString(), anyString());
|
||||
when(sessionFactory.getSession()).thenReturn(session);
|
||||
MessageBuilder<?> out = (MessageBuilder<?>) gw.handleRequestMessage(new GenericMessage<>("foo"));
|
||||
assertEquals("oo", out.getHeaders().get(FileHeaders.RENAME_TO));
|
||||
assertEquals("foo", out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertEquals("foooo", args.get());
|
||||
assertEquals(Boolean.TRUE, out.getPayload());
|
||||
assertThat(out.getHeaders().get(FileHeaders.RENAME_TO)).isEqualTo("oo");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
assertThat(args.get()).isEqualTo("foooo");
|
||||
assertThat(out.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,13 +290,13 @@ public class RemoteFileOutboundGatewayTests {
|
||||
gw.setRenameExpression(PARSER.parseExpression("'foo/bar/baz'"));
|
||||
gw.afterPropertiesSet();
|
||||
Session<?> session = mock(Session.class);
|
||||
final AtomicReference<String> args = new AtomicReference<String>();
|
||||
final AtomicReference<String> args = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
args.set((String) arguments[0] + (String) arguments[1]);
|
||||
args.set((String) arguments[0] + arguments[1]);
|
||||
return null;
|
||||
}).when(session).rename(anyString(), anyString());
|
||||
final List<String> madeDirs = new ArrayList<String>();
|
||||
final List<String> madeDirs = new ArrayList<>();
|
||||
doAnswer(invocation -> {
|
||||
madeDirs.add(invocation.getArgument(0));
|
||||
return null;
|
||||
@@ -318,12 +306,12 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.setHeader(FileHeaders.RENAME_TO, "bar")
|
||||
.build();
|
||||
MessageBuilder<?> out = (MessageBuilder<?>) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo", out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertEquals("foofoo/bar/baz", args.get());
|
||||
assertEquals(Boolean.TRUE, out.getPayload());
|
||||
assertEquals(2, madeDirs.size());
|
||||
assertEquals("foo", madeDirs.get(0));
|
||||
assertEquals("foo/bar", madeDirs.get(1));
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("foo");
|
||||
assertThat(args.get()).isEqualTo("foofoo/bar/baz");
|
||||
assertThat(out.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(madeDirs.size()).isEqualTo(2);
|
||||
assertThat(madeDirs.get(0)).isEqualTo("foo");
|
||||
assertThat(madeDirs.get(1)).isEqualTo("foo/bar");
|
||||
}
|
||||
|
||||
public TestLsEntry[] fileList() {
|
||||
@@ -350,11 +338,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/x"));
|
||||
assertEquals(2, out.getPayload().size());
|
||||
assertSame(files[0], out.getPayload().get(0));
|
||||
assertSame(files[1], out.getPayload().get(1));
|
||||
assertEquals("testremote/x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(2);
|
||||
assertThat(out.getPayload().get(0)).isSameAs(files[0]);
|
||||
assertThat(out.getPayload().get(1)).isSameAs(files[1]);
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/x/");
|
||||
}
|
||||
|
||||
public TestLsEntry[] level1List() {
|
||||
@@ -395,13 +382,12 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/x"));
|
||||
assertEquals(4, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0).getFilename());
|
||||
assertEquals("d1/d2/f4", out.getPayload().get(1).getFilename());
|
||||
assertEquals("d1/f3", out.getPayload().get(2).getFilename());
|
||||
assertEquals("f2", out.getPayload().get(3).getFilename());
|
||||
assertEquals("testremote/x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(4);
|
||||
assertThat(out.getPayload().get(0).getFilename()).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1).getFilename()).isEqualTo("d1/d2/f4");
|
||||
assertThat(out.getPayload().get(2).getFilename()).isEqualTo("d1/f3");
|
||||
assertThat(out.getPayload().get(3).getFilename()).isEqualTo("f2");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/x/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -421,14 +407,13 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/x"));
|
||||
assertEquals(5, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0).getFilename());
|
||||
assertEquals("d1", out.getPayload().get(1).getFilename());
|
||||
assertEquals("d1/d2", out.getPayload().get(2).getFilename());
|
||||
assertEquals("d1/f3", out.getPayload().get(3).getFilename());
|
||||
assertEquals("f2", out.getPayload().get(4).getFilename());
|
||||
assertEquals("testremote/x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertThat(out.getPayload().size()).isEqualTo(5);
|
||||
assertThat(out.getPayload().get(0).getFilename()).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1).getFilename()).isEqualTo("d1");
|
||||
assertThat(out.getPayload().get(2).getFilename()).isEqualTo("d1/d2");
|
||||
assertThat(out.getPayload().get(3).getFilename()).isEqualTo("d1/f3");
|
||||
assertThat(out.getPayload().get(4).getFilename()).isEqualTo("f2");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/x/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -443,7 +428,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(0, out.getPayload().size());
|
||||
assertThat(out.getPayload().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -459,9 +444,9 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(2, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0));
|
||||
assertEquals("f2", out.getPayload().get(1));
|
||||
assertThat(out.getPayload().size()).isEqualTo(2);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1)).isEqualTo("f2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -477,9 +462,9 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(2, out.getPayload().size());
|
||||
assertEquals("f2", out.getPayload().get(0));
|
||||
assertEquals("f1", out.getPayload().get(1));
|
||||
assertThat(out.getPayload().size()).isEqualTo(2);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f2");
|
||||
assertThat(out.getPayload().get(1)).isEqualTo("f1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -495,10 +480,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(3, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0));
|
||||
assertEquals("f2", out.getPayload().get(1));
|
||||
assertEquals("f3", out.getPayload().get(2));
|
||||
assertThat(out.getPayload().size()).isEqualTo(3);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1)).isEqualTo("f2");
|
||||
assertThat(out.getPayload().get(2)).isEqualTo("f3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -514,11 +499,11 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(4, out.getPayload().size());
|
||||
assertEquals("f1", out.getPayload().get(0));
|
||||
assertEquals("f2", out.getPayload().get(1));
|
||||
assertEquals("f3", out.getPayload().get(2));
|
||||
assertEquals("f4", out.getPayload().get(3));
|
||||
assertThat(out.getPayload().size()).isEqualTo(4);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(1)).isEqualTo("f2");
|
||||
assertThat(out.getPayload().get(2)).isEqualTo("f3");
|
||||
assertThat(out.getPayload().get(3)).isEqualTo("f4");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -534,13 +519,13 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(6, out.getPayload().size());
|
||||
assertEquals("f2", out.getPayload().get(0));
|
||||
assertEquals("f1", out.getPayload().get(1));
|
||||
assertEquals("f3", out.getPayload().get(2));
|
||||
assertEquals("f4", out.getPayload().get(3));
|
||||
assertEquals(".f5", out.getPayload().get(4));
|
||||
assertEquals(".f6", out.getPayload().get(5));
|
||||
assertThat(out.getPayload().size()).isEqualTo(6);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f2");
|
||||
assertThat(out.getPayload().get(1)).isEqualTo("f1");
|
||||
assertThat(out.getPayload().get(2)).isEqualTo("f3");
|
||||
assertThat(out.getPayload().get(3)).isEqualTo("f4");
|
||||
assertThat(out.getPayload().get(4)).isEqualTo(".f5");
|
||||
assertThat(out.getPayload().get(5)).isEqualTo(".f6");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -557,8 +542,8 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote"));
|
||||
assertEquals(1, out.getPayload().size());
|
||||
assertEquals("f4", out.getPayload().get(0));
|
||||
assertThat(out.getPayload().size()).isEqualTo(1);
|
||||
assertThat(out.getPayload().get(0)).isEqualTo("f4");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -571,7 +556,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
when(sessionFactory.getSession()).thenReturn(new TestSession() {
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
|
||||
};
|
||||
@@ -587,11 +572,11 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<File> out = (MessageBuilder<File>) gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
File outFile = new File(this.tmpDir + "/f1");
|
||||
assertEquals(outFile, out.getPayload());
|
||||
assertTrue(outFile.exists());
|
||||
assertThat(out.getPayload()).isEqualTo(outFile);
|
||||
assertThat(outFile.exists()).isTrue();
|
||||
outFile.delete();
|
||||
assertNull(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("f1", out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isNull();
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("f1");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -608,7 +593,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
when(sessionFactory.getSession()).thenReturn(new TestSession() {
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
|
||||
};
|
||||
@@ -629,7 +614,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getMessage(), containsString("already exists"));
|
||||
assertThat(e.getMessage()).contains("already exists");
|
||||
}
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.FAIL);
|
||||
@@ -638,22 +623,22 @@ public class RemoteFileOutboundGatewayTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getMessage(), containsString("already exists"));
|
||||
assertThat(e.getMessage()).contains("already exists");
|
||||
}
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.IGNORE);
|
||||
out = (MessageBuilder<File>) gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
assertEquals(outFile, out.getPayload());
|
||||
assertThat(out.getPayload()).isEqualTo(outFile);
|
||||
assertContents("foo", outFile);
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.APPEND);
|
||||
out = (MessageBuilder<File>) gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
assertEquals(outFile, out.getPayload());
|
||||
assertThat(out.getPayload()).isEqualTo(outFile);
|
||||
assertContents("footestfile", outFile);
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.REPLACE);
|
||||
out = (MessageBuilder<File>) gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
assertEquals(outFile, out.getPayload());
|
||||
assertThat(out.getPayload()).isEqualTo(outFile);
|
||||
assertContents("testfile", outFile);
|
||||
|
||||
outFile.delete();
|
||||
@@ -661,12 +646,12 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
private void assertContents(String expected, File outFile) throws Exception {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(outFile));
|
||||
assertEquals(expected, reader.readLine());
|
||||
assertThat(reader.readLine()).isEqualTo(expected);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTempFileDelete() throws Exception {
|
||||
public void testGetTempFileDelete() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "get", "payload");
|
||||
gw.setLocalDirectory(new File(this.tmpDir));
|
||||
@@ -675,7 +660,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
when(sessionFactory.getSession()).thenReturn(new TestSession() {
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
|
||||
};
|
||||
@@ -688,22 +673,22 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
});
|
||||
try {
|
||||
gw.handleRequestMessage(new GenericMessage<String>("f1"));
|
||||
gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getCause(), instanceOf(RuntimeException.class));
|
||||
assertEquals("test remove .writing", e.getCause().getMessage());
|
||||
assertThat(e.getCause()).isInstanceOf(RuntimeException.class);
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("test remove .writing");
|
||||
@SuppressWarnings("unchecked")
|
||||
RemoteFileTemplate template = new RemoteFileTemplate(sessionFactory);
|
||||
File outFile = new File(this.tmpDir + "/f1" + template.getTemporaryFileSuffix());
|
||||
assertFalse(outFile.exists());
|
||||
assertThat(outFile.exists()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGet_P() throws Exception {
|
||||
public void testGet_P() {
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "get", "payload");
|
||||
gw.setLocalDirectory(new File(this.tmpDir));
|
||||
@@ -716,7 +701,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
when(sessionFactory.getSession()).thenReturn(new TestSession() {
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry("f1", 1234, false, false, modified.getTime(), "-rw-r--r--")
|
||||
};
|
||||
@@ -732,18 +717,16 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<File> out = (MessageBuilder<File>) gw.handleRequestMessage(new GenericMessage<>("x/f1"));
|
||||
File outFile = new File(this.tmpDir + "/f1");
|
||||
assertEquals(outFile, out.getPayload());
|
||||
assertTrue(outFile.exists());
|
||||
assertEquals(modified.getTime(), outFile.lastModified());
|
||||
assertThat(out.getPayload()).isEqualTo(outFile);
|
||||
assertThat(outFile.exists()).isTrue();
|
||||
assertThat(outFile.lastModified()).isEqualTo(modified.getTime());
|
||||
outFile.delete();
|
||||
assertEquals("x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("f1",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("x/");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("f1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet_create_dir() throws Exception {
|
||||
public void testGet_create_dir() {
|
||||
new File(this.tmpDir + "/x/f1").delete();
|
||||
new File(this.tmpDir + "/x").delete();
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
@@ -753,7 +736,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
when(sessionFactory.getSession()).thenReturn(new TestSession() {
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return new TestLsEntry[] {
|
||||
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
|
||||
};
|
||||
@@ -766,9 +749,9 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}
|
||||
|
||||
});
|
||||
gw.handleRequestMessage(new GenericMessage<String>("f1"));
|
||||
gw.handleRequestMessage(new GenericMessage<>("f1"));
|
||||
File out = new File(this.tmpDir + "/x/f1");
|
||||
assertTrue(out.exists());
|
||||
assertThat(out.exists()).isTrue();
|
||||
out.delete();
|
||||
}
|
||||
|
||||
@@ -783,12 +766,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageBuilder<Boolean> out = (MessageBuilder<Boolean>) gw
|
||||
.handleRequestMessage(new GenericMessage<>("testremote/x/f1"));
|
||||
assertEquals(Boolean.TRUE, out.getPayload());
|
||||
assertThat(out.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
verify(session).remove("testremote/x/f1");
|
||||
assertEquals("testremote/x/",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
|
||||
assertEquals("f1",
|
||||
out.getHeaders().get(FileHeaders.REMOTE_FILE));
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/x/");
|
||||
assertThat(out.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("f1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -809,7 +790,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
template.setBeanFactory(mock(BeanFactory.class));
|
||||
template.afterPropertiesSet();
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", "payload");
|
||||
FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<TestLsEntry>(sessionFactory);
|
||||
FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<>(sessionFactory);
|
||||
handler.setRemoteDirectoryExpressionString("'foo/'");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
@@ -819,10 +800,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.setHeader(FileHeaders.FILENAME, "bar.txt")
|
||||
.build();
|
||||
String path = (String) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo/bar.txt", path);
|
||||
assertThat(path).isEqualTo("foo/bar.txt");
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(session).write(any(InputStream.class), captor.capture());
|
||||
assertEquals("foo/bar.txt.writing", captor.getValue());
|
||||
assertThat(captor.getValue()).isEqualTo("foo/bar.txt.writing");
|
||||
verify(session).rename("foo/bar.txt.writing", "foo/bar.txt");
|
||||
}
|
||||
|
||||
@@ -844,7 +825,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
template.setBeanFactory(mock(BeanFactory.class));
|
||||
template.afterPropertiesSet();
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", "payload");
|
||||
FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<TestLsEntry>(sessionFactory);
|
||||
FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<>(sessionFactory);
|
||||
handler.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
@@ -856,10 +837,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
// default (null) == REPLACE
|
||||
String path = (String) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo/bar.txt", path);
|
||||
assertThat(path).isEqualTo("foo/bar.txt");
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(session).write(any(InputStream.class), captor.capture());
|
||||
assertEquals("foo/bar.txt.writing", captor.getValue());
|
||||
assertThat(captor.getValue()).isEqualTo("foo/bar.txt.writing");
|
||||
verify(session).rename("foo/bar.txt.writing", "foo/bar.txt");
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.FAIL);
|
||||
@@ -868,27 +849,27 @@ public class RemoteFileOutboundGatewayTests {
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getMessage(), containsString("The destination file already exists"));
|
||||
assertThat(e.getMessage()).contains("The destination file already exists");
|
||||
}
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.REPLACE);
|
||||
path = (String) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo/bar.txt", path);
|
||||
assertThat(path).isEqualTo("foo/bar.txt");
|
||||
captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(session, times(2)).write(any(InputStream.class), captor.capture());
|
||||
assertEquals("foo/bar.txt.writing", captor.getValue());
|
||||
assertThat(captor.getValue()).isEqualTo("foo/bar.txt.writing");
|
||||
verify(session, times(2)).rename("foo/bar.txt.writing", "foo/bar.txt");
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.APPEND);
|
||||
path = (String) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo/bar.txt", path);
|
||||
assertThat(path).isEqualTo("foo/bar.txt");
|
||||
captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(session).append(any(InputStream.class), captor.capture());
|
||||
assertEquals("foo/bar.txt", captor.getValue());
|
||||
assertThat(captor.getValue()).isEqualTo("foo/bar.txt");
|
||||
|
||||
gw.setFileExistsMode(FileExistsMode.IGNORE);
|
||||
path = (String) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals("foo/bar.txt", path);
|
||||
assertThat(path).isEqualTo("foo/bar.txt");
|
||||
// no more writes/appends
|
||||
verify(session, times(2)).write(any(InputStream.class), anyString());
|
||||
verify(session, times(1)).append(any(InputStream.class), anyString());
|
||||
@@ -900,14 +881,14 @@ public class RemoteFileOutboundGatewayTests {
|
||||
SessionFactory<TestLsEntry> sessionFactory = mock(SessionFactory.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Session<TestLsEntry> session = mock(Session.class);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<TestLsEntry>(sessionFactory);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<>(sessionFactory);
|
||||
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
|
||||
template.setBeanFactory(mock(BeanFactory.class));
|
||||
template.afterPropertiesSet();
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", "payload");
|
||||
gw.afterPropertiesSet();
|
||||
when(sessionFactory.getSession()).thenReturn(session);
|
||||
final AtomicReference<String> written = new AtomicReference<String>();
|
||||
final AtomicReference<String> written = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
written.set(invocation.getArgument(1));
|
||||
return null;
|
||||
@@ -918,13 +899,10 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.build();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals(2, out.size());
|
||||
assertThat(out.get(0),
|
||||
not(equalTo(out.get(1))));
|
||||
assertThat(out.get(0), anyOf(
|
||||
equalTo("foo/baz.txt"), equalTo("foo/qux.txt")));
|
||||
assertThat(out.get(1), anyOf(
|
||||
equalTo("foo/baz.txt"), equalTo("foo/qux.txt")));
|
||||
assertThat(out.size()).isEqualTo(2);
|
||||
assertThat(out.get(0)).isNotEqualTo(out.get(1));
|
||||
assertThat(out.get(0)).isIn("foo/baz.txt", "foo/qux.txt");
|
||||
assertThat(out.get(1)).isIn("foo/baz.txt", "foo/qux.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -933,7 +911,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
SessionFactory<TestLsEntry> sessionFactory = mock(SessionFactory.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Session<TestLsEntry> session = mock(Session.class);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<TestLsEntry>(sessionFactory);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<>(sessionFactory);
|
||||
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
|
||||
template.setBeanFactory(mock(BeanFactory.class));
|
||||
template.afterPropertiesSet();
|
||||
@@ -941,7 +919,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
gw.setOptions("-R");
|
||||
gw.afterPropertiesSet();
|
||||
when(sessionFactory.getSession()).thenReturn(session);
|
||||
final AtomicReference<String> written = new AtomicReference<String>();
|
||||
final AtomicReference<String> written = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
written.set(invocation.getArgument(1));
|
||||
return null;
|
||||
@@ -955,15 +933,11 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.build();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals(3, out.size());
|
||||
assertThat(out.get(0),
|
||||
not(equalTo(out.get(1))));
|
||||
assertThat(out.get(0), anyOf(
|
||||
equalTo("foo/baz.txt"), equalTo("foo/qux.txt"), equalTo("foo/" + dir1.getName() + "/" + file3.getName())));
|
||||
assertThat(out.get(1), anyOf(
|
||||
equalTo("foo/baz.txt"), equalTo("foo/qux.txt"), equalTo("foo/" + dir1.getName() + "/" + file3.getName())));
|
||||
assertThat(out.get(2), anyOf(
|
||||
equalTo("foo/baz.txt"), equalTo("foo/qux.txt"), equalTo("foo/" + dir1.getName() + "/" + file3.getName())));
|
||||
assertThat(out.size()).isEqualTo(3);
|
||||
assertThat(out.get(0)).isNotEqualTo(out.get(1));
|
||||
assertThat(out.get(0)).isIn("foo/baz.txt", "foo/qux.txt", "foo/" + dir1.getName() + "/" + file3.getName());
|
||||
assertThat(out.get(1)).isIn("foo/baz.txt", "foo/qux.txt", "foo/" + dir1.getName() + "/" + file3.getName());
|
||||
assertThat(out.get(2)).isIn("foo/baz.txt", "foo/qux.txt", "foo/" + dir1.getName() + "/" + file3.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -972,14 +946,14 @@ public class RemoteFileOutboundGatewayTests {
|
||||
SessionFactory<TestLsEntry> sessionFactory = mock(SessionFactory.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Session<TestLsEntry> session = mock(Session.class);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<TestLsEntry>(sessionFactory);
|
||||
RemoteFileTemplate<TestLsEntry> template = new RemoteFileTemplate<>(sessionFactory);
|
||||
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
|
||||
template.setBeanFactory(mock(BeanFactory.class));
|
||||
template.afterPropertiesSet();
|
||||
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", "payload");
|
||||
gw.afterPropertiesSet();
|
||||
when(sessionFactory.getSession()).thenReturn(session);
|
||||
final AtomicReference<String> written = new AtomicReference<String>();
|
||||
final AtomicReference<String> written = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
written.set(invocation.getArgument(1));
|
||||
return null;
|
||||
@@ -991,12 +965,11 @@ public class RemoteFileOutboundGatewayTests {
|
||||
.build();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
|
||||
assertEquals(2, out.size());
|
||||
assertThat(out.get(0),
|
||||
not(equalTo(out.get(1))));
|
||||
assertThat(out.get(0), equalTo("foo/fiz.txt"));
|
||||
assertThat(out.get(1), equalTo("foo/buz.txt"));
|
||||
assertThat(written.get(), equalTo("foo/buz.txt.writing"));
|
||||
assertThat(out.size()).isEqualTo(2);
|
||||
assertThat(out.get(0)).isNotEqualTo(out.get(1));
|
||||
assertThat(out.get(0)).isEqualTo("foo/fiz.txt");
|
||||
assertThat(out.get(1)).isEqualTo("foo/buz.txt");
|
||||
assertThat(written.get()).isEqualTo("foo/buz.txt.writing");
|
||||
verify(session).rename("foo/buz.txt.writing", "foo/buz.txt");
|
||||
}
|
||||
|
||||
@@ -1006,12 +979,12 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean remove(String path) throws IOException {
|
||||
public boolean remove(String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestLsEntry[] list(String path) throws IOException {
|
||||
public TestLsEntry[] list(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1021,28 +994,25 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(InputStream inputStream, String destination)
|
||||
throws IOException {
|
||||
public void write(InputStream inputStream, String destination) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(InputStream inputStream, String destination)
|
||||
throws IOException {
|
||||
public void append(InputStream inputStream, String destination) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mkdir(String directory) throws IOException {
|
||||
public boolean mkdir(String directory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rmdir(String directory) throws IOException {
|
||||
public boolean rmdir(String directory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String pathFrom, String pathTo)
|
||||
throws IOException {
|
||||
public void rename(String pathFrom, String pathTo) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1056,22 +1026,22 @@ public class RemoteFileOutboundGatewayTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String path) throws IOException {
|
||||
public boolean exists(String path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] listNames(String path) throws IOException {
|
||||
public String[] listNames(String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readRaw(String source) throws IOException {
|
||||
public InputStream readRaw(String source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean finalizeRaw() throws IOException {
|
||||
public boolean finalizeRaw() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1127,7 +1097,8 @@ public class RemoteFileOutboundGatewayTests {
|
||||
@Override
|
||||
protected List<AbstractFileInfo<TestLsEntry>> asFileInfoList(
|
||||
Collection<TestLsEntry> files) {
|
||||
return new ArrayList<AbstractFileInfo<TestLsEntry>>(files);
|
||||
|
||||
return new ArrayList<>(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1154,6 +1125,7 @@ public class RemoteFileOutboundGatewayTests {
|
||||
|
||||
TestLsEntry(String filename, long size, boolean dir, boolean link,
|
||||
long modified, String permissions) {
|
||||
|
||||
this.filename = filename;
|
||||
this.size = size;
|
||||
this.dir = dir;
|
||||
|
||||
@@ -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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.remote.handler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -66,7 +64,7 @@ public class FileTransferringMessageHandlerTests {
|
||||
when(sf.getSession()).thenReturn(session);
|
||||
doAnswer(invocation -> {
|
||||
String path = invocation.getArgument(1);
|
||||
assertFalse(path.startsWith("/"));
|
||||
assertThat(path.startsWith("/")).isFalse();
|
||||
return null;
|
||||
}).when(session).rename(Mockito.anyString(), Mockito.anyString());
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -99,8 +97,8 @@ public class FileTransferringMessageHandlerTests {
|
||||
handler.afterPropertiesSet();
|
||||
handler.handleMessage(new GenericMessage<String>("hello"));
|
||||
verify(session, times(1)).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
assertEquals("bar", temporaryPath.get().substring(0, 3));
|
||||
assertEquals("foo", finalPath.get().substring(0, 3));
|
||||
assertThat(temporaryPath.get().substring(0, 3)).isEqualTo("bar");
|
||||
assertThat(finalPath.get().substring(0, 3)).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -112,7 +110,7 @@ public class FileTransferringMessageHandlerTests {
|
||||
when(sf.getSession()).thenReturn(session);
|
||||
doAnswer(invocation -> {
|
||||
String path = invocation.getArgument(1);
|
||||
assertFalse(path.startsWith("/"));
|
||||
assertThat(path.startsWith("/")).isFalse();
|
||||
return null;
|
||||
}).when(session).rename(Mockito.anyString(), Mockito.anyString());
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -176,16 +174,16 @@ public class FileTransferringMessageHandlerTests {
|
||||
handler.handleMessage(new GenericMessage<String>("hello"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("test", e.getCause().getCause().getMessage());
|
||||
assertThat(e.getCause().getCause().getMessage()).isEqualTo("test");
|
||||
}
|
||||
}
|
||||
verify(session1, times(1)).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
verify(session2, times(1)).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
verify(session3, times(1)).write(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
SimplePool<?> pool = TestUtils.getPropertyValue(csf, "pool", SimplePool.class);
|
||||
assertEquals(1, pool.getAllocatedCount());
|
||||
assertEquals(1, pool.getIdleCount());
|
||||
assertSame(session3, TestUtils.getPropertyValue(pool, "allocated", Set.class).iterator().next());
|
||||
assertThat(pool.getAllocatedCount()).isEqualTo(1);
|
||||
assertThat(pool.getIdleCount()).isEqualTo(1);
|
||||
assertThat(TestUtils.getPropertyValue(pool, "allocated", Set.class).iterator().next()).isSameAs(session3);
|
||||
}
|
||||
|
||||
private <F> Session<F> newSession() throws IOException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.remote.session;
|
||||
|
||||
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.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.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -54,29 +49,29 @@ public class CachingSessionFactoryTests {
|
||||
CachingSessionFactory<String> cache = new CachingSessionFactory<String>(factory);
|
||||
cache.setTestSession(true);
|
||||
Session<String> sess1 = cache.getSession();
|
||||
assertEquals("session:1", TestUtils.getPropertyValue(sess1, "targetSession.id"));
|
||||
assertThat(TestUtils.getPropertyValue(sess1, "targetSession.id")).isEqualTo("session:1");
|
||||
Session<String> sess2 = cache.getSession();
|
||||
assertEquals("session:2", TestUtils.getPropertyValue(sess2, "targetSession.id"));
|
||||
assertThat(TestUtils.getPropertyValue(sess2, "targetSession.id")).isEqualTo("session:2");
|
||||
sess1.close();
|
||||
// session back to pool; should be open and reused.
|
||||
assertTrue(sess1.isOpen());
|
||||
assertThat(sess1.isOpen()).isTrue();
|
||||
sess1 = cache.getSession();
|
||||
assertEquals("session:1", TestUtils.getPropertyValue(sess1, "targetSession.id"));
|
||||
assertTrue((TestUtils.getPropertyValue(sess1, "targetSession.testCalled", Boolean.class)));
|
||||
assertThat(TestUtils.getPropertyValue(sess1, "targetSession.id")).isEqualTo("session:1");
|
||||
assertThat((TestUtils.getPropertyValue(sess1, "targetSession.testCalled", Boolean.class))).isTrue();
|
||||
sess1.close();
|
||||
assertTrue(sess1.isOpen());
|
||||
assertThat(sess1.isOpen()).isTrue();
|
||||
// reset the cache; should close idle (sess1); sess2 should closed later
|
||||
cache.resetCache();
|
||||
assertFalse(sess1.isOpen());
|
||||
assertThat(sess1.isOpen()).isFalse();
|
||||
sess1 = cache.getSession();
|
||||
assertEquals("session:3", TestUtils.getPropertyValue(sess1, "targetSession.id"));
|
||||
assertThat(TestUtils.getPropertyValue(sess1, "targetSession.id")).isEqualTo("session:3");
|
||||
sess1.close();
|
||||
assertTrue(sess1.isOpen());
|
||||
assertThat(sess1.isOpen()).isTrue();
|
||||
// session from previous epoch is closed on return
|
||||
sess2.close();
|
||||
assertFalse(sess2.isOpen());
|
||||
assertThat(sess2.isOpen()).isFalse();
|
||||
cache.resetCache();
|
||||
assertFalse(sess1.isOpen());
|
||||
assertThat(sess1.isOpen()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,8 +95,8 @@ public class CachingSessionFactoryTests {
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getCause(), instanceOf(RuntimeException.class));
|
||||
assertThat(e.getCause().getMessage(), equalTo("bar"));
|
||||
assertThat(e.getCause()).isInstanceOf(RuntimeException.class);
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("bar");
|
||||
}
|
||||
verify(session).close();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 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,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.remote.session;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -81,19 +78,19 @@ public class DelegatingSessionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testDelegates() {
|
||||
assertEquals(foo.mockSession, this.dsf.getSession("foo"));
|
||||
assertEquals(bar.mockSession, this.dsf.getSession("bar"));
|
||||
assertEquals(bar.mockSession, this.dsf.getSession("junk"));
|
||||
assertEquals(bar.mockSession, this.dsf.getSession());
|
||||
assertThat(this.dsf.getSession("foo")).isEqualTo(foo.mockSession);
|
||||
assertThat(this.dsf.getSession("bar")).isEqualTo(bar.mockSession);
|
||||
assertThat(this.dsf.getSession("junk")).isEqualTo(bar.mockSession);
|
||||
assertThat(this.dsf.getSession()).isEqualTo(bar.mockSession);
|
||||
this.dsf.setThreadKey("foo");
|
||||
assertEquals(foo.mockSession, this.dsf.getSession("foo"));
|
||||
assertThat(this.dsf.getSession("foo")).isEqualTo(foo.mockSession);
|
||||
this.dsf.clearThreadKey();
|
||||
TestSessionFactory factory = new TestSessionFactory();
|
||||
this.sessionFactoryLocator.addSessionFactory("baz", factory);
|
||||
this.dsf.setThreadKey("baz");
|
||||
assertEquals(factory.mockSession, this.dsf.getSession("baz"));
|
||||
assertThat(this.dsf.getSession("baz")).isEqualTo(factory.mockSession);
|
||||
this.dsf.clearThreadKey();
|
||||
assertSame(factory, sessionFactoryLocator.removeSessionFactory("baz"));
|
||||
assertThat(sessionFactoryLocator.removeSessionFactory("baz")).isSameAs(factory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,9 +99,9 @@ public class DelegatingSessionFactoryTests {
|
||||
.willReturn(new String[0]);
|
||||
in.send(new GenericMessage<>("foo"));
|
||||
Message<?> received = out.receive(0);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
verify(foo.mockSession).list("foo/");
|
||||
assertNull(TestUtils.getPropertyValue(dsf, "threadKey", ThreadLocal.class).get());
|
||||
assertThat(TestUtils.getPropertyValue(dsf, "threadKey", ThreadLocal.class).get()).isNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -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,10 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.remote.synchronizer;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.File;
|
||||
@@ -87,16 +85,16 @@ public class AbstractRemoteFileSynchronizerTests {
|
||||
|
||||
try {
|
||||
sync.synchronizeToLocalDirectory(mock(File.class));
|
||||
assertEquals(1, count.get());
|
||||
assertThat(count.get()).isEqualTo(1);
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getCause(), instanceOf(MessagingException.class));
|
||||
assertThat(e.getCause().getCause(), instanceOf(IOException.class));
|
||||
assertEquals("fail", e.getCause().getCause().getMessage());
|
||||
assertThat(e.getCause()).isInstanceOf(MessagingException.class);
|
||||
assertThat(e.getCause().getCause()).isInstanceOf(IOException.class);
|
||||
assertThat(e.getCause().getCause().getMessage()).isEqualTo("fail");
|
||||
}
|
||||
sync.synchronizeToLocalDirectory(mock(File.class));
|
||||
assertEquals(3, count.get());
|
||||
assertThat(count.get()).isEqualTo(3);
|
||||
sync.close();
|
||||
}
|
||||
|
||||
@@ -106,11 +104,11 @@ public class AbstractRemoteFileSynchronizerTests {
|
||||
AbstractInboundFileSynchronizer<String> sync = createLimitingSynchronizer(count);
|
||||
|
||||
sync.synchronizeToLocalDirectory(mock(File.class), 1);
|
||||
assertEquals(1, count.get());
|
||||
assertThat(count.get()).isEqualTo(1);
|
||||
sync.synchronizeToLocalDirectory(mock(File.class), 1);
|
||||
assertEquals(2, count.get());
|
||||
assertThat(count.get()).isEqualTo(2);
|
||||
sync.synchronizeToLocalDirectory(mock(File.class), 1);
|
||||
assertEquals(3, count.get());
|
||||
assertThat(count.get()).isEqualTo(3);
|
||||
sync.close();
|
||||
}
|
||||
|
||||
@@ -123,7 +121,7 @@ public class AbstractRemoteFileSynchronizerTests {
|
||||
source.start();
|
||||
|
||||
source.receive();
|
||||
assertEquals(1, count.get());
|
||||
assertThat(count.get()).isEqualTo(1);
|
||||
sync.synchronizeToLocalDirectory(mock(File.class), 1);
|
||||
source.receive();
|
||||
sync.synchronizeToLocalDirectory(mock(File.class), 1);
|
||||
@@ -139,7 +137,7 @@ public class AbstractRemoteFileSynchronizerTests {
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
source.receive();
|
||||
assertEquals(1, count.get());
|
||||
assertThat(count.get()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +148,7 @@ public class AbstractRemoteFileSynchronizerTests {
|
||||
source.afterPropertiesSet();
|
||||
source.start();
|
||||
source.receive();
|
||||
assertEquals(1, count.get());
|
||||
assertThat(count.get()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 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,16 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.splitter;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader;
|
||||
import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeaderKey;
|
||||
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -88,7 +80,7 @@ public class FileSplitterTests {
|
||||
|
||||
private static File file;
|
||||
|
||||
private static final String SAMPLE_CONTENT = "HelloWorld\näöüß";
|
||||
private static final String SAMPLE_CONTENT = "HelloWorld\n????";
|
||||
|
||||
@Autowired
|
||||
private MessageChannel input1;
|
||||
@@ -118,80 +110,80 @@ public class FileSplitterTests {
|
||||
public void testFileSplitter() throws Exception {
|
||||
this.input1.send(new GenericMessage<File>(file));
|
||||
Message<?> receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals("HelloWorld", receive.getPayload());
|
||||
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getPayload()).isEqualTo("HelloWorld");
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(2);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertEquals("äöüß", receive.getPayload());
|
||||
assertEquals(file, receive.getHeaders().get(FileHeaders.ORIGINAL_FILE));
|
||||
assertEquals(file.getName(), receive.getHeaders().get(FileHeaders.FILENAME));
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(receive.getPayload()).isEqualTo("????");
|
||||
assertThat(receive.getHeaders().get(FileHeaders.ORIGINAL_FILE)).isEqualTo(file);
|
||||
assertThat(receive.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(file.getName());
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input1.send(new GenericMessage<String>(file.getAbsolutePath()));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(2);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertEquals(file, receive.getHeaders().get(FileHeaders.ORIGINAL_FILE));
|
||||
assertEquals(file.getName(), receive.getHeaders().get(FileHeaders.FILENAME));
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(receive.getHeaders().get(FileHeaders.ORIGINAL_FILE)).isEqualTo(file);
|
||||
assertThat(receive.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(file.getName());
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input1.send(new GenericMessage<Reader>(new FileReader(file)));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(2);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input2.send(new GenericMessage<File>(file));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(0, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(0);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input2.send(new GenericMessage<InputStream>(new ByteArrayInputStream(SAMPLE_CONTENT.getBytes("UTF-8"))));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(0, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(0);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
try {
|
||||
this.input2.send(new GenericMessage<String>("bar"));
|
||||
fail("FileNotFoundException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getCause(), instanceOf(FileNotFoundException.class));
|
||||
assertThat(e.getMessage(), containsString("failed to read file [bar]"));
|
||||
assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
|
||||
assertThat(e.getMessage()).contains("failed to read file [bar]");
|
||||
}
|
||||
this.input2.send(new GenericMessage<Date>(new Date()));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(1, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive.getPayload(), instanceOf(Date.class));
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(1);
|
||||
assertThat(receive.getPayload()).isInstanceOf(Date.class);
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input3.send(new GenericMessage<File>(file));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(0, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(0);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
|
||||
this.input3.send(new GenericMessage<InputStream>(new ByteArrayInputStream(SAMPLE_CONTENT.getBytes("UTF-8"))));
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //HelloWorld
|
||||
assertEquals(0, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(receive).isNotNull(); //HelloWorld
|
||||
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(0);
|
||||
receive = this.output.receive(10000);
|
||||
assertNotNull(receive); //äöüß
|
||||
assertNull(this.output.receive(1));
|
||||
assertThat(receive).isNotNull(); //????
|
||||
assertThat(this.output.receive(1)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,23 +193,23 @@ public class FileSplitterTests {
|
||||
splitter.setOutputChannel(outputChannel);
|
||||
splitter.handleMessage(new GenericMessage<File>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertEquals("START", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("START");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertNotNull(outputChannel.receive(0));
|
||||
assertNotNull(outputChannel.receive(0));
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(outputChannel.receive(0)).isNotNull();
|
||||
assertThat(outputChannel.receive(0)).isNotNull();
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertEquals("END", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("END");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(2, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,24 +220,24 @@ public class FileSplitterTests {
|
||||
File file = File.createTempFile("empty", ".txt");
|
||||
splitter.handleMessage(new GenericMessage<File>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertEquals("START", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("START");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(0, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(0);
|
||||
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
|
||||
assertEquals("END", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("END");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(0, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,25 +248,25 @@ public class FileSplitterTests {
|
||||
splitter.setOutputChannel(outputChannel);
|
||||
splitter.handleMessage(new GenericMessage<File>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertEquals("START", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(String.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("START");
|
||||
assertThat(received.getPayload()).isInstanceOf(String.class);
|
||||
String payload = (String) received.getPayload();
|
||||
assertThat(payload, containsString("\"mark\":\"START\",\"lineCount\":0"));
|
||||
assertThat(payload).contains("\"mark\":\"START\",\"lineCount\":0");
|
||||
FileMarker fileMarker = objectMapper.fromJson(payload, FileSplitter.FileMarker.class);
|
||||
assertEquals(FileSplitter.FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertNotNull(outputChannel.receive(0));
|
||||
assertNotNull(outputChannel.receive(0));
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(outputChannel.receive(0)).isNotNull();
|
||||
assertThat(outputChannel.receive(0)).isNotNull();
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertEquals("END", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(String.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("END");
|
||||
assertThat(received.getPayload()).isInstanceOf(String.class);
|
||||
fileMarker = objectMapper.fromJson((String) received.getPayload(), FileSplitter.FileMarker.class);
|
||||
assertEquals(FileSplitter.FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(2, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,21 +280,22 @@ public class FileSplitterTests {
|
||||
|
||||
StepVerifier.create(outputChannel)
|
||||
.assertNext(m -> {
|
||||
assertThat(m, hasHeaderKey(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertThat(m, hasHeader(FileHeaders.MARKER, "START"));
|
||||
assertThat(m, hasPayload(instanceOf(FileSplitter.FileMarker.class)));
|
||||
assertThat(m.getHeaders())
|
||||
.containsKey(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)
|
||||
.containsEntry(FileHeaders.MARKER, "START");
|
||||
assertThat(m.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) m.getPayload();
|
||||
assertEquals(FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
})
|
||||
.expectNextCount(2)
|
||||
.assertNext(m -> {
|
||||
assertThat(m, hasHeader(FileHeaders.MARKER, "END"));
|
||||
assertThat(m, hasPayload(instanceOf(FileSplitter.FileMarker.class)));
|
||||
assertThat(m.getHeaders()).containsEntry(FileHeaders.MARKER, "END");
|
||||
assertThat(m.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) m.getPayload();
|
||||
assertEquals(FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(2, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(2);
|
||||
})
|
||||
.then(() ->
|
||||
((Subscriber<?>) TestUtils.getPropertyValue(outputChannel, "subscribers", List.class).get(0))
|
||||
@@ -318,26 +311,26 @@ public class FileSplitterTests {
|
||||
splitter.setOutputChannel(outputChannel);
|
||||
splitter.handleMessage(new GenericMessage<>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertNull(received.getHeaders().get("firstLine"));
|
||||
assertEquals("START", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isNull();
|
||||
assertThat(received.getHeaders().get("firstLine")).isNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("START");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
received = outputChannel.receive(0);
|
||||
assertEquals("HelloWorld", received.getHeaders().get("firstLine"));
|
||||
assertNotNull(received);
|
||||
assertThat(received.getHeaders().get("firstLine")).isEqualTo("HelloWorld");
|
||||
assertThat(received).isNotNull();
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertEquals("END", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertNull(received.getHeaders().get("firstLine"));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("END");
|
||||
assertThat(received.getHeaders().get("firstLine")).isNull();
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(1, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -349,23 +342,23 @@ public class FileSplitterTests {
|
||||
File file = File.createTempFile("empty", ".txt");
|
||||
splitter.handleMessage(new GenericMessage<>(file));
|
||||
Message<?> received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertNull(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
|
||||
assertNull(received.getHeaders().get("firstLine"));
|
||||
assertEquals("START", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isNull();
|
||||
assertThat(received.getHeaders().get("firstLine")).isNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("START");
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.START, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.START);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
received = outputChannel.receive(0);
|
||||
assertNotNull(received);
|
||||
assertEquals("END", received.getHeaders().get(FileHeaders.MARKER));
|
||||
assertNull(received.getHeaders().get("firstLine"));
|
||||
assertThat(received.getPayload(), instanceOf(FileSplitter.FileMarker.class));
|
||||
assertThat(received).isNotNull();
|
||||
assertThat(received.getHeaders().get(FileHeaders.MARKER)).isEqualTo("END");
|
||||
assertThat(received.getHeaders().get("firstLine")).isNull();
|
||||
assertThat(received.getPayload()).isInstanceOf(FileSplitter.FileMarker.class);
|
||||
fileMarker = (FileSplitter.FileMarker) received.getPayload();
|
||||
assertEquals(FileSplitter.FileMarker.Mark.END, fileMarker.getMark());
|
||||
assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
|
||||
assertEquals(0, fileMarker.getLineCount());
|
||||
assertThat(fileMarker.getMark()).isEqualTo(FileSplitter.FileMarker.Mark.END);
|
||||
assertThat(fileMarker.getFilePath()).isEqualTo(file.getAbsolutePath());
|
||||
assertThat(fileMarker.getLineCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.tail;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
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.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -123,17 +118,17 @@ public class FileTailingMessageProducerTests {
|
||||
adapter.afterPropertiesSet();
|
||||
|
||||
adapter.start();
|
||||
assertEquals("tail " + firstOptions + " " + firstFile.getAbsolutePath(), adapter.getCommand());
|
||||
assertThat(adapter.getCommand()).isEqualTo("tail " + firstOptions + " " + firstFile.getAbsolutePath());
|
||||
adapter.stop();
|
||||
|
||||
adapter.setFile(secondFile);
|
||||
adapter.start();
|
||||
assertEquals("tail " + firstOptions + " " + secondFile.getAbsolutePath(), adapter.getCommand());
|
||||
assertThat(adapter.getCommand()).isEqualTo("tail " + firstOptions + " " + secondFile.getAbsolutePath());
|
||||
adapter.stop();
|
||||
|
||||
adapter.setOptions(secondOptions);
|
||||
adapter.start();
|
||||
assertEquals("tail " + secondOptions + " " + secondFile.getAbsolutePath(), adapter.getCommand());
|
||||
assertThat(adapter.getCommand()).isEqualTo("tail " + secondOptions + " " + secondFile.getAbsolutePath());
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
@@ -170,14 +165,14 @@ public class FileTailingMessageProducerTests {
|
||||
adapter.start();
|
||||
|
||||
boolean noFile = fileExistCountDownLatch.await(10, TimeUnit.SECONDS);
|
||||
assertTrue("file does not exist event did not emit ", noFile);
|
||||
assertThat(noFile).as("file does not exist event did not emit ").isTrue();
|
||||
boolean noEvent = idleCountDownLatch.await(100, TimeUnit.MILLISECONDS);
|
||||
assertFalse("event should not emit when no file exit", noEvent);
|
||||
assertThat(noEvent).as("event should not emit when no file exit").isFalse();
|
||||
verify(file, atLeastOnce()).exists();
|
||||
|
||||
file.createNewFile();
|
||||
boolean eventRaised = idleCountDownLatch.await(10, TimeUnit.SECONDS);
|
||||
assertTrue("idle event did not emit", eventRaised);
|
||||
assertThat(eventRaised).as("idle event did not emit").isTrue();
|
||||
adapter.stop();
|
||||
file.delete();
|
||||
}
|
||||
@@ -214,8 +209,8 @@ public class FileTailingMessageProducerTests {
|
||||
foo.close();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
Message<?> message = outputChannel.receive(10000);
|
||||
assertNotNull("expected a non-null message", message);
|
||||
assertEquals("hello" + i, message.getPayload());
|
||||
assertThat(message).as("expected a non-null message").isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("hello" + i);
|
||||
}
|
||||
file.renameTo(renamed);
|
||||
file = new File(testDir, "foo");
|
||||
@@ -230,13 +225,13 @@ public class FileTailingMessageProducerTests {
|
||||
foo.close();
|
||||
for (int i = 50; i < 100; i++) {
|
||||
Message<?> message = outputChannel.receive(10000);
|
||||
assertNotNull("expected a non-null message", message);
|
||||
assertEquals("hello" + i, message.getPayload());
|
||||
assertEquals(file, message.getHeaders().get(FileHeaders.ORIGINAL_FILE));
|
||||
assertEquals(file.getName(), message.getHeaders().get(FileHeaders.FILENAME));
|
||||
assertThat(message).as("expected a non-null message").isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("hello" + i);
|
||||
assertThat(message.getHeaders().get(FileHeaders.ORIGINAL_FILE)).isEqualTo(file);
|
||||
assertThat(message.getHeaders().get(FileHeaders.FILENAME)).isEqualTo(file.getName());
|
||||
}
|
||||
|
||||
assertThat(events.size(), greaterThanOrEqualTo(1));
|
||||
assertThat(events.size()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
private void waitForField(FileTailingMessageProducerSupport adapter, String field) throws Exception {
|
||||
|
||||
@@ -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.file.tail;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -39,7 +39,10 @@ import org.junit.runners.model.Statement;
|
||||
/**
|
||||
* Ignores tests annotated with {@link TailAvailable} if 'tail' with the requested options
|
||||
* does not work on this platform.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@@ -62,7 +65,7 @@ public class TailRule extends TestWatcher {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
public void evaluate() {
|
||||
// skip
|
||||
}
|
||||
};
|
||||
@@ -83,7 +86,7 @@ public class TailRule extends TestWatcher {
|
||||
OutputStream fos = new FileOutputStream(file);
|
||||
fos.write("foo".getBytes());
|
||||
fos.close();
|
||||
final AtomicReference<Integer> c = new AtomicReference<Integer>();
|
||||
final AtomicReference<Integer> c = new AtomicReference<>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Future<Process> future = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
final Process process = Runtime.getRuntime().exec(commandToTest + " " + file.getAbsolutePath());
|
||||
@@ -127,7 +130,9 @@ public class TailRule extends TestWatcher {
|
||||
@Test
|
||||
public void test1() {
|
||||
TailRule rule = new TailRule("-BLAH");
|
||||
assertFalse(rule.tailWorksOnThisMachine());
|
||||
assertThat(rule.tailWorksOnThisMachine()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,13 +16,10 @@
|
||||
|
||||
package org.springframework.integration.file.transformer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -30,7 +27,6 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.file.FileHeaders;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.matcher.HeaderMatcher;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
@@ -42,7 +38,7 @@ public abstract class AbstractFilePayloadTransformerTests<T extends AbstractFile
|
||||
|
||||
static final String DEFAULT_ENCODING = "UTF-8";
|
||||
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\näöüß";
|
||||
static final String SAMPLE_CONTENT = "HelloWorld\n????";
|
||||
|
||||
T transformer;
|
||||
|
||||
@@ -61,40 +57,40 @@ public abstract class AbstractFilePayloadTransformerTests<T extends AbstractFile
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownCommonTestdata() throws IOException {
|
||||
public void tearDownCommonTestdata() {
|
||||
if (sourceFile.exists()) {
|
||||
sourceFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withSourceHeaderValues_copiedToResult() throws Exception {
|
||||
public void transform_withSourceHeaderValues_copiedToResult() {
|
||||
String anyKey = "foo1";
|
||||
String anyValue = "bar1";
|
||||
message = MessageBuilder.fromMessage(message).setHeader(anyKey, anyValue).build();
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result, HeaderMatcher.hasHeader(anyKey, anyValue));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getHeaders()).containsEntry(anyKey, anyValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withFilePayload_filenameInHeaders() throws Exception {
|
||||
public void transform_withFilePayload_filenameInHeaders() {
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result, HeaderMatcher.hasHeader(FileHeaders.FILENAME, sourceFile.getName()));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getHeaders()).containsEntry(FileHeaders.FILENAME, sourceFile.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withDefaultSettings_fileNotDeleted() throws Exception {
|
||||
public void transform_withDefaultSettings_fileNotDeleted() {
|
||||
transformer.transform(message);
|
||||
assertThat(sourceFile.exists(), is(true));
|
||||
assertThat(sourceFile.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withDeleteSetting_doesNotExistAtOldLocation() throws Exception {
|
||||
public void transform_withDeleteSetting_doesNotExistAtOldLocation() {
|
||||
transformer.setDeleteFiles(true);
|
||||
transformer.transform(message);
|
||||
assertThat("exists at: " + sourceFile.getAbsolutePath(), sourceFile.exists(), is(false));
|
||||
assertThat(sourceFile.exists()).as("exists at: " + sourceFile.getAbsolutePath()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.transformer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -43,10 +39,11 @@ public class FileToByteArrayTransformerTests extends
|
||||
@Test
|
||||
public void transform_withFilePayload_convertedToByteArray() throws Exception {
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertThat(result, hasPayload(is(instanceOf(byte[].class))));
|
||||
assertThat(result, hasPayload(SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING)));
|
||||
assertThat(result.getPayload())
|
||||
.isInstanceOf(byte[].class)
|
||||
.isEqualTo(SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.file.transformer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -42,20 +37,22 @@ public class FileToStringTransformerTests extends
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withFilePayload_convertedToString() throws Exception {
|
||||
public void transform_withFilePayload_convertedToString() {
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result, hasPayload(instanceOf(String.class)));
|
||||
assertThat(result, hasPayload(SAMPLE_CONTENT));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload())
|
||||
.isInstanceOf(String.class)
|
||||
.isEqualTo(SAMPLE_CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transform_withWrongEncoding_notMatching() throws Exception {
|
||||
public void transform_withWrongEncoding_notMatching() {
|
||||
transformer.setCharset("ISO-8859-1");
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result, hasPayload(instanceOf(String.class)));
|
||||
assertThat(result, hasPayload(not(SAMPLE_CONTENT)));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload())
|
||||
.isInstanceOf(String.class)
|
||||
.isEqualTo(SAMPLE_CONTENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user