6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package javax.xml.transform.ptests; 24 25 import java.io.File; 26 import javax.xml.transform.Transformer; 27 import javax.xml.transform.TransformerException; 28 import javax.xml.transform.TransformerFactory; 29 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 30 import javax.xml.transform.sax.SAXResult; 31 import javax.xml.transform.stream.StreamSource; 32 import static org.testng.Assert.assertEquals; 33 import static org.testng.Assert.assertNotNull; 34 import static org.testng.Assert.assertNull; 35 import static org.testng.Assert.fail; 36 import org.testng.annotations.Test; 37 38 /** 39 * Basic test for TransformerException specification. 40 */ 41 public class TransformerExcpTest { 42 /** 43 * Transform an unformatted xslt file. TransformerException is thrown. 44 */ 45 @Test 46 public void tfexception() { 47 try { 48 // invalid.xsl has well-formedness error. Therefore transform throws 49 // TransformerException 50 StreamSource streamSource 51 = new StreamSource(new File(XML_DIR + "invalid.xsl")); 52 TransformerFactory tFactory = TransformerFactory.newInstance(); 53 Transformer transformer = tFactory.newTransformer(streamSource); 54 transformer.transform( 55 new StreamSource(new File(XML_DIR + "cities.xml")), 56 new SAXResult()); 57 fail("TransformerException is not thrown as expected"); 58 } catch (TransformerException e) { 59 assertNotNull(e.getCause()); 60 assertNotNull(e.getException()); 61 assertNull(e.getLocationAsString()); 62 assertEquals(e.getMessageAndLocation(),e.getMessage()); 63 } 64 } 65 66 67 /** 68 * Spec says, "if the throwable was created with 69 * TransformerException(Throwable), initCause should throw 70 * IllegalStateException 71 */ 72 @Test(expectedExceptions = IllegalStateException.class) 73 public void tfexception06() { 74 TransformerException te = new TransformerException(new Throwable()); 75 te.initCause(null); 76 } 77 78 /** 79 * Spec says, "if the throwable was created with TransformerException(String, 80 * Throwable), initCause should throw IllegalStateException 81 */ 82 @Test(expectedExceptions = IllegalStateException.class) | 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package javax.xml.transform.ptests; 24 25 import java.io.File; 26 import java.io.FilePermission; 27 import javax.xml.transform.Transformer; 28 import javax.xml.transform.TransformerException; 29 import javax.xml.transform.TransformerFactory; 30 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 31 import javax.xml.transform.sax.SAXResult; 32 import javax.xml.transform.stream.StreamSource; 33 import jaxp.library.JAXPBaseTest; 34 import static org.testng.Assert.assertEquals; 35 import static org.testng.Assert.assertNotNull; 36 import static org.testng.Assert.assertNull; 37 import static org.testng.Assert.fail; 38 import org.testng.annotations.Test; 39 40 /** 41 * Basic test for TransformerException specification. 42 */ 43 public class TransformerExcpTest extends JAXPBaseTest { 44 /** 45 * Transform an unformatted style-sheet file. TransformerException is thrown. 46 */ 47 @Test 48 public void tfexception() { 49 try { 50 setPermissions(new FilePermission(XML_DIR + "-", "read")); 51 // invalid.xsl has well-formedness error. Therefore transform throws 52 // TransformerException 53 StreamSource streamSource 54 = new StreamSource(new File(XML_DIR + "invalid.xsl")); 55 TransformerFactory tFactory = TransformerFactory.newInstance(); 56 Transformer transformer = tFactory.newTransformer(streamSource); 57 transformer.transform( 58 new StreamSource(new File(XML_DIR + "cities.xml")), 59 new SAXResult()); 60 fail("TransformerException is not thrown as expected"); 61 } catch (TransformerException e) { 62 assertNotNull(e.getCause()); 63 assertNotNull(e.getException()); 64 assertNull(e.getLocationAsString()); 65 assertEquals(e.getMessageAndLocation(),e.getMessage()); 66 } finally { 67 setPermissions(); 68 } 69 } 70 71 72 /** 73 * Spec says, "if the throwable was created with 74 * TransformerException(Throwable), initCause should throw 75 * IllegalStateException 76 */ 77 @Test(expectedExceptions = IllegalStateException.class) 78 public void tfexception06() { 79 TransformerException te = new TransformerException(new Throwable()); 80 te.initCause(null); 81 } 82 83 /** 84 * Spec says, "if the throwable was created with TransformerException(String, 85 * Throwable), initCause should throw IllegalStateException 86 */ 87 @Test(expectedExceptions = IllegalStateException.class) |