CR6517717Test.java revision 968:874082a9b565
110217Sphk/*
215284Snate * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
315284Snate * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
415284Snate *
515284Snate * This code is free software; you can redistribute it and/or modify it
615284Snate * under the terms of the GNU General Public License version 2 only, as
715284Snate * published by the Free Software Foundation.
815284Snate *
915284Snate * This code is distributed in the hope that it will be useful, but WITHOUT
1015284Snate * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1115284Snate * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1215284Snate * version 2 for more details (a copy is included in the LICENSE file that
1315284Snate * accompanied this code).
1415284Snate *
1515284Snate * You should have received a copy of the GNU General Public License version
1615284Snate * 2 along with this work; if not, write to the Free Software Foundation,
1715284Snate * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1815284Snate *
1915284Snate * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2015284Snate * or visit www.oracle.com if you need additional information or have any
2115284Snate * questions.
2215284Snate */
2315284Snate
2415284Snatepackage dom;
2515284Snate
2650479Speterimport java.io.IOException;
2710217Sphkimport java.io.StringReader;
2815284Snate
2915177Snateimport javax.xml.parsers.DocumentBuilder;
3010217Sphkimport javax.xml.parsers.DocumentBuilderFactory;
3110217Sphkimport javax.xml.parsers.ParserConfigurationException;
3215177Snate
3310217Sphkimport org.testng.Assert;
3415177Snateimport org.testng.annotations.Listeners;
3510217Sphkimport org.testng.annotations.Test;
3615177Snateimport org.w3c.dom.DOMException;
3710217Sphkimport org.w3c.dom.Document;
3810217Sphkimport org.w3c.dom.Entity;
3915177Snateimport org.xml.sax.InputSource;
4015177Snateimport org.xml.sax.SAXException;
4115177Snate
4210217Sphk/*
4315177Snate * @test
44185033Simp * @bug 6517717
4510217Sphk * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
4615177Snate * @run testng/othervm -DrunSecMngr=true dom.CR6517717Test
4715177Snate * @run testng/othervm dom.CR6517717Test
4815177Snate * @summary Test Node.setPrefix(prefix) shall throw DOMException.NO_MODIFICATION_ALLOWED_ERR if the node is read-only.
4910217Sphk */
5010217Sphk@Listeners({jaxp.library.BasePolicy.class})
5110217Sphkpublic class CR6517717Test {
5215177Snate
5310217Sphk    @Test
5410217Sphk    public void testCanonicalForm001() {
5510217Sphk        String data = "<?xml version=\"1.0\" ?>" + "<!DOCTYPE test:root [" + "<!ELEMENT test:root ANY>" + "<!ENTITY ent \"foo\">"
5610217Sphk                + "<!ATTLIST test:root test:a CDATA #FIXED \"qqq\">" + "]>" + "<test:root xmlns:test=\"http://xxxx.xx/\">" + "</test:root>";
5710217Sphk
5810217Sphk        Document document = null;
5915177Snate        try {
6015177Snate            DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
6110217Sphk            document = docBuilder.parse(new InputSource(new StringReader(data)));
6210217Sphk        } catch (ParserConfigurationException e) {
6310217Sphk            System.out.println(e.toString());
6410217Sphk        } catch (IOException e) {
6515177Snate            System.out.println(e.toString());
6610217Sphk        } catch (SAXException e) {
6710217Sphk            System.out.println(e.toString());
6810217Sphk        }
6915177Snate
7015177Snate        Entity anEntity = (Entity) document.getDoctype().getEntities().item(0);
7110217Sphk        boolean success = false;
7210217Sphk        try {
7310217Sphk            anEntity.setPrefix("test1");
7415177Snate            System.out.println("Should throw DOMException: NO_MODIFICATION_ALLOWED_ERR ");
7510217Sphk        } catch (DOMException e) {
7610217Sphk            if (e.code == DOMException.NO_MODIFICATION_ALLOWED_ERR) {
7710217Sphk                System.out.println("OK");
7810217Sphk                success = true;
7915177Snate            } else {
8015177Snate                System.out.println("should throw DOMException.NO_MODIFICATION_ALLOWED_ERR (7). The error returned is (" + e.code + ")" + e.getMessage());
8110217Sphk            }
8210217Sphk        }
8310217Sphk        if (!success) {
8415177Snate            Assert.fail("should throw DOMException.NO_MODIFICATION_ALLOWED_ERR (7).");
8510217Sphk        }
8610217Sphk
8710217Sphk    }
8810217Sphk}
8910217Sphk
9010217Sphk