Search in sources :

Example 6 with FileMarker

use of org.springframework.integration.file.splitter.FileSplitter.FileMarker in project spring-integration by spring-projects.

the class FileSplitterTests method testFirstLineAsHeader.

@Test
public void testFirstLineAsHeader() {
    QueueChannel outputChannel = new QueueChannel();
    FileSplitter splitter = new FileSplitter(true, true);
    splitter.setFirstLineAsHeader("firstLine");
    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));
    FileMarker fileMarker = (FileSplitter.FileMarker) received.getPayload();
    assertEquals(FileSplitter.FileMarker.Mark.START, fileMarker.getMark());
    assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
    received = outputChannel.receive(0);
    assertEquals("HelloWorld", received.getHeaders().get("firstLine"));
    assertNotNull(received);
    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));
    fileMarker = (FileSplitter.FileMarker) received.getPayload();
    assertEquals(FileSplitter.FileMarker.Mark.END, fileMarker.getMark());
    assertEquals(file.getAbsolutePath(), fileMarker.getFilePath());
    assertEquals(1, fileMarker.getLineCount());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) FileMarker(org.springframework.integration.file.splitter.FileSplitter.FileMarker) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 FileMarker (org.springframework.integration.file.splitter.FileSplitter.FileMarker)6 QueueChannel (org.springframework.integration.channel.QueueChannel)5 File (java.io.File)4 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Subscriber (org.reactivestreams.Subscriber)1 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)1