1 17 package org.apache.geronimo.kernel.util; 18 19 import javax.xml.parsers.DocumentBuilderFactory ; 20 import javax.xml.parsers.SAXParserFactory ; 21 import javax.xml.transform.TransformerFactory ; 22 23 import junit.framework.TestCase; 24 25 28 public class XmlUtilTest extends TestCase { 29 private String documentBuilderClassName; 30 private String saxParserClassName; 31 private String transformerClassName; 32 33 public void testDocumentBuilderDefault() { 34 System.getProperties().remove(XmlUtil.DOCUMENT_BUILDER_FACTORY); 35 assertNull(System.getProperty(XmlUtil.DOCUMENT_BUILDER_FACTORY)); 36 37 DocumentBuilderFactory documentBuilderFactory = XmlUtil.newDocumentBuilderFactory(); 38 String className = documentBuilderFactory.getClass().getName(); 39 assertEquals(documentBuilderClassName, className); 40 } 41 42 public void testDocumentBuilderOverride() { 43 System.setProperty(XmlUtil.DOCUMENT_BUILDER_FACTORY, documentBuilderClassName); 44 assertEquals(documentBuilderClassName, System.getProperty(XmlUtil.DOCUMENT_BUILDER_FACTORY)); 45 46 DocumentBuilderFactory documentBuilderFactory = XmlUtil.newDocumentBuilderFactory(); 47 String className = documentBuilderFactory.getClass().getName(); 48 assertEquals(documentBuilderClassName, className); 49 } 50 51 public void testSaxparserDefault() { 52 System.getProperties().remove(XmlUtil.SAX_PARSER_FACTORY); 53 assertNull(System.getProperty(XmlUtil.SAX_PARSER_FACTORY)); 54 55 SAXParserFactory saxParserFactory = XmlUtil.newSAXParserFactory(); 56 String className = saxParserFactory.getClass().getName(); 57 assertEquals(saxParserClassName, className); 58 } 59 60 public void testSAXParserOverride() { 61 System.setProperty(XmlUtil.SAX_PARSER_FACTORY, saxParserClassName); 62 assertEquals(saxParserClassName, System.getProperty(XmlUtil.SAX_PARSER_FACTORY)); 63 64 SAXParserFactory saxParserFactory = XmlUtil.newSAXParserFactory(); 65 String className = saxParserFactory.getClass().getName(); 66 assertEquals(saxParserClassName, className); 67 } 68 69 public void testTransformerDefault() { 70 System.getProperties().remove(XmlUtil.TRANSFORMER_FACTORY); 71 assertNull(System.getProperty(XmlUtil.TRANSFORMER_FACTORY)); 72 73 TransformerFactory transformerFactory = XmlUtil.newTransformerFactory(); 74 String className = transformerFactory.getClass().getName(); 75 assertEquals(transformerClassName, className); 76 } 77 78 public void testTransformerOverride() { 79 System.setProperty(XmlUtil.TRANSFORMER_FACTORY, transformerClassName); 80 assertEquals(transformerClassName, System.getProperty(XmlUtil.TRANSFORMER_FACTORY)); 81 82 TransformerFactory transformerFactory = XmlUtil.newTransformerFactory(); 83 String className = transformerFactory.getClass().getName(); 84 assertEquals(transformerClassName, className); 85 } 86 87 protected void setUp() throws Exception { 88 super.setUp(); 89 documentBuilderClassName = DocumentBuilderFactory.newInstance().getClass().getName(); 90 saxParserClassName = SAXParserFactory.newInstance().getClass().getName(); 91 transformerClassName = TransformerFactory.newInstance().getClass().getName(); 92 } 93 } 94 | Popular Tags |