/*
* Test pour void index(String, boolean)
*/
final public void testIndexStringboolean() throws Exception {
SimpleAnalyzer analyzer = new SimpleAnalyzer();
MockControl indexFactoryControl = MockControl.createNiceControl(IndexFactory.class);
IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
MockControl indexWriterControl = MockControl.createNiceControl(LuceneIndexWriter.class);
LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
MockControl listenerControl = MockControl.createNiceControl(FileDocumentIndexingListener.class);
FileDocumentIndexingListener listener = (FileDocumentIndexingListener)listenerControl.getMock();
//document
Document document = new Document();
document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
indexFactory.getIndexWriter();
indexFactoryControl.setReturnValue(indexWriter, 1);
listener.beforeIndexingDirectory(getBaseDirectoryToIndex());
listenerControl.setVoidCallable(1);
listener.beforeIndexingFile(getFileFromClasspath("test.foo"));
listenerControl.setVoidCallable(1);
listener.onNotAvailableHandler(getFileFromClasspath("test.foo"));
listenerControl.setVoidCallable(1);
listener.beforeIndexingFile(getFileFromClasspath("test.txt"));
listenerControl.setVoidCallable(1);
indexWriter.addDocument(document);
indexWriterControl.setMatcher(new AbstractMatcher() {
protected boolean argumentMatches(Object expected, Object actual) {
if( expected instanceof Document && actual instanceof Document ) {
return true;
} else {
return expected.equals(actual);
}
}
});
indexWriterControl.setVoidCallable(1);
listener.afterIndexingFile(getFileFromClasspath("test.txt"));
listenerControl.setVoidCallable(1);
listener.afterIndexingDirectory(getBaseDirectoryToIndex());
listenerControl.setVoidCallable(1);
indexWriter.optimize();
indexWriterControl.setVoidCallable(1);
indexWriter.close();
indexWriterControl.setVoidCallable(1);
indexFactoryControl.replay();
indexWriterControl.replay();
listenerControl.replay();
//Indexer
DefaultDirectoryIndexer indexer = new DefaultDirectoryIndexer(indexFactory);
indexer.addListener(listener);
File baseDirectory = getBaseDirectoryToIndex();
indexer.index(baseDirectory.getAbsolutePath(), true);
indexFactoryControl.verify();
indexWriterControl.verify();
listenerControl.verify();
}