1 package org.apache.maven.archetype.old.descriptor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }