List of usage examples for org.springframework.integration.channel QueueChannel QueueChannel
public QueueChannel()
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteFilesTrueWithFilePayload() throws Exception { QueueChannel output = new QueueChannel(); handler.setDeleteSourceFiles(true);/* w ww . j ava 2 s . c om*/ handler.setOutputChannel(output); Message<?> message = MessageBuilder.withPayload(sourceFile).build(); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithStringPayloadAndFileInstanceHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);/* w w w . j av a 2 s . co m*/ handler.setOutputChannel(output); Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT) .setHeader(FileHeaders.ORIGINAL_FILE, sourceFile).build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithStringPayloadAndFilePathHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);/*from w w w . j av a 2 s . c o m*/ handler.setOutputChannel(output); Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT) .setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath()).build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithByteArrayPayloadAndFileInstanceHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);/*from www . j a v a 2s.com*/ handler.setOutputChannel(output); Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING)) .setHeader(FileHeaders.ORIGINAL_FILE, sourceFile).build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithByteArrayPayloadAndFilePathHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);//from w ww . j a v a 2 s. c o m handler.setOutputChannel(output); Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING)) .setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath()).build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithInputstreamPayloadAndFileInstanceHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);/* w w w . j a v a 2 s . com*/ handler.setOutputChannel(output); InputStream is = new FileInputStream(sourceFile); Message<?> message = MessageBuilder.withPayload(is).setHeader(FileHeaders.ORIGINAL_FILE, sourceFile) .build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void deleteSourceFileWithInputstreamPayloadAndFilePathHeader() throws Exception { QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setDeleteSourceFiles(true);/*from ww w . j a v a2 s .com*/ handler.setOutputChannel(output); InputStream is = new FileInputStream(sourceFile); Message<?> message = MessageBuilder.withPayload(is) .setHeader(FileHeaders.ORIGINAL_FILE, sourceFile.getAbsolutePath()).build(); assertTrue(sourceFile.exists()); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertFalse(sourceFile.exists()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void customFileNameGenerator() throws Exception { final String anyFilename = "fooBar.test"; QueueChannel output = new QueueChannel(); handler.setOutputChannel(output);/*w w w.j a v a 2 s . co m*/ handler.setFileNameGenerator(message -> anyFilename); Message<?> message = MessageBuilder.withPayload("test").build(); handler.handleMessage(message); File result = (File) output.receive(0).getPayload(); assertThat(result.getName(), is(anyFilename)); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void existingFileIgnored() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT).build(); QueueChannel output = new QueueChannel(); File outFile = temp.newFile("/outputDirectory/" + message.getHeaders().getId().toString() + ".msg"); FileCopyUtils.copy("foo".getBytes(), new FileOutputStream(outFile)); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);// w w w . ja va 2 s.c om handler.setFileExistsMode(FileExistsMode.IGNORE); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIs(result, "foo"); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void existingWritingFileIgnored() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT).build(); QueueChannel output = new QueueChannel(); File outFile = temp.newFile("/outputDirectory/" + message.getHeaders().getId().toString() + ".msg.writing"); FileCopyUtils.copy("foo".getBytes(), new FileOutputStream(outFile)); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);//from w w w . java 2s . c o m handler.setFileExistsMode(FileExistsMode.IGNORE); 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)); }