1 19 20 package org.netbeans.modules.java.freeform; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.StringReader ; 24 import org.netbeans.junit.NbTestCase; 25 import org.openide.xml.XMLUtil; 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.xml.sax.InputSource ; 29 30 34 public class JavaProjectNatureTest extends NbTestCase { 35 36 public JavaProjectNatureTest(String name) { 37 super(name); 38 } 39 40 public void testUpgradeSchema() throws Exception { 41 String 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 xml2expected = xml1.replaceAll("/1", "/2"); 49 Document doc1 = XMLUtil.parse(new InputSource (new StringReader (xml1)), false, true, null, null); 50 Element el1 = doc1.getDocumentElement(); 51 Element el2 = LookupProviderImpl.upgradeSchema(el1); 52 Document 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 baos = new ByteArrayOutputStream (); 56 XMLUtil.write(doc2, baos, "UTF-8"); 57 String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n"); 58 assertEquals("Correct upgrade result", xml2expected, xml2actual); 59 } 60 61 } 62 | Popular Tags |