Examples of MockControl


Examples of org.easymock.MockControl

    documentCreatorControl.verify();
  }

  final public void testAddDocumentWithInputStream() 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 documentCreatorControl = MockControl.createStrictControl(InputStreamDocumentCreator.class);
    InputStreamDocumentCreator documentCreator = (InputStreamDocumentCreator)documentCreatorControl.getMock();
    MockControl inputStreamControl = MockClassControl.createStrictControl(InputStream.class);
    InputStream inputStream = (InputStream)inputStreamControl.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);
   
    documentCreator.createInputStream();
    documentCreatorControl.setReturnValue(inputStream, 1);
   
    documentCreator.createDocumentFromInputStream(inputStream);
    documentCreatorControl.setReturnValue(document, 1);
   
    indexWriter.addDocument(document);
    indexWriterControl.setVoidCallable(1);
   
    inputStream.close();
    inputStreamControl.setVoidCallable(1);
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
    documentCreatorControl.replay();
    inputStreamControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
    template.addDocument(documentCreator);

    indexFactoryControl.verify();
    indexWriterControl.verify();
    documentCreatorControl.verify();
    inputStreamControl.verify();
  }
View Full Code Here

Examples of org.easymock.MockControl

      fail();
    } catch(Exception ex) {}
  }

  public void testSearcherFactorySpecified() throws Exception {
    MockControl searcherFactoryControl = MockControl.createControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();

    LuceneSearchSupport luceneSearch = new LuceneSearchSupport() {};
    luceneSearch.setSearcherFactory(searcherFactory);

    try {
View Full Code Here

Examples of org.easymock.MockControl

      fail();
    } catch(Exception ex) {}
  }

  public void testSearcherFactoryAnalyzerSpecified() throws Exception {
    MockControl searcherFactoryControl = MockControl.createControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl analyzerControl = MockClassControl.createControl(Analyzer.class);
    Analyzer analyzer = (Analyzer)analyzerControl.getMock();

    LuceneSearchSupport luceneSearch = new LuceneSearchSupport() {};
    luceneSearch.setSearcherFactory(searcherFactory);
    luceneSearch.setAnalyzer(analyzer);
   
View Full Code Here

Examples of org.easymock.MockControl

   
    luceneSearch.afterPropertiesSet();
  }

  public void testTemplateCreation() throws Exception {
    MockControl searcherFactoryControl = MockControl.createControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl analyzerControl = MockClassControl.createControl(Analyzer.class);
    Analyzer analyzer = (Analyzer)analyzerControl.getMock();

    LuceneSearchSupport luceneSearch = new LuceneSearchSupport() {};
    luceneSearch.setSearcherFactory(searcherFactory);
    luceneSearch.setAnalyzer(analyzer);
   
View Full Code Here

Examples of org.easymock.MockControl

    assertNotNull(template);
    assertEquals(template.getClass(), DefaultLuceneSearchTemplate.class);
  }

  public void testTemplateInjection() throws Exception {
    MockControl luceneSearcherTemplateControl = MockControl.createControl(LuceneSearchTemplate.class);
    LuceneSearchTemplate luceneSearchTemplate = (LuceneSearchTemplate)luceneSearcherTemplateControl.getMock();

    LuceneSearchSupport luceneSearch = new LuceneSearchSupport() {};
    luceneSearch.setLuceneSearcherTemplate(luceneSearchTemplate);
   
    luceneSearch.afterPropertiesSet();
View Full Code Here

Examples of org.easymock.MockControl

  }

  final public void testAddDocumentWithInputStreamAndManager() throws Exception {
    //Initialization of the index
    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.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);
   
    indexWriter.addDocument(document);
    indexWriterControl.setVoidCallable(1);
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
    documentHandlerManagerControl.replay();
    documentHandlerControl.replay();
    inputStreamControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory,analyzer);
    final boolean[] called = {false, false, false};
    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;
      }
    });

    indexFactoryControl.verify();
    indexWriterControl.verify();
    inputStreamControl.verify();
    documentHandlerManagerControl.verify();
    documentHandlerControl.verify();
    inputStreamControl.verify();
   
    assertTrue(called[0]);
    assertTrue(called[1]);
    assertTrue(called[2]);
  }
View Full Code Here

Examples of org.easymock.MockControl

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

