jdk/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java
author malenkov
Thu, 10 Nov 2011 17:27:40 +0400
changeset 11086 09b1d6383d0b
parent 5506 202f599c92aa
child 13602 68fbb8be55ab
permissions -rw-r--r--
7064279: Introspector.getBeanInfo() should release some resources in timely manner Reviewed-by: art, alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     1
/**
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3239
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     4
 *
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     8
 *
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    13
 * accompanied this code).
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    14
 *
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3239
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3239
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3239
diff changeset
    21
 * questions.
3239
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    22
 */
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    23
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    24
/*
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    25
 * @test
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    26
 * @bug 6380849
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    27
 * @summary Tests PropertyEditor finder
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    28
 * @author Sergey Malenkov
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    29
 */
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    30
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    31
import editors.SecondBeanEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    32
import editors.ThirdBeanEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    33
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    34
import java.awt.Color;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    35
import java.awt.Font;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    36
import java.beans.PropertyEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    37
import java.beans.PropertyEditorManager;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    38
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    39
import sun.beans.editors.BooleanEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    40
import sun.beans.editors.ByteEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    41
import sun.beans.editors.ColorEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    42
import sun.beans.editors.DoubleEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    43
import sun.beans.editors.EnumEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    44
import sun.beans.editors.FloatEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    45
import sun.beans.editors.FontEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    46
import sun.beans.editors.IntegerEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    47
import sun.beans.editors.LongEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    48
import sun.beans.editors.ShortEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    49
import sun.beans.editors.StringEditor;
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    50
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    51
public class TestPropertyEditor implements Runnable {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    52
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    53
    private enum Enumeration {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    54
        FIRST, SECOND, THIRD
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    55
    }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    56
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    57
    private static final String[] SEARCH_PATH = { "editors" }; // NON-NLS: package name
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    58
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    59
    public static void main(String[] args) throws InterruptedException {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    60
        TestPropertyEditor test = new TestPropertyEditor();
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    61
        test.run();
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    62
        // the following tests fails on previous build
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    63
        ThreadGroup group = new ThreadGroup("$$$"); // NON-NLS: unique thread name
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    64
        Thread thread = new Thread(group, test);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    65
        thread.start();
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    66
        thread.join();
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    67
    }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    68
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    69
    private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    70
        PropertyEditor actual = PropertyEditorManager.findEditor(type);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    71
        if ((actual == null) && (expected != null)) {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    72
            throw new Error("expected editor is not found");
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    73
        }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    74
        if ((actual != null) && !actual.getClass().equals(expected)) {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    75
            throw new Error("found unexpected editor");
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    76
        }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    77
    }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    78
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    79
    public void run() {
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    80
        PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    81
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    82
        test(FirstBean.class, FirstBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    83
        test(SecondBean.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    84
        test(ThirdBean.class, ThirdBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    85
        // test editors for default primitive types
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    86
        test(Byte.TYPE, ByteEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    87
        test(Short.TYPE, ShortEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    88
        test(Integer.TYPE, IntegerEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    89
        test(Long.TYPE, LongEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    90
        test(Boolean.TYPE, BooleanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    91
        test(Float.TYPE, FloatEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    92
        test(Double.TYPE, DoubleEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    93
        // test editors for default object types
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    94
        test(Byte.class, ByteEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    95
        test(Short.class, ShortEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    96
        test(Integer.class, IntegerEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    97
        test(Long.class, LongEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    98
        test(Boolean.class, BooleanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
    99
        test(Float.class, FloatEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   100
        test(Double.class, DoubleEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   101
        test(String.class, StringEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   102
        test(Color.class, ColorEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   103
        test(Font.class, FontEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   104
        test(Enumeration.class, EnumEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   105
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   106
        PropertyEditorManager.registerEditor(ThirdBean.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   107
        PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   108
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   109
        test(FirstBean.class, FirstBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   110
        test(SecondBean.class, SecondBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   111
        test(ThirdBean.class, ThirdBeanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   112
        // test editors for default primitive types
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   113
        test(Byte.TYPE, ByteEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   114
        test(Short.TYPE, ShortEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   115
        test(Integer.TYPE, IntegerEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   116
        test(Long.TYPE, LongEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   117
        test(Boolean.TYPE, BooleanEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   118
        test(Float.TYPE, FloatEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   119
        test(Double.TYPE, DoubleEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   120
        // test editors for default object types
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   121
        test(Byte.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   122
        test(Short.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   123
        test(Integer.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   124
        test(Long.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   125
        test(Boolean.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   126
        test(Float.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   127
        test(Double.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   128
        test(String.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   129
        test(Color.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   130
        test(Font.class, null);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   131
        test(Enumeration.class, EnumEditor.class);
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   132
    }
f675984c2349 6380849: RFE: Automatic discovery of PersistanceDelegates
malenkov
parents:
diff changeset
   133
}