1   package org.apache.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import javax.xml.parsers.DocumentBuilder;
22  import javax.xml.parsers.DocumentBuilderFactory;
23  import javax.xml.parsers.SAXParser;
24  import javax.xml.parsers.SAXParserFactory;
25  
26  import junit.framework.TestCase;
27  
28  import org.xml.sax.XMLReader;
29  import org.xml.sax.helpers.XMLReaderFactory;
30  
31  /**
32   * Tests to check JAXP is correctly configured and classes are being loaded
33   */
34  public class JAXPTest
35      extends TestCase
36  {
37  
38      /**
39       * Constructor for JAXPTest.
40       * @param name test name
41       */
42      public JAXPTest( String name )
43      {
44          super( name );
45      }
46  
47      /**
48       * test the jaxp property for the sax parser (org.xml.sax.parser)
49       * returns the piccolo parser
50       * @throws Exception if any problems occur
51       */
52      public void testSAXParser()
53          throws Exception
54      {
55          // the sax parser should be piccolo
56          SAXParserFactory factory = SAXParserFactory.newInstance();
57          factory.setNamespaceAware( true );
58          SAXParser parser = factory.newSAXParser();
59          assertTrue( "Wrong sax parser", parser.getClass().getName().startsWith( "com.bluecast.xml." ) );
60      }
61  
62      /**
63       * test the jaxp property for the XML Reader (org.xml.sax.driver)
64       * returns the correct XMLReader
65       * @throws Exception if any problems occur
66       */
67      public void testXMLReader()
68          throws Exception
69      {
70          XMLReader reader = XMLReaderFactory.createXMLReader();
71          assertTrue( "Wrong xml reader", reader.getClass().getName().startsWith( "com.bluecast.xml." ) );
72      }
73  
74      /**
75       * Test that the DocumentBuilderFactory comes from Xerces
76       */
77      public void testDocumentBuilderFactory()
78          throws Exception
79      {
80          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
81          factory.setNamespaceAware( true );
82          DocumentBuilder builder = factory.newDocumentBuilder();
83          assertTrue( "Wrong document builder", builder.getClass().getName().startsWith( "org.apache.xerces.jaxp." ) );
84      }
85  }