KickJava   Java API By Example, From Geeks To Geeks.

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


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.textui.TestRunner;
23 import org.netbeans.api.xml.cookies.CheckXMLCookie;
24 import org.openide.nodes.Node;
25
26 public class CheckActionTest extends AbstractCheckTest {
27
28     /** Creates new ValidateActionTest */
29     public CheckActionTest(String JavaDoc testName) {
30         super(testName);
31     }
32
33     // TESTS ///////////////////////////////////////////////////////////////////
34

35     // *** Not well-formed ***
36

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

54     /** Validates document with undeclared element */
55     public void testInvalidElementName() throws Exception JavaDoc {
56         performAction("InvalidElementName.xml", 0);
57     }
58     
59     /** Validates document with inaccessble DTD */
60     public void testInaccessbleDTD() throws Exception JavaDoc {
61         performAction("InaccessbleDTD.xml", new int[] {3});
62     }
63     
64     // *** Valid ***
65

66     /** Validates document where DTD is distributed in several folders*/
67     public void testDistributedDTD() throws Exception JavaDoc {
68         performAction("DistributedDTD.xml", 0);
69     }
70     
71     // LIBS ////////////////////////////////////////////////////////////////////
72

73     /** Check all selected nodes. */
74     protected QaIOReporter performAction(Node[] nodes) {
75         if ((nodes == null) || (nodes.length == 0))
76             fail("Ileegal argumet 'null'");
77         
78         QaIOReporter reporter = new QaIOReporter();
79         for (int i = 0; i<nodes.length; i++) {
80             CheckXMLCookie cake = (CheckXMLCookie) nodes[i].getCookie(CheckXMLCookie.class);
81             if (cake == null) fail("Cannot get 'ValidateXMLCookie'.");;
82             cake.checkXML(reporter);
83         }
84         return reporter;
85     }
86     
87     // MAIN ////////////////////////////////////////////////////////////////////
88

89     /**
90      * Performs this testsuite.
91      * @param args the command line arguments
92      */

93     public static void main(String JavaDoc args[]) {
94         TestRunner.run(CheckActionTest.class);
95     }
96 }
97
Popular Tags