KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > JavaProjectNatureTest


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.java.freeform;
21
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.StringReader JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.xml.XMLUtil;
26 import org.w3c.dom.Document JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28 import org.xml.sax.InputSource JavaDoc;
29
30 /**
31  * Test stuff in JavaProjectNature.
32  * @author Jesse Glick
33  */

34 public class JavaProjectNatureTest extends NbTestCase {
35
36     public JavaProjectNatureTest(String JavaDoc name) {
37         super(name);
38     }
39
40     public void testUpgradeSchema() throws Exception JavaDoc {
41         // Formatting has to be the same as Xerces' formatter produces for this test to pass:
42
String JavaDoc xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
43                       "<java-data xmlns=\"http://www.netbeans.org/ns/freeform-project-java/1\">\n" +
44                       " <!-- Hello there. -->\n" +
45                       " <foo bar=\"baz\" quux=\"whatever\">hello</foo>\n" +
46                       " <x>OK</x>\n" +
47                       "</java-data>\n";
48         String JavaDoc xml2expected = xml1.replaceAll("/1", "/2");
49         Document JavaDoc doc1 = XMLUtil.parse(new InputSource JavaDoc(new StringReader JavaDoc(xml1)), false, true, null, null);
50         Element JavaDoc el1 = doc1.getDocumentElement();
51         Element JavaDoc el2 = LookupProviderImpl.upgradeSchema(el1);
52         Document JavaDoc doc2 = XMLUtil.createDocument(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, null, null);
53         doc2.removeChild(doc2.getDocumentElement());
54         doc2.appendChild(doc2.importNode(el2, true));
55         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
56         XMLUtil.write(doc2, baos, "UTF-8");
57         String JavaDoc xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
58         assertEquals("Correct upgrade result", xml2expected, xml2actual);
59     }
60     
61 }
62
Popular Tags