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;
}
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;
}
Aggregations