KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > generator > GenerateDTDSupportTest


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 package org.netbeans.modules.xml.tools.generator;
20
21 import java.lang.reflect.Method JavaDoc;
22 import junit.textui.TestRunner;
23 import org.netbeans.modules.xml.core.XMLDataObject;
24 import org.netbeans.modules.xml.tax.cookies.TreeEditorCookie;
25 import org.netbeans.tax.TreeDocument;
26 import org.netbeans.tax.TreeElement;
27 import org.netbeans.tests.xml.XTest;
28 import org.openide.filesystems.FileObject;
29
30 /**
31  * <P>
32  * <P>
33  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
34  * <B>
35  * <BR> XML Module API Test: GenerateDTDSupportTest
36  * </B>
37  * </FONT>
38  * <BR><BR><B>What it tests:</B><BR>
39  * GenerateDTDSupportTest checks Generate DTD action on XML document without DTD. The action is
40  * accesible from popup menu on all element nodes.<BR>
41  *
42  * <BR><B>How it works:</B><BR>
43  * Test opens XML document, generates DTD for document root element and writes the DTD into log.<BR>
44  *
45  * <BR><BR><B>Settings:</B><BR>
46  * None
47  *
48  * <BR><BR><B>Output (Golden file):</B><BR>
49  * DTD for the XML document.<BR>
50  * <BR><B>Possible reasons of failure:</B>
51  * <UL>
52  * <LI type="circle">
53  * <I>None<BR></I>
54  * </LI>
55  * </UL>
56  * <BR><B>To Do:</B>
57  * <UL>
58  * <LI type="circle">
59  * Test Generate DTD action on XML document with DTD (regenerate DTD).<BR>
60  * </LI>
61  * <LI type="circle">
62  * Test Generate DTD action on different elements (no only on root element). <BR>
63  * </LI>
64  * </UL>
65  * <P>
66  */

67
68 public class GenerateDTDSupportTest extends XTest {
69     
70     /** Creates new GenerateDTDSupportTest */
71     public GenerateDTDSupportTest(String JavaDoc testName) {
72         super(testName);
73     }
74     
75     public void test() throws Exception JavaDoc {
76         XMLDataObject dao = (XMLDataObject) TestUtil.THIS.findData("Node00.xml");
77         if (dao == null) {
78             fail("\"data/Node00.xml\" data object is not found!");
79         }
80         TreeEditorCookie cake = (TreeEditorCookie) dao.getCookie(TreeEditorCookie.class);
81         TreeElement element = ((TreeDocument)cake.openDocumentRoot()).getDocumentElement();
82         FileObject primFile = dao.getPrimaryFile();
83         String JavaDoc name = primFile.getName() + "_" + element.getQName();
84         FileObject folder = primFile.getParent();
85         String JavaDoc encoding = null;
86         try {
87             encoding = element.getOwnerDocument().getEncoding();
88         } catch (NullPointerException JavaDoc e) { /* NOTHING */ }
89         
90         GenerateDTDSupport gen = new GenerateDTDSupport(dao);
91         // Original: String result = gen.xml2dtd (element, name, encoding);
92
Method JavaDoc m = gen.getClass().getDeclaredMethod("xml2dtd", new Class JavaDoc[] {String JavaDoc.class, String JavaDoc.class});
93         m.setAccessible(true);
94         String JavaDoc result = (String JavaDoc) m.invoke(gen, new Object JavaDoc[] {name, encoding});
95         
96         ref(result);
97         compareReferenceFiles();
98     }
99     
100     /**
101      * Performs this testsuite.
102      * @param args the command line arguments
103      */

104     public static void main(String JavaDoc args[]) {
105         TestRunner.run(GenerateDTDSupportTest.class);
106     }
107 }
108
Popular Tags