1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 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 24 package stream.XMLInputFactoryTest; 25 26 import javax.xml.stream.XMLInputFactory; 27 28 import org.testng.Assert; 29 import org.testng.annotations.Test; 30 31 /* 32 * @bug 6756677 33 * @summary Test XMLInputFactory.newFactory(String factoryId, ClassLoader classLoader). 34 */ 35 public class Bug6756677Test { 36 37 @Test 38 public void testNewInstance() { 39 String myFactory = "stream.XMLInputFactoryTest.MyInputFactory"; 40 try { 41 System.setProperty("MyInputFactory", myFactory); 42 XMLInputFactory xif = XMLInputFactory.newInstance("MyInputFactory", null); 43 System.out.println(xif.getClass().getName()); 44 Assert.assertTrue(xif.getClass().getName().equals(myFactory)); 45 46 } catch (UnsupportedOperationException oe) { 47 Assert.fail(oe.getMessage()); 48 } 49 50 } 51 52 // newFactory was added in StAX 1.2 53 @Test 54 public void testNewFactory() { 55 String myFactory = "stream.XMLInputFactoryTest.MyInputFactory"; 56 ClassLoader cl = null; 57 try { 58 System.setProperty("MyInputFactory", myFactory); 59 XMLInputFactory xif = XMLInputFactory.newFactory("MyInputFactory", cl); 60 System.out.println(xif.getClass().getName()); 61 Assert.assertTrue(xif.getClass().getName().equals(myFactory)); 62 63 } catch (UnsupportedOperationException oe) { 64 Assert.fail(oe.getMessage()); 65 } 66 67 } 68 69 String Temp_Result = ""; 70 boolean PASSED = true; 71 boolean FAILED = false; 72 73 String XMLInputFactoryClassName = "com.sun.xml.internal.stream.XMLInputFactoryImpl"; 74 String XMLInputFactoryID = "javax.xml.stream.XMLInputFactory"; 75 ClassLoader CL = null; 76 77 // jaxp-test jaxp-product-tests javax.xml.jaxp14.ptests.FactoryTest 78 @Test 79 public void test() { 80 if (!test29()) { 81 Assert.fail(Temp_Result); 82 } 83 if (!test31()) { 84 Assert.fail(Temp_Result); 85 } 86 } 87 88 /* 89 * test for XMLInputFactory.newInstance(java.lang.String factoryClassName, 90 * java.lang.ClassLoader classLoader) classloader is null and 91 * factoryClassName points to correct implementation of 92 * javax.xml.stream.XMLInputFactory , should return newInstance of 93 * XMLInputFactory 94 */ 95 @Test 96 public boolean test29() { 97 try { 98 System.setProperty(XMLInputFactoryID, XMLInputFactoryClassName); 99 XMLInputFactory xif = XMLInputFactory.newInstance(XMLInputFactoryID, CL); 100 if (xif instanceof XMLInputFactory) { 101 System.out.println(" test29() passed"); 102 return PASSED; 103 } else { 104 System.out.println(" test29() failed"); 105 Temp_Result = "test29() failed: xif not an instance of XMLInputFactory "; 106 return FAILED; 107 } 108 } catch (javax.xml.stream.FactoryConfigurationError fce) { 109 System.out.println("Failed : FactoryConfigurationError in test29 " + fce); 110 Temp_Result = "test29() failed "; 111 return FAILED; 112 } catch (Exception e) { 113 System.out.println("Failed : Exception in test29 " + e); 114 Temp_Result = "test29() failed "; 115 return FAILED; 116 } 117 } 118 119 /* 120 * test for XMLInputFactory.newInstance(java.lang.String factoryClassName, 121 * java.lang.ClassLoader classLoader) classloader is 122 * default(Class.getClassLoader()) and factoryClassName points to correct 123 * implementation of javax.xml.stream.XMLInputFactory , should return 124 * newInstance of XMLInputFactory 125 */ 126 @Test 127 public boolean test31() { 128 try { 129 Bug6756677Test test3 = new Bug6756677Test(); 130 ClassLoader cl = (test3.getClass()).getClassLoader(); 131 System.setProperty(XMLInputFactoryID, XMLInputFactoryClassName); 132 XMLInputFactory xif = XMLInputFactory.newInstance(XMLInputFactoryID, cl); 133 if (xif instanceof XMLInputFactory) { 134 System.out.println(" test31() passed"); 135 return PASSED; 136 } else { 137 System.out.println(" test31() failed"); 138 Temp_Result = "test31() failed: xif not an instance of XMLInputFactory "; 139 return FAILED; 140 } 141 } catch (javax.xml.stream.FactoryConfigurationError fce) { 142 System.out.println("Failed : FactoryConfigurationError in test31 " + fce); 143 Temp_Result = "test31() failed "; 144 return FAILED; 145 } catch (Exception e) { 146 System.out.println("Failed : Exception in test31 " + e); 147 Temp_Result = "test31() failed "; 148 return FAILED; 149 } 150 } 151 }