Package org.easymock

Examples of org.easymock.MockControl


        assertEquals("Should be no hooks left after unregistration", 0, sr.getHooks(ListenerHook.class).size());
    }

    public void testRegisterListenerHookServiceFactory()
    {
        MockControl control = MockControl.createNiceControl(Bundle.class);
        Bundle b = (Bundle) control.getMock();
        control.replay();

        MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
        BundleContext c = (BundleContext) controlContext.getMock();
        controlContext.expectAndReturn(c.getBundle(), b);
        controlContext.replay();

        ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
        MockControl sfControl = MockControl.createNiceControl(ServiceFactory.class);
        sfControl.replay();
        ServiceFactory sf = (ServiceFactory) sfControl.getMock();

        assertEquals("Precondition failed", 0, sr.getHooks(EventHook.class).size());
        assertEquals("Precondition failed", 0, sr.getHooks(FindHook.class).size());
        assertEquals("Precondition failed", 0, sr.getHooks(ListenerHook.class).size());
        ServiceRegistration reg = sr.registerService(c, new String [] {ListenerHook.class.getName()}, sf, new Hashtable());
View Full Code Here


        assertEquals("Should be no hooks left after unregistration", 0, sr.getHooks(ListenerHook.class).size());
    }

    public void testRegisterCombinedService()
    {
        MockControl control = MockControl.createNiceControl(Bundle.class);
        Bundle b = (Bundle) control.getMock();
        control.replay();

        MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
        BundleContext c = (BundleContext) controlContext.getMock();
        controlContext.expectAndReturn(c.getBundle(), b);
        controlContext.replay();

        ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
        class CombinedService implements ListenerHook, FindHook, EventHook, Runnable
        {
            public void added(Collection listeners)
View Full Code Here

        assertEquals("Should be no hooks left after unregistration", 0, sr.getHooks(ListenerHook.class).size());
    }

    public void testRegisterPlainService()
    {
        MockControl control = MockControl.createNiceControl(Bundle.class);
        Bundle b = (Bundle) control.getMock();
        control.replay();

        MockControl controlContext = MockControl.createNiceControl(BundleContext.class);
        BundleContext c = (BundleContext) controlContext.getMock();
        controlContext.expectAndReturn(c.getBundle(), b);
        controlContext.replay();

        ServiceRegistry sr = new ServiceRegistry(new Logger(), null);
        String svcObj = "hello";
        assertEquals("Precondition failed", 0, sr.getHooks(EventHook.class).size());
        assertEquals("Precondition failed", 0, sr.getHooks(FindHook.class).size());
View Full Code Here

    } catch (DocumentHandlerException ex) {
    }
  }

  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

  /*
   * Test pour void index(String)
   */
  final public void testIndexStringIfDirectoryNotExist() throws Exception {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    MockControl indexFactoryControl = MockControl.createControl(IndexFactory.class);
    IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();

    indexFactoryControl.replay();
   
    //Indexer
    DefaultDirectoryIndexer indexer = new DefaultDirectoryIndexer(indexFactory);
    File baseDirectory = getBaseDirectoryToIndex();
    File wrongBaseDirectory = new File(baseDirectory.getCanonicalPath()+"/test");

    try {
      indexer.index(wrongBaseDirectory.getAbsolutePath());
      fail();
    } catch(LuceneIndexingException ex) {
    }
   
    indexFactoryControl.verify();
  }
View Full Code Here

    resultSetControl.verify();
  }

  public void testGetDocument() throws Exception {
    MockControl resultSetControl = MockControl.createControl(ResultSet.class);
    ResultSet resultSet = (ResultSet)resultSetControl.getMock();
   
    String sql = "sql";
    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]);
    assertEquals(sqlRequests[0].getParams()[1], params[1]);
    assertEquals(sqlRequests[0].getTypes()[0], paramTypes[0]);
View Full Code Here

    assertTrue(deletions);
  }

  final public void testGetMaxDoc() throws Exception {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
    IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
    MockControl indexReaderControl = MockControl.createStrictControl(LuceneIndexReader.class);
    LuceneIndexReader indexReader = (LuceneIndexReader)indexReaderControl.getMock();

    indexFactory.getIndexReader();
    indexFactoryControl.setReturnValue(indexReader, 1);
   
    indexReader.maxDoc();
    indexReaderControl.setReturnValue(3, 1);
   
    indexReader.close();
    indexReaderControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexReaderControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
    int maxDoc = template.getMaxDoc();

    indexFactoryControl.verify();
    indexReaderControl.verify();
   
    assertEquals(maxDoc, 3);
  }
View Full Code Here

    assertEquals(maxDoc, 3);
  }

  final public void testGetNumDocs() throws Exception {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
    IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
    MockControl indexReaderControl = MockControl.createStrictControl(LuceneIndexReader.class);
    LuceneIndexReader indexReader = (LuceneIndexReader)indexReaderControl.getMock();

    indexFactory.getIndexReader();
    indexFactoryControl.setReturnValue(indexReader, 1);
   
    indexReader.numDocs();
    indexReaderControl.setReturnValue(3, 1);
   
    indexReader.close();
    indexReaderControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexReaderControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
    int numDoc = template.getNumDocs();

    indexFactoryControl.verify();
    indexReaderControl.verify();
   
    assertEquals(numDoc, 3);
  }
View Full Code Here

    assertEquals(numDoc, 3);
  }

  final public void testAddDocument() 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(DocumentCreator.class);
    DocumentCreator documentCreator = (DocumentCreator)documentCreatorControl.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.createDocument();
    documentCreatorControl.setReturnValue(document);
   
    indexWriter.addDocument(document);
    indexWriterControl.setVoidCallable(1);
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
    documentCreatorControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
    template.addDocument(documentCreator);

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

    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

TOP

Related Classes of org.easymock.MockControl

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.