KickJava   Java API By Example, From Geeks To Geeks.

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


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.DTDDataObject;
24 import org.netbeans.tests.xml.XTest;
25
26 //import org.openide.*;
27
import org.openide.filesystems.FileObject;
28
29 /**
30  * <P>
31  * <P>
32  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
33  * <B>
34  * <BR> XML Module API Test: XMLGenerator2Test
35  * </B>
36  * </FONT>
37  * <BR><BR><B>What it tests:</B><BR>
38  * XMLGenerator2Test checks 'Generate DOM Tree Scanner' action on DTD document. The action is
39  * accesible from popup menu an all DTD document nodes.<BR>
40  *
41  * <BR><B>How it works:</B><BR>
42  * Test opens DTD document, generates Java source text for the document and writes it into output.<BR>
43  *
44  * <BR><BR><B>Settings:</B><BR>
45  * None
46  *
47  * <BR><BR><B>Output (Golden file):</B><BR>
48  * Scanner of DOM tree as Java source text.<BR>
49  *
50  * <BR><B>Possible reasons of failure:</B>
51  * <UL>
52  * <LI type="circle">
53  * <I>None<BR></I>
54  * </LI>
55  * </UL>
56  * <P>
57  */

58
59 public class GenerateDOMScannerSupportTest extends XTest {
60     
61     /** Creates new CoreSettingsTest */
62     public GenerateDOMScannerSupportTest(String JavaDoc testName) {
63         super(testName);
64     }
65     
66     public void test() throws Exception JavaDoc {
67         DTDDataObject dao = (DTDDataObject) TestUtil.THIS.findData("books.dtd");
68         if (dao == null) {
69             fail("\"data/books.dtd\" data object is not found!");
70         }
71         FileObject primFile = dao.getPrimaryFile();
72         String JavaDoc rawName = primFile.getName();
73         String JavaDoc name = rawName.substring(0,1).toUpperCase() + rawName.substring(1) + "Scanner";
74         FileObject folder = primFile.getParent();
75         String JavaDoc packageName = folder.getPackageName('.');
76         GenerateDOMScannerSupport gen = new GenerateDOMScannerSupport(dao);
77         // prepareDOMScanner() is private at GenerateDOMScannerSupport.class
78
Method JavaDoc m = gen.getClass().getDeclaredMethod("prepareDOMScanner", new Class JavaDoc[] {String JavaDoc.class, String JavaDoc.class, FileObject.class});
79         m.setAccessible(true);
80         String JavaDoc result = (String JavaDoc) m.invoke(gen, new Object JavaDoc[] {name, packageName, primFile});
81         // first comment contains variable informations - remove it
82
result = TestUtil.replaceString(result, "/*", "*/", "/* REMOVED */");
83         ref(result);
84         compareReferenceFiles();
85     }
86     
87     /**
88      * Performs this testsuite.
89      * @param args the command line arguments
90      */

91     public static void main(String JavaDoc args[]) {
92         TestRunner.run(GenerateDOMScannerSupportTest.class);
93     }
94 }
95
Popular Tags