use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeNewUnnamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element that does
* not have a name or id attribute, <code>jndi-bindings</code>. It should be added between
* <code>pdx</code> and <code>region</code> elements.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeNewUnnamed() throws Exception {
final String xPath = "/cache:cache/cache:jndi-bindings";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeNewUnnamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("jndi-bindings").withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final List<Node> childElements = getElementNodes(config.getFirstChild().getChildNodes());
assertEquals("pdx", childElements.get(2).getNodeName());
assertEquals("jndi-bindings", childElements.get(3).getNodeName());
assertEquals("region", childElements.get(4).getNodeName());
}
Aggregations