KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > dtd > grammar > DTDParserTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.dtd.grammar;
21
22 import java.io.*;
23 import java.net.*;
24 import java.util.*;
25 import org.xml.sax.*;
26 import org.xml.sax.ext.*;
27 import org.xml.sax.helpers.*;
28 import org.openide.xml.*;
29 import org.openide.util.Lookup;
30 import org.netbeans.modules.xml.core.tree.ModuleEntityResolver;
31 import junit.framework.*;
32
33 /**
34  * It tests if internal and external DTD is properly parsed.
35  *
36  * Warning: this test has knowledge for following resource files:
37  * email.xml and email.dtd.
38  *
39  * @author Petr Kuzel
40  */

41 public class DTDParserTest extends TestCase {
42     
43     public DTDParserTest(java.lang.String JavaDoc testName) {
44         super(testName);
45     }
46     
47     public void testParse() {
48         
49         try {
50             DTDParser parser = new DTDParser();
51             InputSource in = new InputSource();
52             URL url = getClass().getResource("email.xml");
53             in.setSystemId(url.toExternalForm());
54             in.setByteStream(url.openConnection().getInputStream());
55             DTDGrammar dtd = parser.parse(in);
56             
57             assertTrue("Missing entity!", dtd.entities.contains("testExternalEntity"));
58             assertTrue("Missing notation!", dtd.notations.contains("testNotation"));
59             assertTrue("Missing element!", dtd.elementDecls.keySet().contains("testANYElement"));
60             assertTrue("Missing attribute!", dtd.attrDecls.keySet().contains("subject"));
61             
62             // ANY elements must contain all declared
63
Set all = (Set) dtd.elementDecls.get("testANYElement");
64             assertTrue("ANY must contain all declared!", all.containsAll(dtd.elementDecls.keySet()));
65
66             // EMPTY must be empty
67
assertTrue("EMPTY must be empty!", ((Set)dtd.elementDecls.get("attachment")).isEmpty());
68             
69             // #PCDATA mus be empty
70
assertTrue("#PCDATA must be empty!", ((Set)dtd.elementDecls.get("name")).isEmpty());
71
72         } catch (Exception JavaDoc ex) {
73             // Add your test code below by replacing the default call to fail.
74
ex.printStackTrace();
75             fail(ex.toString());
76         }
77                 
78     }
79     
80 }
81
Popular Tags