use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeReplaceUnnamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element that does
* not have a name or id attribute, <code>pdx</code>. It should replace <code>pdx</code> element.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeReplaceUnnamed() throws Exception {
final String xPath = "/cache:cache/cache:pdx";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals("foo", XmlUtils.getAttribute(element, "disk-store-name"));
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeReplaceUnnamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals("bar", XmlUtils.getAttribute(element, "disk-store-name"));
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("pdx").withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals("bar", XmlUtils.getAttribute(element, "disk-store-name"));
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeNewUnnamedExtension.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with an {@link Extension} that does not
* have a name or id attribute. It should be added to the end of the config xml. Attempts a name
* collision with test:region, it should not collide with the similarly named cache:region
* element.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeNewUnnamedExtension() throws Exception {
final String xPath = "/cache:cache/test:region";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeNewUnnamedExtension.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
assertEquals("test:region", element.getNodeName());
final XmlEntity xmlEntity = XmlEntity.builder().withType("region").withNamespace(TEST_PREFIX, TEST_NAMESPACE).withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
assertEquals("test:region", element.getNodeName());
final List<Node> childElements = getElementNodes(config.getFirstChild().getChildNodes());
assertEquals("test:cache", childElements.get(5).getNodeName());
assertEquals("test:region", childElements.get(6).getNodeName());
assertEquals(7, childElements.size());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testDeleteNodeUnnamedExtension.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with an {@link Extension} that does not
* have a name or id attribute, <code>test:cache</code>. It should remove the existing
* <code>test:cache</code> element.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testDeleteNodeUnnamedExtension() throws Exception {
final String xPath = "/cache:cache/test:cache";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals("1", XmlUtils.getAttribute(element, "value"));
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testDeleteNodeUnnamedExtension.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final XmlEntity xmlEntity = XmlEntity.builder().withType("cache").withNamespace(TEST_PREFIX, TEST_NAMESPACE).withConfig(changes).build();
XmlUtils.deleteNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class CreateMockCacheExtensionFunction method execute.
@Override
public void execute(FunctionContext context) {
final Cache cache = CacheFactory.getAnyInstance();
if (!(cache instanceof Extensible)) {
throw new FunctionException("Not extensible cache.");
}
final String value = (String) ((Object[]) context.getArguments())[0];
@SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
final MockCacheExtension extension = new MockCacheExtension(value);
extension.beforeCreate(extensible, cache);
extension.onCreate(extensible, extensible);
final XmlEntity xmlEntity = XmlEntity.builder().withType(ELEMENT_CACHE).withNamespace(PREFIX, NAMESPACE).build();
final ResultSender<Object> resultSender = context.getResultSender();
final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock cache extension created on \"{0}\"", new Object[] { memberNameOrId })));
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class CreateMockRegionExtensionFunction method execute.
@Override
public void execute(FunctionContext context) {
final Cache cache = CacheFactory.getAnyInstance();
final Region<?, ?> region = cache.getRegion((String) ((Object[]) context.getArguments())[0]);
if (!(region instanceof Extensible)) {
throw new FunctionException("Not extensible region.");
}
final String value = (String) ((Object[]) context.getArguments())[1];
@SuppressWarnings("unchecked") final Extensible<Region<?, ?>> extensible = (Extensible<Region<?, ?>>) region;
final MockRegionExtension extension = new MockRegionExtension(value);
extension.beforeCreate(extensible, cache);
extension.onCreate(extensible, extensible);
XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", region.getName());
final ResultSender<Object> resultSender = context.getResultSender();
final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock region extension \"{0}\" created on \"{1}\"", new Object[] { region.getFullPath(), memberNameOrId })));
}
Aggregations