| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package org.netbeans.modules.web.freeform; |
| |
| import java.io.ByteArrayOutputStream; |
| import java.io.StringReader; |
| import org.netbeans.junit.NbTestCase; |
| import org.openide.xml.XMLUtil; |
| import org.w3c.dom.Document; |
| import org.w3c.dom.Element; |
| import org.xml.sax.InputSource; |
| |
| /** |
| * Test stuff in WebProjectNature. |
| * @author Jesse Glick, Tomas Mysik |
| * @see org.netbeans.modules.java.freeform.JavaProjectNature |
| */ |
| public class WebProjectNatureTest extends NbTestCase { |
| |
| public WebProjectNatureTest(String name) { |
| super(name); |
| } |
| |
| public void testUpgradeSchema() throws Exception { |
| // Formatting has to be the same as Xerces' formatter produces for this test to pass: |
| String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| "<web-data xmlns=\"http://www.netbeans.org/ns/freeform-project-web/1\">\n" + |
| " <!-- Hello there. -->\n" + |
| " <foo bar=\"baz\" quux=\"whatever\">hello</foo>\n" + |
| " <x>OK</x>\n" + |
| "</web-data>\n"; |
| String xml2expected = xml1.replaceAll("/1", "/2"); |
| Document doc1 = XMLUtil.parse(new InputSource(new StringReader(xml1)), false, true, null, null); |
| Element el1 = doc1.getDocumentElement(); |
| Element el2 = LookupProviderImpl.upgradeSchema(el1); |
| Document doc2 = XMLUtil.createDocument(WebProjectNature.EL_WEB, WebProjectNature.NS_WEB_2, null, null); |
| doc2.removeChild(doc2.getDocumentElement()); |
| doc2.appendChild(doc2.importNode(el2, true)); |
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| XMLUtil.write(doc2, baos, "UTF-8"); |
| String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n"); |
| assertEquals("Correct upgrade result", xml2expected, xml2actual); |
| } |
| |
| } |