1405N/A/**
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
1405N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1405N/A *
1405N/A * This code is free software; you can redistribute it and/or modify it
1405N/A * under the terms of the GNU General Public License version 2 only, as
1405N/A * published by the Free Software Foundation.
1405N/A *
1405N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1405N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1405N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1405N/A * version 2 for more details (a copy is included in the LICENSE file that
1405N/A * accompanied this code).
1405N/A *
1405N/A * You should have received a copy of the GNU General Public License version
1405N/A * 2 along with this work; if not, write to the Free Software Foundation,
1405N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1405N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1405N/A */
1405N/A
1405N/A/*
1405N/A * @test
1405N/A * @bug 6380849
1405N/A * @summary Tests BeanInfo finder
1405N/A * @author Sergey Malenkov
1405N/A */
1405N/A
1405N/Aimport beans.FirstBean;
1405N/Aimport beans.FirstBeanBeanInfo;
1405N/Aimport beans.SecondBean;
1405N/Aimport beans.ThirdBean;
1405N/A
1405N/Aimport infos.SecondBeanBeanInfo;
1405N/Aimport infos.ThirdBeanBeanInfo;
1405N/A
1405N/Aimport java.beans.BeanInfo;
1405N/Aimport java.beans.Introspector;
5313N/Aimport java.lang.reflect.Method;
1405N/A
1405N/Apublic class TestBeanInfo implements Runnable {
1405N/A
1405N/A private static final String[] SEARCH_PATH = { "infos" }; // NON-NLS: package name
1405N/A
1405N/A public static void main(String[] args) throws InterruptedException {
1405N/A TestBeanInfo test = new TestBeanInfo();
1405N/A test.run();
1405N/A // the following tests fails on previous build
1405N/A ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name
1405N/A Thread thread = new Thread(group, test);
1405N/A thread.start();
1405N/A thread.join();
1405N/A }
1405N/A
1405N/A private static void test(Class<?> type, Class<? extends BeanInfo> expected) {
1405N/A BeanInfo actual;
1405N/A try {
1405N/A actual = Introspector.getBeanInfo(type);
1405N/A type = actual.getClass();
5313N/A Method method = type.getDeclaredMethod("getTargetBeanInfo"); // NON-NLS: method name
5313N/A method.setAccessible(true);
5313N/A actual = (BeanInfo) method.invoke(actual);
1405N/A }
1405N/A catch (Exception exception) {
1405N/A throw new Error("unexpected error", exception);
1405N/A }
1405N/A if ((actual == null) && (expected != null)) {
1405N/A throw new Error("expected info is not found");
1405N/A }
1405N/A if ((actual != null) && !actual.getClass().equals(expected)) {
1405N/A throw new Error("found unexpected info");
1405N/A }
1405N/A }
1405N/A
1405N/A private boolean passed;
1405N/A
1405N/A public void run() {
1405N/A Introspector.flushCaches();
1405N/A
1405N/A test(FirstBean.class, FirstBeanBeanInfo.class);
1405N/A test(SecondBean.class, null);
1405N/A test(ThirdBean.class, null);
1405N/A test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
1405N/A
1405N/A Introspector.setBeanInfoSearchPath(SEARCH_PATH);
1405N/A Introspector.flushCaches();
1405N/A
1405N/A test(FirstBean.class, FirstBeanBeanInfo.class);
1405N/A test(SecondBean.class, SecondBeanBeanInfo.class);
1405N/A test(ThirdBean.class, null);
1405N/A test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
1405N/A }
1405N/A}