Package org.springmodules.lucene.index.document.handler

Examples of org.springmodules.lucene.index.document.handler.DocumentHandler


      assertNull(indexer.getDocumentHandler("test"));
      fail();
    } catch(Exception ex) {}

    //Register a document handler
    indexer.registerDocumentHandler(matching,new DocumentHandler() {
      public Document getDocument(Map description, Object object) throws IOException {
        return null;
      }

      public boolean supports(Class clazz) {
View Full Code Here


public class SqlDocumentHandlerTests extends TestCase {
  public void testSupport() throws Exception {
    MockControl resultSetControl = MockControl.createControl(ResultSet.class);
    ResultSet resultSet = (ResultSet)resultSetControl.getMock();
   
    DocumentHandler documentHandler = new SqlDocumentHandler() {
      public Document getDocument(SqlRequest request, ResultSet rs) throws SQLException {
        return null;
      }
    };

    resultSetControl.replay();
   
    Map description = new HashMap();
    description.put(SqlRequest.SQL_REQUEST, "sql");
    documentHandler.getDocument(description, resultSet);

    resultSetControl.verify();
  }
View Full Code Here

        return name.equals("test");
      }
    };

    //Register a document handler
    indexer.registerDocumentHandler(matching,new DocumentHandler() {
      public Document getDocument(Map description, Object object) throws IOException {
        return null;
      }

      public boolean supports(Class clazz) {
View Full Code Here

    resultSetControl.verify();
  }

  public void testNotSupport() throws Exception {
    DocumentHandler documentHandler = new SqlDocumentHandler() {
      public Document getDocument(SqlRequest request, ResultSet rs) throws SQLException {
        return null;
      }
    };
 
    Map description = new HashMap();
    description.put(SqlRequest.SQL_REQUEST, "sql");
    try {
      documentHandler.getDocument(description, "test");
      fail();
    } catch (DocumentHandlerException ex) {
    }
  }
View Full Code Here

  public void testDescription() throws Exception {
    MockControl resultSetControl = MockControl.createControl(ResultSet.class);
    ResultSet resultSet = (ResultSet)resultSetControl.getMock();
   
    DocumentHandler documentHandler = new SqlDocumentHandler() {
      public Document getDocument(SqlRequest request, ResultSet rs) throws SQLException {
        return null;
      }
    };
 
    Map description = new HashMap();
    description.put(SqlRequest.SQL_REQUEST, "sql");
    try {
      documentHandler.getDocument(description, "test");
      fail();
    } catch (DocumentHandlerException ex) {
    }

    resultSetControl.replay();
   
    description.put(SqlRequest.SQL_REQUEST, "sql");
    documentHandler.getDocument(description, resultSet);

    resultSetControl.verify();
  }
View Full Code Here

    Object[] params = new Object[] { "param1", new Integer(12)};
    int[] paramTypes = new int[] { Types.VARCHAR, Types.INTEGER };

    final boolean[] called = { false };
    final SqlRequest[] sqlRequests = { null };
    DocumentHandler documentHandler = new SqlDocumentHandler() {
      public Document getDocument(SqlRequest request, ResultSet rs) throws SQLException {
        called[0] = true;
        sqlRequests[0] = request;
        return null;
      }
    };
 
    resultSetControl.replay();
   
    Map description = new HashMap();
    description.put(SqlRequest.SQL_REQUEST, sql);
    description.put(SqlRequest.REQUEST_PARAMETERS, params);
    description.put(SqlRequest.REQUEST_PARAMETER_TYPES, paramTypes);
    documentHandler.getDocument(description, resultSet);

    resultSetControl.verify();
    assertTrue(called[0]);
    assertEquals(sqlRequests[0].getSql(), sql);
    assertEquals(sqlRequests[0].getParams()[0], params[0]);
View Full Code Here

import org.apache.lucene.document.Document;
import org.springmodules.lucene.index.document.handler.DocumentHandler;

public class ReflectiveDocumentHandlerTests extends TestCase {
  public void testGetDocument() throws Exception {
    DocumentHandler documentHandler = new ReflectiveDocumentHandler();

    TestBean bean = new TestBean();
    bean.setField1("field1");
    bean.setField2(2);
    bean.setField3("field3");

    Document document = documentHandler.getDocument(new HashMap(), bean);

    assertEquals("field1", document.get("field1"));
    String typeField1 = document.getField("field1").toString();
    assertTrue(typeField1.startsWith("stored/uncompressed,indexed,tokenized<"));
View Full Code Here

    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.txt");
    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(documentHandler, 1);
    //Document document = documentHandler.getDocument(getResourceDescription(),inputStream);
    documentHandler.getDocument(description, inputStream);
    documentHandlerControl.setReturnValue(document, 1);
   
    inputStream.close();
    inputStreamControl.setVoidCallable(1);
   
View Full Code Here

    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");
View Full Code Here

   * @see #doCallHandler(File, FileInputStream, DocumentHandler)
   * @see DocumentIndexingListener
   */
  private void indexFile(LuceneIndexWriter writer, File file) throws IOException {
    fireListenersOnBeforeFile(file);
    DocumentHandler handler = doGetDocumentHandler(file);
    if( handler!=null ) {
      FileInputStream inputStream = null;
      try {
        inputStream = new FileInputStream(file);
        Document document = doCallHandler(file, inputStream, handler);
View Full Code Here

TOP

Related Classes of org.springmodules.lucene.index.document.handler.DocumentHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.