Search in sources :

Example 6 with PartialSuccessException

use of org.springframework.integration.support.PartialSuccessException in project spring-integration by spring-projects.

the class FtpServerOutboundTests method testMgetRecursivePartial.

@Test
public void testMgetRecursivePartial() throws Exception {
    Session<FTPFile> session = spyOnSession();
    doAnswer(invocation -> {
        FTPFile[] files = (FTPFile[]) invocation.callRealMethod();
        // add an extra file where the get will fail
        files = Arrays.copyOf(files, files.length + 1);
        FTPFile bogusFile = new FTPFile();
        bogusFile.setName("bogus.txt");
        bogusFile.setTimestamp(Calendar.getInstance());
        files[files.length - 1] = bogusFile;
        return files;
    }).when(session).list("ftpSource/subFtpSource/");
    String dir = "ftpSource/";
    try {
        this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*"));
        fail("expected exception");
    } catch (PartialSuccessException e) {
        assertEquals(4, e.getDerivedInput().size());
        assertEquals(2, e.getPartialResults().size());
        assertThat(e.getCause().getMessage(), containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory."));
    }
}
Also used : PartialSuccessException(org.springframework.integration.support.PartialSuccessException) FTPFile(org.apache.commons.net.ftp.FTPFile) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

PartialSuccessException (org.springframework.integration.support.PartialSuccessException)6 File (java.io.File)4 IOException (java.io.IOException)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 FTPFile (org.apache.commons.net.ftp.FTPFile)3 Test (org.junit.Test)3 MessageHandlingException (org.springframework.messaging.MessageHandlingException)3 MessagingException (org.springframework.messaging.MessagingException)3 List (java.util.List)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 AbstractFileInfo (org.springframework.integration.file.remote.AbstractFileInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1