Search in sources :

Example 46 with XmlEntity

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());
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)46 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)25 DistributedMember (org.apache.geode.distributed.DistributedMember)18 Cache (org.apache.geode.cache.Cache)17 Result (org.apache.geode.management.cli.Result)17 CliCommand (org.springframework.shell.core.annotation.CliCommand)16 CliMetaData (org.apache.geode.management.cli.CliMetaData)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 InternalCache (org.apache.geode.internal.cache.InternalCache)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)11 Test (org.junit.Test)10 InputStreamReader (java.io.InputStreamReader)9 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Document (org.w3c.dom.Document)9 Element (org.w3c.dom.Element)9 NodeList (org.w3c.dom.NodeList)9 ConverterHint (org.apache.geode.management.cli.ConverterHint)7