View Javadoc

1   package org.apache.maven.archetype.old.descriptor;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.InputStream;
24  
25  import javax.xml.parsers.SAXParser;
26  import javax.xml.parsers.SAXParserFactory;
27  
28  import org.codehaus.plexus.PlexusTestCase;
29  import org.codehaus.plexus.util.IOUtil;
30  import org.xml.sax.InputSource;
31  import org.xml.sax.SAXException;
32  import org.xml.sax.SAXParseException;
33  import org.xml.sax.helpers.DefaultHandler;
34  
35  
36  public class ArchetypeXsdTest
37      extends PlexusTestCase
38  {
39      private static final String ARCHETYPE_XSD = "archetype-1.0.0.xsd";
40  
41      public void testXsd()
42          throws Exception
43      {
44          File archetypeXsd = new File( getBasedir(), "/target/generated-site/xsd/" + ARCHETYPE_XSD );
45  
46          SAXParserFactory factory = SAXParserFactory.newInstance();
47          factory.setValidating( true );
48          factory.setNamespaceAware( true );
49          SAXParser saxParser = factory.newSAXParser();
50          saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
51                                 "http://www.w3.org/2001/XMLSchema" );
52          saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", archetypeXsd );
53  
54          InputStream in = getClass().getResourceAsStream( "sample-archetype.xml" );
55          try
56          {
57              saxParser.parse( new InputSource( in ), new Handler() );
58          }
59          finally
60          {
61              IOUtil.close( in );
62          }
63      }
64  
65      private static class Handler
66          extends DefaultHandler
67      {
68          public void warning ( SAXParseException e )
69              throws SAXException
70          {
71              throw e;
72          }
73  
74          public void error ( SAXParseException e )
75              throws SAXException
76          {
77              throw e;
78          }
79      }
80  }