Search in sources :

Example 1 with CacheXmlGenerator

use of org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator in project geode by apache.

the class LuceneIndexXmlGeneratorJUnitTest method generateWithFields.

/**
   * 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"));
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CacheXmlGenerator(org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) HashSet(java.util.HashSet) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

HashSet (java.util.HashSet)1 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)1 CacheXmlGenerator (org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1 Attributes (org.xml.sax.Attributes)1 ContentHandler (org.xml.sax.ContentHandler)1