KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > util > XmlUtilTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.kernel.util;
18
19 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
20 import javax.xml.parsers.SAXParserFactory JavaDoc;
21 import javax.xml.transform.TransformerFactory JavaDoc;
22
23 import junit.framework.TestCase;
24
25 /**
26  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
27  */

28 public class XmlUtilTest extends TestCase {
29     private String JavaDoc documentBuilderClassName;
30     private String JavaDoc saxParserClassName;
31     private String JavaDoc 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 JavaDoc documentBuilderFactory = XmlUtil.newDocumentBuilderFactory();
38         String JavaDoc 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 JavaDoc documentBuilderFactory = XmlUtil.newDocumentBuilderFactory();
47         String JavaDoc 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 JavaDoc saxParserFactory = XmlUtil.newSAXParserFactory();
56         String JavaDoc 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 JavaDoc saxParserFactory = XmlUtil.newSAXParserFactory();
65         String JavaDoc 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 JavaDoc transformerFactory = XmlUtil.newTransformerFactory();
74         String JavaDoc 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 JavaDoc transformerFactory = XmlUtil.newTransformerFactory();
83         String JavaDoc className = transformerFactory.getClass().getName();
84         assertEquals(transformerClassName, className);
85     }
86
87     protected void setUp() throws Exception JavaDoc {
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