List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testInt2866LocalDirectoryExpressionGET() { String dir = "ftpSource/"; long modified = setModifiedOnSource1(); this.inboundGet.send(new GenericMessage<Object>(dir + " ftpSource1.txt")); Message<?> result = this.output.receive(1000); assertNotNull(result);/*from www.j a v a 2s . c o m*/ File localFile = (File) result.getPayload(); assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir.toUpperCase())); assertPreserved(modified, localFile); dir = "ftpSource/subFtpSource/"; this.inboundGet.send(new GenericMessage<Object>(dir + "subFtpSource1.txt")); result = this.output.receive(1000); assertNotNull(result); localFile = (File) result.getPayload(); assertThat(localFile.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir.toUpperCase())); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testInt2866LocalDirectoryExpressionMGET() { String dir = "ftpSource/"; long modified = setModifiedOnSource1(); this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt")); Message<?> result = this.output.receive(1000); assertNotNull(result);//w w w. j a v a 2s.c om List<File> localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); boolean assertedModified = false; for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); if (file.getPath().contains("localTarget1")) { assertedModified = assertPreserved(modified, file); } } assertTrue(assertedModified); dir = "ftpSource/subFtpSource/"; this.inboundMGet.send(new GenericMessage<Object>(dir + "*.txt")); result = this.output.receive(1000); assertNotNull(result); localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); } }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testMGETOnNullDir() throws IOException { Session<FTPFile> session = ftpSessionFactory.getSession(); ((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource"); session.close();/* ww w. j ava 2 s. c o m*/ this.inboundMGet.send(new GenericMessage<Object>("")); Message<?> result = this.output.receive(1000); assertNotNull(result); List<File> localFiles = (List<File>) result.getPayload(); assertThat(localFiles.size(), Matchers.greaterThan(0)); for (File file : localFiles) { assertThat(file.getName(), isOneOf(" localTarget1.txt", "localTarget2.txt")); assertThat(file.getName(), not(containsString("null"))); } }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testInt3172LocalDirectoryExpressionMGETRecursive() throws IOException { String dir = "ftpSource/"; long modified = setModifiedOnSource1(); File secondRemote = new File(getSourceRemoteDirectory(), "ftpSource2.txt"); secondRemote.setLastModified(System.currentTimeMillis() - 1_000_000); this.inboundMGetRecursive.send(new GenericMessage<Object>("*")); Message<?> result = this.output.receive(1000); assertNotNull(result);/* w w w . j a v a 2 s . com*/ List<File> localFiles = (List<File>) result.getPayload(); assertEquals(3, localFiles.size()); boolean assertedModified = false; for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); if (file.getPath().contains("localTarget1")) { assertedModified = assertPreserved(modified, file); } } assertTrue(assertedModified); assertThat(localFiles.get(2).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir + "subFtpSource")); File secondTarget = new File(getTargetLocalDirectory() + File.separator + "ftpSource", "localTarget2.txt"); ByteArrayOutputStream remoteContents = new ByteArrayOutputStream(); ByteArrayOutputStream localContents = new ByteArrayOutputStream(); FileUtils.copyFile(secondRemote, remoteContents); FileUtils.copyFile(secondTarget, localContents); String localAsString = new String(localContents.toByteArray()); assertEquals(new String(remoteContents.toByteArray()), localAsString); long oldLastModified = secondRemote.lastModified(); FileUtils.copyInputStreamToFile(new ByteArrayInputStream("junk".getBytes()), secondRemote); long newLastModified = secondRemote.lastModified(); secondRemote.setLastModified(oldLastModified); this.inboundMGetRecursive.send(new GenericMessage<Object>("*")); this.output.receive(0); localContents = new ByteArrayOutputStream(); FileUtils.copyFile(secondTarget, localContents); assertEquals(localAsString, new String(localContents.toByteArray())); secondRemote.setLastModified(newLastModified); this.inboundMGetRecursive.send(new GenericMessage<Object>("*")); this.output.receive(0); localContents = new ByteArrayOutputStream(); FileUtils.copyFile(secondTarget, localContents); assertEquals("junk", new String(localContents.toByteArray())); // restore the remote file contents FileUtils.copyInputStreamToFile(new ByteArrayInputStream(localAsString.getBytes()), secondRemote); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test @SuppressWarnings("unchecked") public void testInt3172LocalDirectoryExpressionMGETRecursiveFiltered() { String dir = "ftpSource/"; this.inboundMGetRecursiveFiltered.send(new GenericMessage<Object>(dir + "*")); Message<?> result = this.output.receive(1000); assertNotNull(result);//from w w w . ja va 2 s . c o m List<File> localFiles = (List<File>) result.getPayload(); // should have filtered ftpSource2.txt assertEquals(2, localFiles.size()); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir)); } assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), containsString(dir + "subFtpSource")); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testInt3088MPutNotRecursive() { this.inboundMPut.send(new GenericMessage<File>(getSourceLocalDirectory())); @SuppressWarnings("unchecked") Message<List<String>> out = (Message<List<String>>) this.output.receive(1000); assertNotNull(out);/* w w w .j a va 2s. c o m*/ assertEquals(2, out.getPayload().size()); assertThat(out.getPayload().get(0), not(equalTo(out.getPayload().get(1)))); assertThat(out.getPayload().get(0), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"))); assertThat(out.getPayload().get(1), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"))); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testInt3088MPutRecursive() { this.inboundMPutRecursive.send(new GenericMessage<File>(getSourceLocalDirectory())); @SuppressWarnings("unchecked") Message<List<String>> out = (Message<List<String>>) this.output.receive(1000); assertNotNull(out);//from w ww .j a v a 2 s .c o m assertEquals(3, out.getPayload().size()); assertThat(out.getPayload().get(0), not(equalTo(out.getPayload().get(1)))); assertThat(out.getPayload().get(0), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"), equalTo("ftpTarget/subLocalSource/subLocalSource1.txt"))); assertThat(out.getPayload().get(1), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"), equalTo("ftpTarget/subLocalSource/subLocalSource1.txt"))); assertThat(out.getPayload().get(2), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"), equalTo("ftpTarget/subLocalSource/subLocalSource1.txt"))); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testInt3088MPutRecursiveFiltered() { this.inboundMPutRecursiveFiltered.send(new GenericMessage<File>(getSourceLocalDirectory())); @SuppressWarnings("unchecked") Message<List<String>> out = (Message<List<String>>) this.output.receive(1000); assertNotNull(out);//from w w w.j a va2s . c o m assertEquals(2, out.getPayload().size()); assertThat(out.getPayload().get(0), not(equalTo(out.getPayload().get(1)))); assertThat(out.getPayload().get(0), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"), equalTo("ftpTarget/subLocalSource/subLocalSource1.txt"))); assertThat(out.getPayload().get(1), anyOf(equalTo("ftpTarget/localSource1.txt"), equalTo("ftpTarget/localSource2.txt"), equalTo("ftpTarget/subLocalSource/subLocalSource1.txt"))); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testStream() { String dir = "ftpSource/"; this.inboundGetStream.send(new GenericMessage<Object>(dir + " ftpSource1.txt")); Message<?> result = this.output.receive(1000); assertNotNull(result);/*from w w w . j a v a2s . c o m*/ assertEquals("source1", result.getPayload()); assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)); assertEquals(" ftpSource1.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE)); Session<?> session = (Session<?>) result.getHeaders() .get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE); // Returned to cache assertTrue(session.isOpen()); // Raw reading is finished assertFalse(TestUtils.getPropertyValue(session, "targetSession.readingRaw", AtomicBoolean.class).get()); // Check that we can use the same session from cache to read another remote InputStream this.inboundGetStream.send(new GenericMessage<Object>(dir + "ftpSource2.txt")); result = this.output.receive(1000); assertNotNull(result); assertEquals("source2", result.getPayload()); assertEquals("ftpSource/", result.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)); assertEquals("ftpSource2.txt", result.getHeaders().get(FileHeaders.REMOTE_FILE)); assertSame(TestUtils.getPropertyValue(session, "targetSession"), TestUtils.getPropertyValue( result.getHeaders().get(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE), "targetSession")); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testMessageSessionCallback() { this.inboundCallback.send(new GenericMessage<String>("foo")); Message<?> receive = this.output.receive(10000); assertNotNull(receive);//w ww . j ava 2 s. c om assertEquals("FOO", receive.getPayload()); }