1 /* 2 * Copyright (c) 2010, 2012, 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 /* 25 * @test 26 * @bug 6380849 27 * @summary Tests BeanInfo finder 28 * @modules java.desktop/java.beans:open 29 * @author Sergey Malenkov 30 */ 31 32 import beans.FirstBean; 33 import beans.FirstBeanBeanInfo; 34 import beans.SecondBean; 35 import beans.ThirdBean; 36 37 import infos.SecondBeanBeanInfo; 38 import infos.ThirdBeanBeanInfo; 39 40 import java.beans.BeanInfo; 41 import java.beans.Introspector; 42 import java.lang.reflect.Method; 43 44 public class TestBeanInfo implements Runnable { 45 46 private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name 47 main(String[] args)48 public static void main(String[] args) throws InterruptedException { 49 TestBeanInfo test = new TestBeanInfo(); 50 test.run(); 51 // the following tests fails on previous build 52 ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name 53 Thread thread = new Thread(group, test); 54 thread.start(); 55 thread.join(); 56 } 57 test(Class<?> type, Class<? extends BeanInfo> expected)58 private static void test(Class<?> type, Class<? extends BeanInfo> expected) { 59 BeanInfo actual; 60 try { 61 actual = Introspector.getBeanInfo(type); 62 type = actual.getClass(); 63 Method method = type.getDeclaredMethod("getTargetBeanInfo"); // NON-NLS: method name 64 method.setAccessible(true); 65 actual = (BeanInfo) method.invoke(actual); 66 } 67 catch (Exception exception) { 68 throw new Error("unexpected error", exception); 69 } 70 if ((actual == null) && (expected != null)) { 71 throw new Error("expected info is not found"); 72 } 73 if ((actual != null) && !actual.getClass().equals(expected)) { 74 throw new Error("found unexpected info"); 75 } 76 } 77 78 private boolean passed; 79 run()80 public void run() { 81 Introspector.flushCaches(); 82 83 test(FirstBean.class, FirstBeanBeanInfo.class); 84 test(SecondBean.class, null); 85 test(ThirdBean.class, null); 86 test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class); 87 88 Introspector.setBeanInfoSearchPath(SEARCH_PATH); 89 Introspector.flushCaches(); 90 91 test(FirstBean.class, FirstBeanBeanInfo.class); 92 test(SecondBean.class, SecondBeanBeanInfo.class); 93 test(ThirdBean.class, null); 94 test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class); 95 } 96 } 97