@Override void startElement(Stack<Object> stack, Attributes attributes) { if (!(stack.peek() instanceof RegionCreation)) { throw new CacheXmlException( "<jdbc:mapping> elements must occur within <region> elements"); } RegionCreation regionCreation = (RegionCreation) stack.peek(); RegionMapping mapping = new RegionMapping(); mapping.setRegionName(regionCreation.getFullPath().substring(1)); mapping.setDataSourceName( attributes.getValue(JdbcConnectorServiceXmlParser.DATA_SOURCE)); mapping.setTableName(attributes.getValue(JdbcConnectorServiceXmlParser.TABLE)); mapping.setPdxName(attributes.getValue(JdbcConnectorServiceXmlParser.PDX_NAME)); mapping.setIds(attributes.getValue(JdbcConnectorServiceXmlParser.IDS)); mapping.setCatalog(attributes.getValue(JdbcConnectorServiceXmlParser.CATALOG)); mapping.setSchema(attributes.getValue(JdbcConnectorServiceXmlParser.SCHEMA)); stack.push(mapping); }
@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<>(); }
/** * Creates a new <code>RegionCreation</code> with the given name and with the default * <code>RegionAttributes</code>. */ public RegionCreation(CacheCreation cache, RegionCreation parent, String name, String refid) { this.cache = cache; if (parent != null) { this.fullPath = parent.getFullPath() + SEPARATOR + name; } else { this.fullPath = SEPARATOR + name; } this.name = name; this.refid = refid; this.attrs = new RegionAttributesCreation(this.cache); if (refid != null) { this.attrs.setRefid(refid); this.attrs.inheritAttributes(cache); } }
@Test public void startElementRegionMapping() { when(attributes.getValue(DATA_SOURCE)).thenReturn("connectionName"); when(attributes.getValue(TABLE)).thenReturn("table"); when(attributes.getValue(PDX_NAME)).thenReturn("pdxClass"); when(attributes.getValue(IDS)).thenReturn("ids"); when(attributes.getValue(CATALOG)).thenReturn("catalog"); when(attributes.getValue(SCHEMA)).thenReturn("schema"); when(regionCreation.getFullPath()).thenReturn("/region"); stack.push(regionCreation); ElementType.JDBC_MAPPING.startElement(stack, attributes); RegionMapping regionMapping = (RegionMapping) stack.pop(); assertThat(regionMapping.getRegionName()).isEqualTo("region"); assertThat(regionMapping.getDataSourceName()).isEqualTo("connectionName"); assertThat(regionMapping.getTableName()).isEqualTo("table"); assertThat(regionMapping.getPdxName()).isEqualTo("pdxClass"); assertThat(regionMapping.getIds()).isEqualTo("ids"); assertThat(regionMapping.getCatalog()).isEqualTo("catalog"); assertThat(regionMapping.getSchema()).isEqualTo("schema"); }
@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); }