KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > actions > ValidateActionTest


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.tools.actions;
21
22 import junit.framework.Test;
23 import junit.textui.TestRunner;
24 import org.netbeans.api.xml.cookies.ValidateXMLCookie;
25 import org.netbeans.junit.NbTestSuite;
26 import org.openide.nodes.Node;
27
28 public class ValidateActionTest extends AbstractCheckTest {
29
30     /** Creates new ValidateActionTest */
31     public ValidateActionTest(String JavaDoc testName) {
32         super(testName);
33     }
34
35     // TESTS ///////////////////////////////////////////////////////////////////
36

37     // *** Not well-formed ***
38

39     /** Validates document with incorrectly nested tags */
40     public void testIncorrectlyNestedTags() throws Exception JavaDoc {
41         performAction("IncorrectlyNestedTags.xml", new int[] {6});
42     }
43     
44     /** Validates document where missing closing tags */
45     public void testMissingClosingTag() throws Exception JavaDoc {
46         performAction("MissingClosingTag.xml", new int[] {7});
47     }
48     
49     /** Validates document without root element */
50     public void testMissingRootElement() throws Exception JavaDoc {
51         performAction("MissingRootElement.xml", new int[] {-1});
52     }
53
54     // *** Not valid but well-formed (DTD) ***
55

56     /** Validates document with undeclared element */
57     public void testInvalidElementName() throws Exception JavaDoc {
58         performAction("InvalidElementName.xml", new int[] {9, 11});
59     }
60     
61     /** Validates document with inaccessble DTD */
62     public void testInaccessbleDTD() throws Exception JavaDoc {
63         performAction("InaccessbleDTD.xml", new int[] {3});
64     }
65     
66     // *** Not valid but well-formed (Schema) ***
67

68     /** Validates document according to schema */
69     public void testInvalidElementNameSD() throws Exception JavaDoc {
70         performAction("InvalidElementNameSD.xml", new int[] {15});
71     }
72
73     /** Validates document according to schema */
74     public void testInvalidSchemaLocationSD() throws Exception JavaDoc {
75         performAction("InvalidSchemaLocationSD.xml", new int[] {6});
76     }
77     
78     // *** Valid (DTD) ***
79

80     /** Validates document where DTD is distributed in several folders*/
81     public void testDistributedDTD() throws Exception JavaDoc {
82         performAction("DistributedDTD.xml", 0);
83     }
84     
85     // *** Valid (Schema) ***
86

87     /** Validates document according to schema */
88     public void testValidSD() throws Exception JavaDoc {
89         performAction("ValidSD.xml", 0);
90     }
91     
92     // LIBS ////////////////////////////////////////////////////////////////////
93

94     /** Check all selected nodes. */
95     protected QaIOReporter performAction(Node[] nodes) {
96         if ((nodes == null) || (nodes.length == 0))
97             fail("Ileegal argumet 'null'");
98         
99         QaIOReporter reporter = new QaIOReporter();
100         for (int i = 0; i<nodes.length; i++) {
101             ValidateXMLCookie cake = (ValidateXMLCookie) nodes[i].getCookie(ValidateXMLCookie.class);
102             if (cake == null) fail("Cannot get 'ValidateXMLCookie'.");;
103             cake.validateXML(reporter);
104         }
105         return reporter;
106     }
107     
108     // MAIN ////////////////////////////////////////////////////////////////////
109

110 // public static Test suite() {
111
// NbTestSuite suite = new NbTestSuite();
112
// suite.addTest(new ValidateActionTest("testInvalidSchemaLocationSD"));
113
// return suite;
114
// }
115

116     /**
117      * Performs this testsuite.
118      * @param args the command line arguments
119      */

120     public static void main(String JavaDoc[] args) {
121         DEBUG = true;
122         // TestRunner.run(suite());
123
TestRunner.run(ValidateActionTest.class);
124     }
125 }
126
Popular Tags