--- old/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java 2016-07-18 00:49:52.042940772 -0700 +++ new/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java 2016-07-18 00:49:51.919002771 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,15 +23,20 @@ package javax.xml.parsers.ptests; +import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR; + import java.io.File; import java.io.FileInputStream; import java.io.FilePermission; import java.io.IOException; + import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR; -import jaxp.library.JAXPFileReadOnlyBaseTest; + +import jaxp.library.JAXPTestUtilities; + import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; import org.testng.annotations.Test; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; @@ -41,7 +46,8 @@ /** * Class contains the test cases for SAXParser API */ -public class SAXParserTest extends JAXPFileReadOnlyBaseTest { +@Listeners({jaxp.library.FilePolicy.class}) +public class SAXParserTest { /** * Provide SAXParser. * @@ -92,13 +98,7 @@ @Test(expectedExceptions = { SAXException.class }, dataProvider = "parser-provider") public void testParse03(SAXParser saxparser) throws Exception { - String workingDir = getSystemProperty("user.dir"); - setPermissions(new FilePermission(workingDir, "read")); - try { - saxparser.parse("", new HandlerBase()); - } finally { - setPermissions(); - } + saxparser.parse("", new HandlerBase()); } /** @@ -124,13 +124,7 @@ */ @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse05(SAXParser saxparser) throws Exception { - String workingDir = getSystemProperty("user.dir"); - setPermissions(new FilePermission(workingDir, "read")); - try { - saxparser.parse(new File(""), new HandlerBase()); - } finally { - setPermissions(); - } + saxparser.parse(new File(""), new HandlerBase()); } /** @@ -176,23 +170,18 @@ } /** - * Test with non-existence URI, parsing should fail and throw - * SAXException or IOException. + * Test with non-existence URI, parsing should fail and throw SAXException + * or IOException. * - * @param saxparser a SAXParser instance. - * @throws Exception If any errors occur. + * @param saxparser + * a SAXParser instance. + * @throws Exception + * If any errors occur. */ - @Test(expectedExceptions = { SAXException.class, IOException.class }, - dataProvider = "parser-provider") + @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider") public void testParse09(SAXParser saxparser) throws Exception { - String workingDir = getSystemProperty("user.dir"); - setPermissions(new FilePermission(workingDir + "/../-", "read")); - String uri = " "; - try { - saxparser.parse(uri, new DefaultHandler()); - } finally { - setPermissions(); - } + JAXPTestUtilities.tryRunWithTmpPermission(() -> saxparser.parse(" ", new DefaultHandler()), + new FilePermission(System.getProperty("user.dir") + "/ ", "read")); } /** @@ -204,14 +193,8 @@ */ @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse10(SAXParser saxparser) throws Exception { - String workingDir = getSystemProperty("user.dir"); - setPermissions(new FilePermission(workingDir, "read")); File file = new File(""); - try { - saxparser.parse(file, new DefaultHandler()); - } finally { - setPermissions(); - } + saxparser.parse(file, new DefaultHandler()); } /** @@ -248,7 +231,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse13(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream(new File( @@ -263,7 +246,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse14(SAXParser saxparser) throws Exception { saxparser.parse(new File(XML_DIR, "parsertest.xml"), new HandlerBase()); @@ -276,7 +259,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse15(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "correct.xml"))) { @@ -291,7 +274,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse16(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream( new File(XML_DIR, "parsertest.xml"))) { @@ -306,7 +289,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse17(SAXParser saxparser) throws Exception { File file = new File(XML_DIR, "correct.xml"); saxparser.parse(file.toURI().toASCIIString(), new HandlerBase()); @@ -319,7 +302,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse18(SAXParser saxparser) throws Exception { saxparser.parse(new File(XML_DIR, "valid.xml"), new HandlerBase()); @@ -332,7 +315,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse19(SAXParser saxparser) throws Exception { saxparser.parse(new File(XML_DIR, "correct.xml"), new HandlerBase()); } @@ -344,7 +327,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse20(SAXParser saxparser) throws Exception { try(FileInputStream instream = new FileInputStream(new File(XML_DIR, @@ -360,7 +343,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse21(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "correct.xml"))) { @@ -375,7 +358,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse22(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream( @@ -391,7 +374,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse23(SAXParser saxparser) throws Exception { DefaultHandler handler = new DefaultHandler(); saxparser.parse(new File(XML_DIR, "parsertest.xml"), handler); @@ -404,7 +387,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse24(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "correct.xml"))) { @@ -420,7 +403,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse25(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream( new File(XML_DIR, "parsertest.xml"))) { @@ -435,7 +418,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse26(SAXParser saxparser) throws Exception { File file = new File(XML_DIR, "correct.xml"); saxparser.parse(file.toURI().toASCIIString(), new DefaultHandler()); @@ -448,7 +431,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse27(SAXParser saxparser) throws Exception { saxparser.parse(new File(XML_DIR, "valid.xml"), new DefaultHandler()); @@ -461,7 +444,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse28(SAXParser saxparser) throws Exception { saxparser.parse(new File(XML_DIR, "correct.xml"), new DefaultHandler()); } @@ -472,7 +455,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, + @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider") public void testParse29(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream( @@ -487,7 +470,7 @@ * @param saxparser a SAXParser instance. * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider") + @Test(dataProvider = "parser-provider") public void testParse30(SAXParser saxparser) throws Exception { try (FileInputStream instream = new FileInputStream( new File(XML_DIR, "correct.xml"))) { @@ -500,7 +483,7 @@ * * @throws Exception If any errors occur. */ - @Test(groups = {"readLocalFiles"}) + @Test public void testParse31() throws Exception { try (FileInputStream instream = new FileInputStream( new File(XML_DIR, "ns4.xml"))) {