/* * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */ /* * 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.apache.qetest.trax; import com.sun.org.apache.xml.internal.utils.DefaultErrorHandler; import javax.xml.transform.TransformerException; import jaxp.library.JAXPBaseTest; import static org.testng.Assert.assertNotNull; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; /** * API Coverage test for ErrorListener. */ public class ErrorListenerAPITest extends JAXPBaseTest { /** * All test method need access internal package * com.sun.org.apache.xml.internal.utils and * com.sun.org.apache.xpath.internal.objects. */ @BeforeMethod public void inititalize() { setPermissions(new RuntimePermission("accessClassInPackage.com.sun.org.apache.xml.internal.utils"), new RuntimePermission("accessClassInPackage.com.sun.org.apache.xpath.internal.objects")); } /** * Root exception wrap message. */ private final String EXP_MSG = "Exception-message-here"; /** * Transformer exception wrap message. */ private final String TRANSFORMER_EXP_MSG = "TransformerException-message-here"; /** * Default behavior of DefaultErrorHandler.warning is doing nothing. * * @throws TransformerException Any SAX exception, possibly wrapping another * exception. */ @Test public void testWarning() throws TransformerException { DefaultErrorHandler deh = new DefaultErrorHandler(); assertNotNull(deh); Exception ex = new Exception(EXP_MSG); TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); deh.warning(tex); } /** * Default behavior of DefaultErrorHandler.error is throwing out the * TransformerException. * * @throws TransformerException Any SAX exception, possibly wrapping another * exception. */ @Test(expectedExceptions = TransformerException.class) public void testError() throws TransformerException { DefaultErrorHandler deh = new DefaultErrorHandler(); assertNotNull(deh); Exception ex = new Exception(EXP_MSG); TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); deh.error(tex); } /** * Default behavior of DefaultErrorHandler.fatalError is throwing out the * TransformerException. * * @throws TransformerException Any SAX exception, possibly wrapping another * exception. */ @Test(expectedExceptions = TransformerException.class) public void testFatalError() throws TransformerException { DefaultErrorHandler deh = new DefaultErrorHandler(); assertNotNull(deh); Exception ex = new Exception(EXP_MSG); TransformerException tex = new TransformerException(TRANSFORMER_EXP_MSG, ex); deh.fatalError(tex); } }