@Override void endElement(Stack<Object> stack) { RegionMapping mapping = (RegionMapping) stack.pop(); RegionCreation regionCreation = (RegionCreation) stack.peek(); regionCreation.getExtensionPoint().addExtension(new RegionMappingConfiguration(mapping)); } };
@Override public void endElement(String uri, String localName, String qName) throws SAXException { switch (localName) { case ELEMENT_CACHE: { MockCacheExtension extension = (MockCacheExtension) stack.pop(); CacheCreation cache = (CacheCreation) stack.peek(); cache.getExtensionPoint().addExtension(extension); break; } case ELEMENT_REGION: { MockRegionExtension extension = (MockRegionExtension) stack.pop(); RegionCreation region = (RegionCreation) stack.peek(); region.getExtensionPoint().addExtension(extension); break; } default: throw new SAXParseException("Unexpected element '" + localName + "'.", documentLocator); } }
private void startIndex(Attributes atts) { if (!(stack.peek() instanceof RegionCreation)) { throw new CacheXmlException("lucene <index> elements must occur within <region> elements"); } final RegionCreation region = (RegionCreation) stack.peek(); String name = atts.getValue(NAME); LuceneIndexCreation indexCreation = new LuceneIndexCreation(); indexCreation.setName(name); indexCreation.setRegion(region); region.getExtensionPoint().addExtension(indexCreation); stack.push(indexCreation); cache = (CacheCreation) region.getCache(); }
@Before public void setup() { attributes = mock(Attributes.class); regionCreation = mock(RegionCreation.class); extensionPoint = mock(ExtensionPoint.class); when(regionCreation.getExtensionPoint()).thenReturn(extensionPoint); stack = new Stack<>(); }
@Before public void setup() { attributes = mock(Attributes.class); regionCreation = mock(RegionCreation.class); when(regionCreation.getFullPath()).thenReturn("/region"); extensionPoint = mock(ExtensionPoint.class); when(regionCreation.getExtensionPoint()).thenReturn(extensionPoint); stack = new Stack<>(); }
@Before public void setUp() { this.parser = new LuceneXmlParser(); CacheCreation cache = Mockito.mock(CacheCreation.class); RegionCreation regionCreation = Mockito.mock(RegionCreation.class); RegionAttributesCreation rac = Mockito.mock(RegionAttributesCreation.class); Mockito.when(regionCreation.getFullPath()).thenReturn("/region"); Mockito.when(regionCreation.getAttributes()).thenReturn(rac); Mockito.when(regionCreation.getExtensionPoint()) .thenReturn(new SimpleExtensionPoint(this.rc, this.rc)); this.rc = regionCreation; this.stack = new Stack<Object>(); stack.push(cache); stack.push(rc); this.parser.setStack(stack); }
/** * Test method for {@link RegionCreation#getExtensionPoint()}. * * Assert that method returns a {@link SimpleExtensionPoint} instance and assume that * {@link SimpleExtensionPointJUnitTest} has covered the rest. */ @Test public void testGetExtensionPoint() { final CacheCreation cache = new CacheCreation(); final RegionCreation region = new RegionCreation(cache, "test"); final ExtensionPoint<Region<?, ?>> extensionPoint = region.getExtensionPoint(); assertNotNull(extensionPoint); assertEquals(extensionPoint.getClass(), SimpleExtensionPoint.class); }
@Test public void generateWithFields() throws SAXException { AttributesImpl attrs = new AttributesImpl(); XmlGeneratorUtils.addAttribute(attrs, LuceneXmlConstants.NAME, "index"); this.parser.startElement(LuceneXmlConstants.NAMESPACE, LuceneXmlConstants.INDEX, null, attrs); addField("field1"); addField("field2"); addField("field3", KeywordAnalyzer.class.getName()); this.parser.endElement(LuceneXmlConstants.NAMESPACE, LuceneXmlConstants.INDEX, null); assertEquals(this.rc, this.stack.peek()); LuceneIndexCreation index = (LuceneIndexCreation) this.rc.getExtensionPoint().getExtensions().iterator().next(); assertEquals("index", index.getName()); assertArrayEquals(new String[] {"field1", "field2", "field3"}, index.getFieldNames()); // Assert analyzers Map<String, Analyzer> fieldAnalyzers = index.getFieldAnalyzers(); assertEquals(1, fieldAnalyzers.size()); assertTrue(fieldAnalyzers.containsKey("field3")); assertTrue(fieldAnalyzers.get("field3") instanceof KeywordAnalyzer); }