Search in sources :

Example 1 with GenericFileMessage

use of org.apache.camel.component.file.GenericFileMessage in project ddf by codice.

the class ContentProducerDataAccessObjectTest method getMockMessage.

private GenericFileMessage<File> getMockMessage(File testFile) {
    // set the mockGenericFile to return the test file when requested
    GenericFile<File> mockGenericFileFromBody = mock(GenericFile.class);
    doReturn(testFile).when(mockGenericFileFromBody).getFile();
    WatchEvent<Path> mockWatchEvent = mock(WatchEvent.class);
    // mock out the context that links to the file
    Path mockContext = mock(Path.class);
    doReturn(testFile).when(mockContext).toFile();
    // mock out with a sample kind
    WatchEvent.Kind mockKind = mock(WatchEvent.Kind.class);
    doReturn("example").when(mockKind).name();
    // return the kind or context for the mockWatchEvent
    doReturn(mockKind).when(mockWatchEvent).kind();
    doReturn(mockContext).when(mockWatchEvent).context();
    // return the mockWatchEvent when the file is called for
    GenericFile<File> mockGenericFile = mock(GenericFile.class);
    doReturn(mockWatchEvent).when(mockGenericFile).getFile();
    GenericFileMessage mockMessage = mock(GenericFileMessage.class);
    doReturn(mockGenericFileFromBody).when(mockMessage).getBody();
    doReturn(mockGenericFile).when(mockMessage).getGenericFile();
    return mockMessage;
}
Also used : Path(java.nio.file.Path) GenericFileMessage(org.apache.camel.component.file.GenericFileMessage) WatchEvent(java.nio.file.WatchEvent) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Example 2 with GenericFileMessage

use of org.apache.camel.component.file.GenericFileMessage in project ddf by codice.

the class ContentProducerDataAccessObject method getFileUsingRefKey.

public File getFileUsingRefKey(boolean storeRefKey, Message in) throws ContentComponentException {
    File ingestedFile;
    try {
        if (!storeRefKey) {
            ingestedFile = ((GenericFile<File>) in.getBody()).getFile();
        } else {
            WatchEvent<Path> pathWatchEvent = (WatchEvent<Path>) ((GenericFileMessage) in).getGenericFile().getFile();
            ingestedFile = pathWatchEvent.context().toFile();
        }
    } catch (ClassCastException e) {
        throw new ContentComponentException("Unable to cast message body to Camel GenericFile, so unable to process ingested file");
    }
    return ingestedFile;
}
Also used : Path(java.nio.file.Path) GenericFileMessage(org.apache.camel.component.file.GenericFileMessage) WatchEvent(java.nio.file.WatchEvent) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File)

Aggregations

File (java.io.File)2 Path (java.nio.file.Path)2 WatchEvent (java.nio.file.WatchEvent)2 GenericFile (org.apache.camel.component.file.GenericFile)2 GenericFileMessage (org.apache.camel.component.file.GenericFileMessage)2