View Javadoc
1   package org.codehaus.modello.plugin.xsd;
2   
3   /*
4    * Copyright (c) 2004, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  
25  import javax.xml.parsers.SAXParser;
26  
27  import java.util.Properties;
28  
29  import org.codehaus.modello.AbstractModelloGeneratorTest;
30  import org.codehaus.modello.core.ModelloCore;
31  import org.codehaus.modello.model.Model;
32  import org.xml.sax.SAXException;
33  import org.xml.sax.SAXParseException;
34  import org.xml.sax.helpers.DefaultHandler;
35  
36  /**
37   * Check that features.mdo (which tries to be the most complete model) can be checked against XSD generated from
38   * Modello model <code>modello.mdo</code>.
39   *
40   * @author Hervé Boutemy
41   */
42  public class ModelloXsdGeneratorTest extends AbstractModelloGeneratorTest {
43      public ModelloXsdGeneratorTest() {
44          super("modello");
45      }
46  
47      public void testXsdGenerator() throws Throwable {
48          ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE);
49  
50          Properties parameters = getModelloParameters("1.4.0");
51  
52          Model model = modello.loadModel(getTestFile("../../src/main/mdo/modello.mdo"));
53  
54          modello.generate(model, "xsd", parameters);
55  
56          SAXParser saxParser = createSaxParserWithSchema("modello-1.4.0.xsd");
57  
58          // first self-test: validate Modello model with xsd generated from it
59          saxParser.parse(getTestFile("../../src/main/mdo/modello.mdo"), new Handler());
60  
61          // then features.mdo
62          saxParser.parse(getClass().getResourceAsStream("/features.mdo"), new Handler());
63      }
64  
65      private static class Handler extends DefaultHandler {
66          public void warning(SAXParseException e) throws SAXException {
67              throw e;
68          }
69  
70          public void error(SAXParseException e) throws SAXException {
71              throw e;
72          }
73      }
74  }