Search in sources :

Example 71 with File

use of java.io.File in project camel by apache.

the class DirectoryCreateIssueTest method testFileCreatedAsDir.

public void testFileCreatedAsDir() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(numFiles);
    template.send("seda:testFileCreatedAsDir", new Processor() {

        public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setBody("Contents of test file");
        }
    });
    assertMockEndpointsSatisfied();
    // wait a little while for the files to settle down
    Thread.sleep(200);
    for (int i = 0; i < numFiles; i++) {
        assertTrue((new File(path + "/file" + i + ".txt")).isFile());
    }
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 72 with File

use of java.io.File in project camel by apache.

the class FileAbsoluteAndRelativeConsumerTest method setUp.

@Override
protected void setUp() throws Exception {
    deleteDirectory("target/filerelative");
    deleteDirectory("target/fileabsolute");
    // use current dir as base as aboslute path
    base = new File("").getAbsolutePath() + "/target/fileabsolute";
    super.setUp();
}
Also used : File(java.io.File)

Example 73 with File

use of java.io.File in project camel by apache.

the class FileBrowsableEndpointTest method testBrowsableOneFile.

public void testBrowsableOneFile() throws Exception {
    template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
    FileEndpoint endpoint = context.getEndpoint("file:target/browse", FileEndpoint.class);
    assertNotNull(endpoint);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
    assertEquals(0, repo.getCacheSize());
    List<Exchange> list = endpoint.getExchanges();
    assertNotNull(list);
    assertEquals(1, list.size());
    assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
    // the in progress repo should not leak
    assertEquals(0, repo.getCacheSize());
    // and the file is still there
    File file = new File("target/browse/a.txt");
    assertTrue("File should exist " + file, file.exists());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository)

Example 74 with File

use of java.io.File in project camel by apache.

the class FileBrowsableEndpointTest method testBrowsableThreeFilesRecursive.

public void testBrowsableThreeFilesRecursive() throws Exception {
    template.sendBodyAndHeader("file:target/browse", "A", Exchange.FILE_NAME, "a.txt");
    template.sendBodyAndHeader("file:target/browse", "B", Exchange.FILE_NAME, "foo/b.txt");
    template.sendBodyAndHeader("file:target/browse", "C", Exchange.FILE_NAME, "bar/c.txt");
    FileEndpoint endpoint = context.getEndpoint("file:target/browse?recursive=true&sortBy=file:name", FileEndpoint.class);
    assertNotNull(endpoint);
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) endpoint.getInProgressRepository();
    assertEquals(0, repo.getCacheSize());
    List<Exchange> list = endpoint.getExchanges();
    assertNotNull(list);
    assertEquals(3, list.size());
    assertEquals("a.txt", list.get(0).getIn().getHeader(Exchange.FILE_NAME));
    assertEquals("c.txt", list.get(1).getIn().getHeader(Exchange.FILE_NAME_ONLY));
    assertEquals("b.txt", list.get(2).getIn().getHeader(Exchange.FILE_NAME_ONLY));
    // the in progress repo should not leak
    assertEquals(0, repo.getCacheSize());
    // and the files is still there
    File fileA = new File("target/browse/a.txt");
    assertTrue("File should exist " + fileA, fileA.exists());
    File fileB = new File("target/browse/foo/b.txt");
    assertTrue("File should exist " + fileB, fileB.exists());
    File fileC = new File("target/browse/bar/c.txt");
    assertTrue("File should exist " + fileC, fileC.exists());
}
Also used : Exchange(org.apache.camel.Exchange) File(java.io.File) MemoryIdempotentRepository(org.apache.camel.processor.idempotent.MemoryIdempotentRepository)

Example 75 with File

use of java.io.File in project camel by apache.

the class FileConcurrentWriteAppendSameFileTest method testConcurrentAppend.

public void testConcurrentAppend() throws Exception {
    // create file with many lines
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size; i++) {
        sb.append("Line " + i + LS);
    }
    template.sendBodyAndHeader("file:target/concurrent", sb.toString(), Exchange.FILE_NAME, "input.txt");
    // start route
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(size);
    mock.expectsNoDuplicates(body());
    mock.setResultWaitTime(30000);
    // we need to wait a bit for our slow CI server to make sure the entire file is written on disc
    Thread.sleep(1000);
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    // check the file has correct number of lines
    String txt = context.getTypeConverter().convertTo(String.class, new File("target/concurrent/outbox/result.txt"));
    assertNotNull(txt);
    String[] lines = txt.split(LS);
    assertEquals("Should be " + size + " lines", size, lines.length);
    // should be unique
    Set<String> rows = new LinkedHashSet<String>(Arrays.asList(lines));
    assertEquals("Should be " + size + " unique lines", size, rows.size());
    log.info(txt);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Aggregations

File (java.io.File)45560 IOException (java.io.IOException)9550 Test (org.junit.Test)9009 FileOutputStream (java.io.FileOutputStream)3388 ArrayList (java.util.ArrayList)3273 FileInputStream (java.io.FileInputStream)2915 InputStream (java.io.InputStream)1783 FileNotFoundException (java.io.FileNotFoundException)1743 URL (java.net.URL)1649 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1478 Test (org.testng.annotations.Test)1411 HashMap (java.util.HashMap)1404 RandomAccessFile (java.io.RandomAccessFile)1154 FileWriter (java.io.FileWriter)1081 Properties (java.util.Properties)1019 ZipFile (java.util.zip.ZipFile)959 JarFile (java.util.jar.JarFile)866 List (java.util.List)850 BufferedReader (java.io.BufferedReader)840 OutputStream (java.io.OutputStream)811