geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorJUnitTest.java
@Test
  public void generateWithFields() throws Exception {
    LuceneIndex index = mock(LuceneIndex.class);
    when(index.getName()).thenReturn("index");
    String[] fields = new String[] {"field1", "field2"};
    when(index.getFieldNames()).thenReturn(fields);

    LuceneIndexXmlGenerator generator = new LuceneIndexXmlGenerator(index);
    CacheXmlGenerator cacheXmlGenerator = mock(CacheXmlGenerator.class);
    ContentHandler handler = mock(ContentHandler.class);
    when(cacheXmlGenerator.getContentHandler()).thenReturn(handler);
    generator.generate(cacheXmlGenerator);

    ArgumentCaptor<Attributes> captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler).startElement(eq(""), eq("index"), eq("lucene:index"), captor.capture());
    Attributes value = captor.getValue();
    assertEquals("index", value.getValue(LuceneXmlConstants.NAME));

    captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, times(2)).startElement(eq(""), eq("field"), eq("lucene:field"),
        captor.capture());
    Set<String> foundFields = new HashSet<String>();
    for (Attributes fieldAttr : captor.getAllValues()) {
      foundFields.add(fieldAttr.getValue(LuceneXmlConstants.NAME));
    }

    HashSet<String> expected = new HashSet<String>(Arrays.asList(fields));
    assertEquals(expected, foundFields);

    verify(handler, times(2)).endElement(eq(""), eq("field"), eq("lucene:field"));
    verify(handler).endElement(eq(""), eq("index"), eq("lucene:index"));
  }
/**
   * Test of generating and reading cache configuration back in.
   */
Test of generating and reading cache configuration back in.
Test of generating and reading cache configuration back in .
@Test
  public void generateWithFields() throws Exception {
    LuceneIndex index = mock(LuceneIndex.class);
    when(index.getName()).thenReturn("index");
    String[] fields = new String[] {"field1", "field2"};
    when(index.getFieldNames()).thenReturn(fields);
    LuceneIndexXmlGenerator generator = new LuceneIndexXmlGenerator(index);
    CacheXmlGenerator cacheXmlGenerator = mock(CacheXmlGenerator.class);
    ContentHandler handler = mock(ContentHandler.class);
    when(cacheXmlGenerator.getContentHandler()).thenReturn(handler);
    generator.generate(cacheXmlGenerator);
    ArgumentCaptor<Attributes> captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler).startElement(eq(""), eq("index"), eq("lucene:index"), captor.capture());
    Attributes value = captor.getValue();
    assertEquals("index", value.getValue(LuceneXmlConstants.NAME));
    captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, times(2)).startElement(eq(""), eq("field"), eq("lucene:field"),
        captor.capture());
    Set<String> foundFields = new HashSet<String>();
    for (Attributes fieldAttr : captor.getAllValues()) {
      foundFields.add(fieldAttr.getValue(LuceneXmlConstants.NAME));
    }
    HashSet<String> expected = new HashSet<String>(Arrays.asList(fields));
    assertEquals(expected, foundFields);
    verify(handler, times(2)).endElement(eq(""), eq("field"), eq("lucene:field"));
    verify(handler).endElement(eq(""), eq("index"), eq("lucene:index"));
  }
@ Test public void generateWithFields ( ) throws Exception { LuceneIndex index = mock ( LuceneIndex . class ) ; when ( index . getName ( ) ) . thenReturn ( "index" ) ; String [ ] fields = new String [ ] { "field1" , "field2" } ; when ( index . getFieldNames ( ) ) . thenReturn ( fields ) ; LuceneIndexXmlGenerator generator = new LuceneIndexXmlGenerator ( index ) ; CacheXmlGenerator cacheXmlGenerator = mock ( CacheXmlGenerator . class ) ; ContentHandler handler = mock ( ContentHandler . class ) ; when ( cacheXmlGenerator . getContentHandler ( ) ) . thenReturn ( handler ) ; generator . generate ( cacheXmlGenerator ) ; ArgumentCaptor < Attributes > captor = ArgumentCaptor . forClass ( Attributes . class ) ; verify ( handler ) . startElement ( eq ( "" ) , eq ( "index" ) , eq ( "lucene:index" ) , captor . capture ( ) ) ; Attributes value = captor . getValue ( ) ; assertEquals ( "index" , value . getValue ( LuceneXmlConstants . NAME ) ) ; captor = ArgumentCaptor . forClass ( Attributes . class ) ; verify ( handler , times ( 2 ) ) . startElement ( eq ( "" ) , eq ( "field" ) , eq ( "lucene:field" ) , captor . capture ( ) ) ; Set < String > foundFields = new HashSet < String > ( ) ; for ( Attributes fieldAttr : captor . getAllValues ( ) ) { foundFields . add ( fieldAttr . getValue ( LuceneXmlConstants . NAME ) ) ; } HashSet < String > expected = new HashSet < String > ( Arrays . asList ( fields ) ) ; assertEquals ( expected , foundFields ) ; verify ( handler , times ( 2 ) ) . endElement ( eq ( "" ) , eq ( "field" ) , eq ( "lucene:field" ) ) ; verify ( handler ) . endElement ( eq ( "" ) , eq ( "index" ) , eq ( "lucene:index" ) ) ; }
Test of generating and reading cache configuration back in.
Test of generating and reading cache configuration back in .