Path: blob/master/test/jaxp/javax/xml/jaxp/unittest/sax/Attributes2ImplTest.java
42232 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package sax;2425import org.testng.Assert;26import org.testng.annotations.Listeners;27import org.testng.annotations.Test;28import org.xml.sax.ext.Attributes2Impl;2930/*31* @test32* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest33* @run testng/othervm -DrunSecMngr=true -Djava.security.manager=allow sax.Attributes2ImplTest34* @run testng/othervm sax.Attributes2ImplTest35* @summary Test Attributes2Impl.36*/37@Listeners({jaxp.library.BasePolicy.class})38public class Attributes2ImplTest {3940@Test41public void test01() {42System.out.println("===in test01()===");43Attributes2Impl impl = new Attributes2Impl();44impl.addAttribute("http://www.cars.com/xml", "attr1", "Qname1", "type", "value");45impl.addAttribute("http://www.cars.com/xml", "attr2", "Qname2", "type", "value");46impl.addAttribute("http://www.cars.com/xml", "attr3", "Qname3", "type", "value");4748Assert.assertTrue(impl.isDeclared(0));49impl.setDeclared(0, false);50Assert.assertFalse(impl.isDeclared(0));5152Assert.assertTrue(impl.isDeclared("Qname2"));53impl.setDeclared(1, false);54Assert.assertFalse(impl.isDeclared("Qname2"));5556Assert.assertTrue(impl.isDeclared("http://www.cars.com/xml", "attr3"));57impl.setDeclared(2, false);58Assert.assertFalse(impl.isDeclared(2));5960try {61impl.isDeclared(3);62} catch (ArrayIndexOutOfBoundsException e) {63System.out.println("Expected ArrayIndexOutOfBoundsException");64}6566try {67impl.isDeclared("wrongQname");68} catch (IllegalArgumentException e) {69System.out.println("Expected IllegalArgumentException");70}7172try {73impl.isDeclared("http://www.cars.com/xml", "attr4");74} catch (IllegalArgumentException e) {75System.out.println("Expected IllegalArgumentException");76}7778impl.removeAttribute(2);79try {80impl.isDeclared(2);81} catch (ArrayIndexOutOfBoundsException e) {82System.out.println("Expected ArrayIndexOutOfBoundsException on index=2 after removing");83}84}8586@Test87public void test02() {88System.out.println("===in test02()===");89Attributes2Impl impl = new Attributes2Impl();90impl.addAttribute("http://www.cars.com/xml", "attr1", "Qname1", "type", "value");91impl.addAttribute("http://www.cars.com/xml", "attr2", "Qname2", "type", "value");92impl.addAttribute("http://www.cars.com/xml", "attr3", "Qname3", "type", "value");9394Assert.assertTrue(impl.isSpecified(0));95impl.setSpecified(0, false);96Assert.assertFalse(impl.isSpecified(0));9798Assert.assertTrue(impl.isSpecified("Qname2"));99impl.setSpecified(1, false);100Assert.assertFalse(impl.isSpecified("Qname2"));101102Assert.assertTrue(impl.isSpecified("http://www.cars.com/xml", "attr3"));103impl.setSpecified(2, false);104Assert.assertFalse(impl.isSpecified(2));105106try {107impl.isSpecified(3);108} catch (ArrayIndexOutOfBoundsException e) {109System.out.println("Expected ArrayIndexOutOfBoundsException");110}111112try {113impl.isSpecified("wrongQname");114} catch (IllegalArgumentException e) {115System.out.println("Expected IllegalArgumentException");116}117118try {119impl.isSpecified("http://www.cars.com/xml", "attr4");120} catch (IllegalArgumentException e) {121System.out.println("Expected IllegalArgumentException");122}123124impl.removeAttribute(2);125try {126impl.isSpecified(2);127} catch (ArrayIndexOutOfBoundsException e) {128System.out.println("Expected ArrayIndexOutOfBoundsException on index=2 after removing");129}130}131132@Test133public void test03() {134System.out.println("===in test03()===");135Attributes2Impl impl1 = new Attributes2Impl();136impl1.addAttribute("http://www.cars.com/xml", "attr1", "Qname1", "type", "value");137impl1.addAttribute("http://www.cars.com/xml", "attr2", "Qname2", "type", "value");138impl1.addAttribute("http://www.cars.com/xml", "attr3", "Qname3", "type", "value");139140Attributes2Impl impl2 = new Attributes2Impl(impl1);141142Attributes2Impl impl3 = new Attributes2Impl();143impl3.setAttributes(impl1);144145Assert.assertTrue(impl1.getQName(0).equals(impl2.getQName(0)));146Assert.assertTrue(impl1.getQName(0).equals(impl3.getQName(0)));147148Assert.assertTrue(impl1.getQName(1).equals(impl2.getQName(1)));149Assert.assertTrue(impl1.getQName(1).equals(impl3.getQName(1)));150151Assert.assertTrue(impl1.getQName(2).equals(impl2.getQName(2)));152Assert.assertTrue(impl1.getQName(2).equals(impl3.getQName(2)));153}154}155156157