assertTrue(called[2]);
}
final public void testAddDocumentWithInputStreamAndManagerError() throws Exception {
SimpleAnalyzer analyzer = new SimpleAnalyzer();
MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
MockControl documentHandlerManagerControl = MockControl.createStrictControl(DocumentHandlerManager.class);
DocumentHandlerManager documentHandlerManager = (DocumentHandlerManager)documentHandlerManagerControl.getMock();
MockControl documentHandlerControl = MockControl.createStrictControl(DocumentHandler.class);
DocumentHandler documentHandler = (DocumentHandler)documentHandlerControl.getMock();
MockControl inputStreamControl = MockClassControl.createStrictControl(InputStream.class);
final InputStream inputStream = (InputStream)inputStreamControl.getMock();
//file
final File file = getFileFromClasspath("test.foo");
final Map description = new HashMap();
description.put(AbstractInputStreamDocumentHandler.FILENAME, file.getPath());
//final FileInputStream inputStream = new FileInputStream(file);
//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);
//DocumentHandler documentHandler = documentHandlerManager.getDocumentHandler(getResourceName());
documentHandlerManager.getDocumentHandler(file.getPath());
documentHandlerManagerControl.setReturnValue(null, 1);
//Document document = documentHandler.getDocument(getResourceDescription(),inputStream);
/*documentHandler.getDocument(description, inputStream);
documentHandlerControl.setReturnValue(document, 1);*/
/*inputStream.close();
inputStreamControl.setVoidCallable(1);
indexWriter.addDocument(document);
indexWriterControl.setVoidCallable(1);
indexWriter.close();
indexWriterControl.setVoidCallable(1);*/
inputStream.close();
inputStreamControl.setVoidCallable(1);
indexFactoryControl.replay();
indexWriterControl.replay();
documentHandlerManagerControl.replay();
documentHandlerControl.replay();
inputStreamControl.replay();
//Lucene template
final boolean[] called = {false, false, false};
try {
LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
template.addDocument(new InputStreamDocumentCreatorWithManager(documentHandlerManager) {
protected String getResourceName() {
called[0] = true;
return file.getPath();
}
protected Map getResourceDescription() {
called[1] = true;
return description;
}
public InputStream createInputStream() throws IOException {
called[2] = true;
return inputStream;
}
});
fail();
} catch(LuceneIndexingException ex) {
}
indexFactoryControl.verify();
indexWriterControl.verify();
inputStreamControl.verify();
documentHandlerManagerControl.verify();
documentHandlerControl.verify();
inputStreamControl.verify();
assertTrue(called[0]);
assertFalse(called[1]);
assertTrue(called[2]);
}