Examples of org.easymock.MockControl

    assertTrue(called[2]);
  }

  final public void testAddDocumentWithManager() 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();

    DefaultDocumentHandlerManager manager = new DefaultDocumentHandlerManager();

    //Object to index
    final String text = "a text";

    //document
    final Document document = new Document();
    document.add(new Field("text", text, Field.Store.YES, Field.Index.TOKENIZED));


    final boolean[] called = {false, false};
    manager.registerDocumentHandler(new IdentityDocumentMatching("java.lang.String"), new AbstractDocumentHandler() {
      public boolean supports(Class clazz) {
        called[0]=true;
        return true;
      }

      protected Document doGetDocument(Map description, Object object) throws Exception {
        called[1]=true;
        return document;
      }
    });
   
    indexFactory.getIndexWriter();
    indexFactoryControl.setReturnValue(indexWriter, 1);

    indexWriter.addDocument(document);
    indexWriterControl.setVoidCallable(1);
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template=new DefaultLuceneIndexTemplate(indexFactory,analyzer);
    template.addDocument(new DocumentCreatorWithManager(manager, text));

    //Check if a writer has been opened
    //Check if the writer calls the addDocument method
    //Check if the writer of the template is closed
    indexFactoryControl.verify();
    indexWriterControl.verify();
   
    //Check if the writer calls the getResourceName, getResourceDescription and
    //createInputStream methods
    assertTrue(called[0]);
    assertTrue(called[1]);
View Full Code Here

Examples of org.easymock.MockControl

    assertTrue(called[1]);
  }

  final public void testAddDocumentWithManagerError() 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();

    DefaultDocumentHandlerManager manager=new DefaultDocumentHandlerManager();

    //Object to index
    final String text="a text";

    //document
    final Document document = new Document();
    document.add(new Field("text", text, Field.Store.YES, Field.Index.TOKENIZED));

    final boolean[] called = {false, false};
    manager.registerDocumentHandler(new IdentityDocumentMatching("text"), new AbstractDocumentHandler() {
      public boolean supports(Class clazz) {
        called[0] = true;
        return true;
      }

      protected Document doGetDocument(Map description, Object object) throws Exception {
        called[1] = true;
        return document;
      }
    });
   
    indexFactoryControl.replay();
    indexWriterControl.replay();

    try {
      //Lucene template
      LuceneIndexTemplate template=new DefaultLuceneIndexTemplate(indexFactory,analyzer);
      template.addDocument(new DocumentCreatorWithManager(manager, text));
      fail();
    } catch(Exception ex) {
      //Check if a writer has been opened
      //Check if the writer calls the addDocument method
      //Check if the writer of the template is closed
      indexFactoryControl.verify();
      indexWriterControl.verify();
     
      //Check if the writer calls the getResourceName, getResourceDescription and
      //createInputStream methods
      assertFalse(called[0]);
      assertFalse(called[1]);
View Full Code Here

Examples of org.easymock.MockControl

    }
  }

  final public void testAddDocumentWithManagerAndName() 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();

    DefaultDocumentHandlerManager manager=new DefaultDocumentHandlerManager();

    //Object to index
    final String text="a text";

    //document
    final Document document = new Document();
    document.add(new Field("text", text, Field.Store.YES, Field.Index.TOKENIZED));

    final boolean[] called = {false, false};
    manager.registerDocumentHandler(new IdentityDocumentMatching("text"), new AbstractDocumentHandler() {
      public boolean supports(Class clazz) {
        called[0] = true;
        return true;
      }

      protected Document doGetDocument(Map description, Object object) throws Exception {
        called[1] = true;
        return document;
      }
    });
   
    indexFactory.getIndexWriter();
    indexFactoryControl.setReturnValue(indexWriter, 1);

    indexWriter.addDocument(document);
    indexWriterControl.setVoidCallable(1);
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
    template.addDocument(new DocumentCreatorWithManager(manager, "text", text));

    //Check if a writer has been opened
    //Check if the writer calls the addDocument method
    //Check if the writer of the template is closed
    indexFactoryControl.verify();
    indexWriterControl.verify();
   
    //Check if the writer calls the getResourceName, getResourceDescription and
    //createInputStream methods
    assertTrue(called[0]);
    assertTrue(called[1]);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.