1 37 package net.sourceforge.cruisecontrol.util; 38 39 import java.io.StringReader ; 40 import java.io.StringWriter ; 41 import java.io.Writer ; 42 43 import org.jdom.Document; 44 import org.jdom.input.SAXBuilder; 45 import org.jdom.output.XMLOutputter; 46 47 import junit.framework.TestCase; 48 49 53 public class PruneElementFilterTest extends TestCase { 54 55 private SAXBuilder builder; 56 57 protected void setUp() throws Exception { 58 builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser"); 59 builder.setXMLFilter(new PruneElementFilter("properties")); 60 } 61 62 public void testFiltering() throws Exception { 63 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" 64 + "<testsuites><testsuite><properties>" 65 + "<property/><property id=\"foo\">With some text</property>" 66 + "</properties><othertag/></testsuite></testsuites>"; 67 Document doc = builder.build(new StringReader (xml)); 68 Writer stringWriter = new StringWriter (); 69 new XMLOutputter().output(doc, stringWriter); 70 String filteredXml = stringWriter.toString(); 71 assertTrue("<properties>-element should have been filtered", 72 filteredXml.indexOf("<properties>") == -1); 73 assertTrue("<property>-elements should have been filtered", 74 filteredXml.indexOf("<property>") == -1); 75 assertTrue("<testsuite>-element should not have been filtered", 76 filteredXml.indexOf("<testsuite>") != -1); 77 assertTrue("<othertag>-element should not have been filtered", 78 filteredXml.indexOf("<othertag") != -1); 79 } 80 } 81 | Popular Tags |