< prev index next >

test/java/beans/Introspector/BeanPropertyTest.java

Print this page




  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 import java.beans.BeanInfo;
  25 import java.beans.BeanProperty;
  26 import java.beans.IntrospectionException;
  27 import java.beans.Introspector;
  28 import java.beans.PropertyChangeListener;
  29 import java.beans.PropertyDescriptor;
  30 
  31 import java.util.Arrays;
  32 
  33 
  34 /**
  35  * @test
  36  * @bug 8132703 8132163 8132732 8132973 8154756 8132888
  37  * @summary Some check for BeanProperty annotation
  38  * @author a.stepanov
  39  * @run main BeanPropertyTest
  40  */
  41 
  42 
  43 public class BeanPropertyTest {
  44 
  45     private final static String  DESCRIPTION = "TEST";
  46     private final static boolean BOUND       = true;
  47     private final static boolean EXPERT      = false;
  48     private final static boolean HIDDEN      = true;
  49     private final static boolean PREFERRED   = false;
  50     private final static boolean REQUIRED    = true;
  51     private final static boolean UPDATE      = false;
  52     private final static String
  53         V_NAME  = "javax.swing.SwingConstants.TOP",
  54         V_SHORT = "TOP",
  55         V = Integer.toString(javax.swing.SwingConstants.TOP);
  56     private final static int X = javax.swing.SwingConstants.TOP;


 836         private static SelfArr arr[] = null;
 837         private SelfArr() {}
 838 
 839         @BeanProperty(
 840             description  = DESCRIPTION,
 841             bound        = BOUND,
 842             expert       = EXPERT,
 843             hidden       = HIDDEN,
 844             preferred    = PREFERRED,
 845             required     = REQUIRED,
 846             visualUpdate = UPDATE)
 847         public SelfArr[] getSelfArr() {
 848             if (arr == null) { arr = new SelfArr[]{new SelfArr(), new SelfArr()}; }
 849             return arr;
 850         }
 851 
 852         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 853         public void removePropertyChangeListener(PropertyChangeListener l) {}
 854     }
 855 


























































 856 
 857     // ---------- checks ----------
 858 
 859     private static boolean check(String what, boolean v, boolean ref) {
 860 
 861         boolean ok = (v == ref);
 862         if (!ok) { System.out.println(
 863             "invalid " + what + ": " + v + ", expected: " + ref); }
 864         return ok;
 865     }
 866 
 867     private static boolean checkInfo(BeanInfo i, boolean checkVals) {
 868 
 869         System.out.println("checking info...");
 870 
 871         PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
 872         int nd = descriptors.length;
 873         if (nd != 1) {
 874             System.out.println("invalid number of descriptors: " + nd);
 875             return false;


 936             (boolean) d.getValue("visualUpdate"), !UPDATE);
 937 
 938         Object vals[] = (Object[]) d.getValue("enumerationValues");
 939         if (vals != null || vals.length > 0) {
 940             System.out.println("non-null enumerationValues");
 941             return false;
 942         }
 943 
 944         return ok;
 945     }
 946 
 947 
 948     private static boolean checkAlternative(Class<?> c) {
 949         return (
 950             c.equals(G09.class) ||
 951             c.equals(S09.class) ||
 952             c.equals(GS.class));
 953     }
 954 
 955     private static boolean ignoreVals(Class<?> c) {
 956         return (c.equals(Self.class) || c.equals(SelfArr.class));
 957     }
 958 
 959 
 960     // ---------- run test ----------
 961 
 962     public static void main(String[] args) throws Exception {
 963 
 964         Class<?> cases[] = {
 965 
 966             G01.class, S01.class,
 967             // G02.class, S02.class, // TODO: please update after 8132703 fix
 968             // G03.class, S03.class, // TODO: please update after 8132703 fix
 969             // G04.class, S04.class, // TODO: please update after 8132163 fix
 970             G05.class, // S05.class, // TODO: please update after 8132163 fix
 971             G06.class, S06.class,
 972             G07.class, S07.class,
 973             // G08.class, S08.class, // TODO: please update after 8132732 fix
 974             // G09.class, S09.class, // TODO: please update after 8132732 fix
 975             G10.class, S10.class,
 976             G11.class, S11.class,


 985 
 986         boolean passed = true;
 987 
 988         for (Class<?> c: cases) {
 989 
 990             java.lang.reflect.Field f = c.getDeclaredField("TESTCASE");
 991             f.setAccessible(true);
 992             String descr = f.get(c).toString();
 993 
 994             System.out.println("\n" + c.getSimpleName() + " (" + descr + "):");
 995             BeanInfo i;
 996             try { i = Introspector.getBeanInfo(c, Object.class); }
 997             catch (IntrospectionException e) { throw new RuntimeException(e); }
 998             boolean ok = checkInfo(i, !ignoreVals(c));
 999             if (checkAlternative(c)) {
1000                 ok |= checkAlternativeInfo(i);
1001             }
1002             System.out.println(ok ? "OK" : "NOK");
1003             passed = passed && ok;
1004         }























1005 
1006         if (!passed) { throw new RuntimeException("test failed"); }
1007         System.out.println("\ntest passed");
1008     }
1009 }


  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 import java.beans.BeanInfo;
  25 import java.beans.BeanProperty;
  26 import java.beans.IntrospectionException;
  27 import java.beans.Introspector;
  28 import java.beans.PropertyChangeListener;
  29 import java.beans.PropertyDescriptor;
  30 
  31 import java.util.Arrays;
  32 
  33 
  34 /**
  35  * @test
  36  * @bug 8132703 8132163 8132732 8132973 8154756 8132888 8155103
  37  * @summary Some check for BeanProperty annotation
  38  * @author a.stepanov
  39  * @run main BeanPropertyTest
  40  */
  41 
  42 
  43 public class BeanPropertyTest {
  44 
  45     private final static String  DESCRIPTION = "TEST";
  46     private final static boolean BOUND       = true;
  47     private final static boolean EXPERT      = false;
  48     private final static boolean HIDDEN      = true;
  49     private final static boolean PREFERRED   = false;
  50     private final static boolean REQUIRED    = true;
  51     private final static boolean UPDATE      = false;
  52     private final static String
  53         V_NAME  = "javax.swing.SwingConstants.TOP",
  54         V_SHORT = "TOP",
  55         V = Integer.toString(javax.swing.SwingConstants.TOP);
  56     private final static int X = javax.swing.SwingConstants.TOP;


 836         private static SelfArr arr[] = null;
 837         private SelfArr() {}
 838 
 839         @BeanProperty(
 840             description  = DESCRIPTION,
 841             bound        = BOUND,
 842             expert       = EXPERT,
 843             hidden       = HIDDEN,
 844             preferred    = PREFERRED,
 845             required     = REQUIRED,
 846             visualUpdate = UPDATE)
 847         public SelfArr[] getSelfArr() {
 848             if (arr == null) { arr = new SelfArr[]{new SelfArr(), new SelfArr()}; }
 849             return arr;
 850         }
 851 
 852         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 853         public void removePropertyChangeListener(PropertyChangeListener l) {}
 854     }
 855 
 856     // JDK-8155103
 857     public static enum E {
 858 
 859         ONE,
 860         TWO {
 861             @BeanProperty(
 862             description  = DESCRIPTION,
 863             bound        = BOUND,
 864             expert       = EXPERT,
 865             hidden       = HIDDEN,
 866             preferred    = PREFERRED,
 867             required     = REQUIRED,
 868             visualUpdate = UPDATE,
 869             enumerationValues = {V_NAME})
 870             public void setX(int v) {}
 871 
 872             public void addPropertyChangeListener(PropertyChangeListener l)    {}
 873             public void removePropertyChangeListener(PropertyChangeListener l) {}
 874         };
 875 
 876         @BeanProperty(
 877             description  = DESCRIPTION,
 878             bound        = BOUND,
 879             expert       = EXPERT,
 880             hidden       = HIDDEN,
 881             preferred    = PREFERRED,
 882             required     = REQUIRED,
 883             visualUpdate = UPDATE,
 884             enumerationValues = {V_NAME})
 885         public void setX(int v) {}
 886 
 887         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 888         public void removePropertyChangeListener(PropertyChangeListener l) {}
 889 
 890     }
 891 
 892     private static enum EB {
 893 
 894         TRUE(true), FALSE(false);
 895 
 896         private boolean b;
 897         private EB(boolean v) { b = v; }
 898 
 899         @BeanProperty(
 900             description  = DESCRIPTION,
 901             bound        = BOUND,
 902             expert       = EXPERT,
 903             hidden       = HIDDEN,
 904             preferred    = PREFERRED,
 905             required     = REQUIRED,
 906             visualUpdate = UPDATE)
 907         public boolean isTrue() { return true; }
 908 
 909         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 910         public void removePropertyChangeListener(PropertyChangeListener l) {}
 911 
 912     }
 913 
 914 
 915     // ---------- checks ----------
 916 
 917     private static boolean check(String what, boolean v, boolean ref) {
 918 
 919         boolean ok = (v == ref);
 920         if (!ok) { System.out.println(
 921             "invalid " + what + ": " + v + ", expected: " + ref); }
 922         return ok;
 923     }
 924 
 925     private static boolean checkInfo(BeanInfo i, boolean checkVals) {
 926 
 927         System.out.println("checking info...");
 928 
 929         PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
 930         int nd = descriptors.length;
 931         if (nd != 1) {
 932             System.out.println("invalid number of descriptors: " + nd);
 933             return false;


 994             (boolean) d.getValue("visualUpdate"), !UPDATE);
 995 
 996         Object vals[] = (Object[]) d.getValue("enumerationValues");
 997         if (vals != null || vals.length > 0) {
 998             System.out.println("non-null enumerationValues");
 999             return false;
1000         }
1001 
1002         return ok;
1003     }
1004 
1005 
1006     private static boolean checkAlternative(Class<?> c) {
1007         return (
1008             c.equals(G09.class) ||
1009             c.equals(S09.class) ||
1010             c.equals(GS.class));
1011     }
1012 
1013     private static boolean ignoreVals(Class<?> c) {
1014         return (c.equals(Self.class) || c.equals(SelfArr.class)) || c.equals(EB.class);
1015     }
1016 
1017 
1018     // ---------- run test ----------
1019 
1020     public static void main(String[] args) throws Exception {
1021 
1022         Class<?> cases[] = {
1023 
1024             G01.class, S01.class,
1025             // G02.class, S02.class, // TODO: please update after 8132703 fix
1026             // G03.class, S03.class, // TODO: please update after 8132703 fix
1027             // G04.class, S04.class, // TODO: please update after 8132163 fix
1028             G05.class, // S05.class, // TODO: please update after 8132163 fix
1029             G06.class, S06.class,
1030             G07.class, S07.class,
1031             // G08.class, S08.class, // TODO: please update after 8132732 fix
1032             // G09.class, S09.class, // TODO: please update after 8132732 fix
1033             G10.class, S10.class,
1034             G11.class, S11.class,


1043 
1044         boolean passed = true;
1045 
1046         for (Class<?> c: cases) {
1047 
1048             java.lang.reflect.Field f = c.getDeclaredField("TESTCASE");
1049             f.setAccessible(true);
1050             String descr = f.get(c).toString();
1051 
1052             System.out.println("\n" + c.getSimpleName() + " (" + descr + "):");
1053             BeanInfo i;
1054             try { i = Introspector.getBeanInfo(c, Object.class); }
1055             catch (IntrospectionException e) { throw new RuntimeException(e); }
1056             boolean ok = checkInfo(i, !ignoreVals(c));
1057             if (checkAlternative(c)) {
1058                 ok |= checkAlternativeInfo(i);
1059             }
1060             System.out.println(ok ? "OK" : "NOK");
1061             passed = passed && ok;
1062         }
1063 
1064         // enums
1065 
1066         Class<?> enumCases[] = {
1067 
1068             // TODO: uncomment/update after 8155103 fix
1069             //E.class, E.TWO.getClass(), EB.class
1070         };
1071 
1072         int ne = 1;
1073         for (Class<?> c: enumCases) {
1074 
1075             System.out.println("\nEnum-" + ne + ":");
1076             ne++;
1077 
1078             BeanInfo i;
1079             try { i = Introspector.getBeanInfo(c, Object.class); }
1080             catch (IntrospectionException e) { throw new RuntimeException(e); }
1081             boolean ok = checkInfo(i, !ignoreVals(c));
1082             System.out.println(ok ? "OK" : "NOK");
1083             passed = passed && ok;
1084         }
1085 
1086 
1087         if (!passed) { throw new RuntimeException("test failed"); }
1088         System.out.println("\ntest passed");
1089     }
1090 }
< prev index next >