@Test public void removeAllElements() throws Exception { List<ParserFeature> features = Collections.emptyList(); document = XmlHelper.parse( getClass() .getResourceAsStream( "/com/google/code/configprocessor/data/xml-target-config-2.xml"), features); RemoveAction action = new RemoveAction("/root/property[@attribute='value3']", NodeSetPolicy.ALL); XmlActionProcessingAdvisor advisor = new XmlRemoveActionProcessingAdvisor( action, expressionResolver, namespaceContext, Collections.<ParserFeature>emptyList()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + LINE_SEPARATOR + "<root>" + LINE_SEPARATOR + " <property5>" + LINE_SEPARATOR + " <nested1 a=\"1\"/>" + LINE_SEPARATOR + " </property5>" + LINE_SEPARATOR + "</root>" + LINE_SEPARATOR; executeTest(advisor, expected); }
@Test public void removeNestedElement() throws Exception { RemoveAction action = new RemoveAction("/root/property5/nested1"); XmlActionProcessingAdvisor advisor = new XmlRemoveActionProcessingAdvisor( action, expressionResolver, namespaceContext, Collections.<ParserFeature>emptyList()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + LINE_SEPARATOR + "<root>" + LINE_SEPARATOR + " <property1>value1</property1>" + LINE_SEPARATOR + " <property2/>" + LINE_SEPARATOR + " <property3 attribute=\"value3\">value3</property3>" + LINE_SEPARATOR + " <property4 attribute=\"value4\">value4</property4>" + LINE_SEPARATOR + " <property5/>" + LINE_SEPARATOR + "</root>" + LINE_SEPARATOR; executeTest(advisor, expected); }
@Test(expected = ParsingException.class) public void removeMissingSingleElement() throws Exception { RemoveAction action = new RemoveAction("/root/nonExistentProperty"); XmlActionProcessingAdvisor advisor = new XmlRemoveActionProcessingAdvisor( action, expressionResolver, namespaceContext, Collections.<ParserFeature>emptyList(), true); executeTest(advisor, null); }