1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.qetest.trax; 21 22 import com.sun.org.apache.xml.internal.utils.DefaultErrorHandler; 23 import javax.xml.transform.TransformerException; 24 import jaxp.library.JAXPBaseTest; 25 import static org.testng.Assert.assertNotNull; 26 import org.testng.annotations.BeforeMethod; 27 import org.testng.annotations.Test; 28 29 /** 30 * API Coverage test for ErrorListener. 31 */ 32 public class ErrorListenerAPITest extends JAXPBaseTest { 33 /** 34 * All test method need access internal package 35 * com.sun.org.apache.xml.internal.utils and 36 * com.sun.org.apache.xpath.internal.objects. 37 */ 38 @BeforeMethod 39 public void inititalize() { 40 setPermissions(new RuntimePermission("accessClassInPackage.com.sun.org.apache.xml.internal.utils"), 41 new RuntimePermission("accessClassInPackage.com.sun.org.apache.xpath.internal.objects")); 42 } 43 /** 44 * Root exception wrap message. 45 */ 46 private final String EXP_MSG = "Exception-message-here"; 47 48 /** 49 * Transformer exception wrap message. 50 */ 51 private final String TRANSFORMER_EXP_MSG = "TransformerException-message-here"; 52 53 /** 54 * Default behavior of DefaultErrorHandler.warning is doing nothing. 55 * 56 * @throws TransformerException Any SAX exception, possibly wrapping another 57 * exception. 58 */ 59 @Test 60 public void testWarning() throws TransformerException { 61 DefaultErrorHandler deh = new DefaultErrorHandler(); 62 assertNotNull(deh); 63 64 Exception ex = new Exception(EXP_MSG); 65 TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); 66 deh.warning(tex); 67 } 68 69 /** 70 * Default behavior of DefaultErrorHandler.error is throwing out the 71 * TransformerException. 72 * 73 * @throws TransformerException Any SAX exception, possibly wrapping another 74 * exception. 75 */ 76 @Test(expectedExceptions = TransformerException.class) 77 public void testError() throws TransformerException { 78 DefaultErrorHandler deh = new DefaultErrorHandler(); 79 assertNotNull(deh); 80 81 Exception ex = new Exception(EXP_MSG); 82 TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); 83 deh.error(tex); 84 } 85 86 /** 87 * Default behavior of DefaultErrorHandler.fatalError is throwing out the 88 * TransformerException. 89 * 90 * @throws TransformerException Any SAX exception, possibly wrapping another 91 * exception. 92 */ 93 @Test(expectedExceptions = TransformerException.class) 94 public void testFatalError() throws TransformerException { 95 DefaultErrorHandler deh = new DefaultErrorHandler(); 96 assertNotNull(deh); 97 98 Exception ex = new Exception(EXP_MSG); 99 TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); 100 deh.fatalError(tex); 101 } 102 }