< prev index next >

test/java/beans/Introspector/BeanPropertyTest.java

Print this page




 280 
 281         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 282         public void removePropertyChangeListener(PropertyChangeListener l) {}
 283     }
 284 
 285     public static class G06 {
 286 
 287         private final static String TESTCASE = "indexed getter";
 288 
 289         private final int x[] = {X, X, X};
 290 
 291         @BeanProperty(
 292             description  = DESCRIPTION,
 293             bound        = BOUND,
 294             expert       = EXPERT,
 295             hidden       = HIDDEN,
 296             preferred    = PREFERRED,
 297             required     = REQUIRED,
 298             visualUpdate = UPDATE,
 299             enumerationValues = {V_NAME})
 300         public int getX(int i) throws IndexOutOfBoundsException {
 301             if (i < 0 || i >= x.length) {
 302                 throw new IndexOutOfBoundsException(); }
 303             return x[i];
 304         }
 305 
 306         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 307         public void removePropertyChangeListener(PropertyChangeListener l) {}
 308     }
 309 
 310     public static class S06 {
 311 
 312         private final static String TESTCASE = "indexed setter";
 313 
 314         private final int x[] = {X, X, X};
 315 
 316         @BeanProperty(
 317             description  = DESCRIPTION,
 318             bound        = BOUND,
 319             expert       = EXPERT,
 320             hidden       = HIDDEN,
 321             preferred    = PREFERRED,
 322             required     = REQUIRED,
 323             visualUpdate = UPDATE,
 324             enumerationValues = {V_NAME})
 325         public void setX(int i, int v) throws IndexOutOfBoundsException {
 326             if (i < 0 || i >= x.length) {
 327                 throw new IndexOutOfBoundsException(); }
 328             x[i] = v;
 329         }
 330 
 331         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 332         public void removePropertyChangeListener(PropertyChangeListener l) {}
 333     }
 334 
 335     public static class G07 {
 336 
 337         private final static String TESTCASE =
 338             "indexed (annotated) + non-indexed getters";
 339 
 340         private final int x[] = {X, X, X};
 341 
 342         @BeanProperty(
 343             description  = DESCRIPTION,
 344             bound        = BOUND,
 345             expert       = EXPERT,
 346             hidden       = HIDDEN,
 347             preferred    = PREFERRED,
 348             required     = REQUIRED,
 349             visualUpdate = UPDATE,
 350             enumerationValues = {V_NAME})
 351         public int getX(int i) throws IndexOutOfBoundsException {
 352             if (i < 0 || i >= x.length) {
 353                 throw new IndexOutOfBoundsException(); }
 354             return x[i];
 355         }
 356 
 357         public int[] getX() { return x; }
 358 
 359         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 360         public void removePropertyChangeListener(PropertyChangeListener l) {}
 361     }
 362 
 363     public static class S07 {
 364 
 365         private final static String TESTCASE =
 366             "indexed (annotated) + non-indexed setters";
 367 
 368         private int x[] = new int[3];
 369 
 370         @BeanProperty(
 371             description  = DESCRIPTION,
 372             bound        = BOUND,
 373             expert       = EXPERT,
 374             hidden       = HIDDEN,
 375             preferred    = PREFERRED,
 376             required     = REQUIRED,
 377             visualUpdate = UPDATE,
 378             enumerationValues = {V_NAME})
 379         public void setX(int i, int v) throws IndexOutOfBoundsException {
 380             if (i < 0 || i >= x.length) {
 381                 throw new IndexOutOfBoundsException(); }
 382             x[i] = v;
 383         }
 384 
 385         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 386 
 387         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 388         public void removePropertyChangeListener(PropertyChangeListener l) {}
 389     }
 390 
 391     // JDK-8132732
 392     public static class G08 {
 393 
 394         private final static String TESTCASE =
 395             "non-indexed (annotated) + indexed getters";
 396 
 397         private final int x[] = {X, X, X};
 398 
 399         @BeanProperty(
 400             description  = DESCRIPTION,
 401             bound        = BOUND,
 402             expert       = EXPERT,
 403             hidden       = HIDDEN,
 404             preferred    = PREFERRED,
 405             required     = REQUIRED,
 406             visualUpdate = UPDATE,
 407             enumerationValues = {V_NAME})
 408         public int[] getX() { return x; }
 409 
 410         public int getX(int i) throws IndexOutOfBoundsException {
 411             if (i < 0 || i >= x.length) {
 412                 throw new IndexOutOfBoundsException(); }
 413             return x[i];
 414         }
 415 
 416         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 417         public void removePropertyChangeListener(PropertyChangeListener l) {}
 418     }
 419 
 420     // JDK-8132732
 421     public static class S08 {
 422 
 423         private final static String TESTCASE =
 424             "non-indexed (annotated) + indexed setters";
 425 
 426         private int x[] = new int[3];
 427 
 428         @BeanProperty(
 429             description  = DESCRIPTION,
 430             bound        = BOUND,
 431             expert       = EXPERT,
 432             hidden       = HIDDEN,
 433             preferred    = PREFERRED,
 434             required     = REQUIRED,
 435             visualUpdate = UPDATE,
 436             enumerationValues = {V_NAME})
 437         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 438 
 439         public void setX(int i, int v) throws IndexOutOfBoundsException {
 440             if (i < 0 || i >= x.length) {
 441                 throw new IndexOutOfBoundsException(); }
 442             x[i] = v;
 443         }
 444 
 445         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 446         public void removePropertyChangeListener(PropertyChangeListener l) {}
 447     }
 448 
 449     // JDK-8132732
 450     public static class G09 {
 451 
 452         private final static String TESTCASE = "two annotated getters";
 453 
 454         private final int x[] = {X, X, X};
 455 
 456         @BeanProperty(
 457             description  = DESCRIPTION,
 458             bound        = BOUND,
 459             expert       = EXPERT,
 460             hidden       = HIDDEN,
 461             preferred    = PREFERRED,
 462             required     = REQUIRED,
 463             visualUpdate = UPDATE,
 464             enumerationValues = {V_NAME})
 465         public int[] getX() { return x; }
 466 
 467         @BeanProperty(
 468             description  = DESCRIPTION_2,
 469             bound        = !BOUND,
 470             expert       = !EXPERT,
 471             hidden       = !HIDDEN,
 472             preferred    = !PREFERRED,
 473             required     = !REQUIRED,
 474             visualUpdate = !UPDATE)
 475         public int getX(int i) throws IndexOutOfBoundsException {
 476             if (i < 0 || i >= x.length) {
 477                 throw new IndexOutOfBoundsException(); }
 478             return x[i];
 479         }
 480 
 481         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 482         public void removePropertyChangeListener(PropertyChangeListener l) {}
 483     }
 484 
 485     // JDK-8132732
 486     public static class S09 {
 487 
 488         private final static String TESTCASE = "two annotated setters";
 489 
 490         private int x[] = new int[3];
 491 
 492         @BeanProperty(
 493             description  = DESCRIPTION,
 494             bound        = BOUND,
 495             expert       = EXPERT,
 496             hidden       = HIDDEN,
 497             preferred    = PREFERRED,
 498             required     = REQUIRED,
 499             visualUpdate = UPDATE,
 500             enumerationValues = {V_NAME})
 501         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 502 
 503         @BeanProperty(
 504             description  = DESCRIPTION_2,
 505             bound        = !BOUND,
 506             expert       = !EXPERT,
 507             hidden       = !HIDDEN,
 508             preferred    = !PREFERRED,
 509             required     = !REQUIRED,
 510             visualUpdate = !UPDATE)
 511         public void setX(int i, int v) throws IndexOutOfBoundsException {
 512             if (i < 0 || i >= x.length) {
 513                 throw new IndexOutOfBoundsException(); }
 514             x[i] = v;
 515         }
 516 
 517 
 518         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 519         public void removePropertyChangeListener(PropertyChangeListener l) {}
 520     }
 521 
 522     public static class G10 {
 523 
 524         private final static String TESTCASE =
 525             "getter + similarly named field";
 526 
 527         public int prop, Prop, setProp, getProp;
 528 
 529         @BeanProperty(
 530             description  = DESCRIPTION,
 531             bound        = BOUND,
 532             expert       = EXPERT,
 533             hidden       = HIDDEN,
 534             preferred    = PREFERRED,
 535             required     = REQUIRED,


 820             required     = REQUIRED,
 821             visualUpdate = UPDATE,
 822             enumerationValues = {V_NAME})
 823         public int getX() { return x; }
 824 
 825         @BeanProperty(
 826             description  = DESCRIPTION_2,
 827             bound        = !BOUND,
 828             expert       = !EXPERT,
 829             hidden       = !HIDDEN,
 830             preferred    = !PREFERRED,
 831             required     = !REQUIRED,
 832             visualUpdate = !UPDATE)
 833         public void setX(int v) { x = v; }
 834 
 835 
 836         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 837         public void removePropertyChangeListener(PropertyChangeListener l) {}
 838     }
 839 



 840 











































 841 
 842 
 843     // ---------- checks ----------
 844 
 845     private static boolean check(String what, boolean v, boolean ref) {
 846 
 847         boolean ok = (v == ref);
 848         if (!ok) { System.out.println(
 849             "invalid " + what + ": " + v + ", expected: " + ref); }
 850         return ok;
 851     }
 852 
 853     private static boolean checkInfo(BeanInfo i) {
 854 
 855         System.out.println("checking info...");
 856 
 857         PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
 858         int nd = descriptors.length;
 859         if (nd != 1) {
 860             System.out.println("invalid number of descriptors: " + nd);
 861             return false;
 862         }
 863 
 864         PropertyDescriptor d = descriptors[0];
 865 
 866         String descr = d.getShortDescription();
 867         boolean ok = descr.equals(DESCRIPTION);
 868         if (!ok) { System.out.println("invalid description: " + descr +
 869                 ", expected: " + DESCRIPTION); }
 870 
 871         ok &= check("isBound",  d.isBound(),  BOUND);
 872         ok &= check("isExpert", d.isExpert(), EXPERT);
 873         ok &= check("isHidden", d.isHidden(), HIDDEN);
 874         ok &= check("isPreferred", d.isPreferred(), PREFERRED);
 875         ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
 876         ok &= check("visualUpdate",
 877             (boolean) d.getValue("visualUpdate"), UPDATE);
 878 


 879         Object vals[] = (Object[]) d.getValue("enumerationValues");
 880         if (vals == null) {
 881             System.out.println("null enumerationValues");
 882             return false;
 883         }
 884 
 885         boolean okVals = (
 886             (vals.length == 3) &&
 887              vals[0].toString().equals(V_SHORT) &&
 888              vals[1].toString().equals(V)       &&
 889              vals[2].toString().equals(V_NAME));
 890 
 891         if (!okVals) { System.out.println("invalid enumerationValues"); }
 892 
 893         return (ok && okVals);
 894     }
 895 
 896     private static boolean checkAlternativeInfo(BeanInfo i) {
 897 
 898         System.out.println("checking alternative info...");


 919         ok &= check("visualUpdate",
 920             (boolean) d.getValue("visualUpdate"), !UPDATE);
 921 
 922         Object vals[] = (Object[]) d.getValue("enumerationValues");
 923         if (vals != null || vals.length > 0) {
 924             System.out.println("non-null enumerationValues");
 925             return false;
 926         }
 927 
 928         return ok;
 929     }
 930 
 931 
 932     private static boolean checkAlternative(Class<?> c) {
 933         return (
 934             c.equals(G09.class) ||
 935             c.equals(S09.class) ||
 936             c.equals(GS.class));
 937     }
 938 




 939 
 940     // ---------- run test ----------
 941 
 942     public static void main(String[] args) throws Exception {
 943 
 944         Class<?> cases[] = {
 945 
 946             G01.class, S01.class,
 947             // G02.class, S02.class, // TODO: please update after 8132703 fix
 948             // G03.class, S03.class, // TODO: please update after 8132703 fix
 949             // G04.class, S04.class, // TODO: please update after 8132163 fix
 950             G05.class, // S05.class, // TODO: please update after 8132163 fix
 951             G06.class, S06.class,
 952             G07.class, S07.class,
 953             // G08.class, S08.class, // TODO: please update after 8132732 fix
 954             // G09.class, S09.class, // TODO: please update after 8132732 fix
 955             G10.class, S10.class,
 956             G11.class, S11.class,
 957             // G12.class, S12.class, // TODO: please update after 8132163 fix
 958             G13.class, // S13.class, // TODO: please update after 8154756 fix
 959             // G14.class, S14.class, // TODO: please update after 8132888 fix or
 960                                      // remove these cases if it is not an issue
 961             // GS.class, // TODO: please update after 8132973 fix
 962             getX.class, setX.class

 963         };
 964 
 965         boolean passed = true;
 966 
 967         for (Class<?> c: cases) {
 968 
 969             java.lang.reflect.Field f = c.getDeclaredField("TESTCASE");
 970             f.setAccessible(true);
 971             String descr = f.get(c).toString();
 972 
 973             System.out.println("\n" + c.getSimpleName() + " (" + descr + "):");
 974             BeanInfo i;
 975             try { i = Introspector.getBeanInfo(c, Object.class); }
 976             catch (IntrospectionException e) { throw new RuntimeException(e); }
 977             boolean ok = checkInfo(i);
 978             if (checkAlternative(c)) {
 979                 ok |= checkAlternativeInfo(i);
 980             }
 981             System.out.println(ok ? "OK" : "NOK");
 982             passed = passed && ok;
 983         }
 984 
 985         if (!passed) { throw new RuntimeException("test failed"); }
 986         System.out.println("\ntest passed");
 987     }
 988 }


 280 
 281         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 282         public void removePropertyChangeListener(PropertyChangeListener l) {}
 283     }
 284 
 285     public static class G06 {
 286 
 287         private final static String TESTCASE = "indexed getter";
 288 
 289         private final int x[] = {X, X, X};
 290 
 291         @BeanProperty(
 292             description  = DESCRIPTION,
 293             bound        = BOUND,
 294             expert       = EXPERT,
 295             hidden       = HIDDEN,
 296             preferred    = PREFERRED,
 297             required     = REQUIRED,
 298             visualUpdate = UPDATE,
 299             enumerationValues = {V_NAME})
 300         public int getX(int i) { return x[i]; }




 301 
 302         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 303         public void removePropertyChangeListener(PropertyChangeListener l) {}
 304     }
 305 
 306     public static class S06 {
 307 
 308         private final static String TESTCASE = "indexed setter";
 309 
 310         private final int x[] = {X, X, X};
 311 
 312         @BeanProperty(
 313             description  = DESCRIPTION,
 314             bound        = BOUND,
 315             expert       = EXPERT,
 316             hidden       = HIDDEN,
 317             preferred    = PREFERRED,
 318             required     = REQUIRED,
 319             visualUpdate = UPDATE,
 320             enumerationValues = {V_NAME})
 321         public void setX(int i, int v) { x[i] = v; }




 322 
 323         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 324         public void removePropertyChangeListener(PropertyChangeListener l) {}
 325     }
 326 
 327     public static class G07 {
 328 
 329         private final static String TESTCASE =
 330             "indexed (annotated) + non-indexed getters";
 331 
 332         private final int x[] = {X, X, X};
 333 
 334         @BeanProperty(
 335             description  = DESCRIPTION,
 336             bound        = BOUND,
 337             expert       = EXPERT,
 338             hidden       = HIDDEN,
 339             preferred    = PREFERRED,
 340             required     = REQUIRED,
 341             visualUpdate = UPDATE,
 342             enumerationValues = {V_NAME})
 343         public int getX(int i) { return x[i]; }




 344 
 345         public int[] getX() { return x; }
 346 
 347         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 348         public void removePropertyChangeListener(PropertyChangeListener l) {}
 349     }
 350 
 351     public static class S07 {
 352 
 353         private final static String TESTCASE =
 354             "indexed (annotated) + non-indexed setters";
 355 
 356         private int x[] = new int[3];
 357 
 358         @BeanProperty(
 359             description  = DESCRIPTION,
 360             bound        = BOUND,
 361             expert       = EXPERT,
 362             hidden       = HIDDEN,
 363             preferred    = PREFERRED,
 364             required     = REQUIRED,
 365             visualUpdate = UPDATE,
 366             enumerationValues = {V_NAME})
 367         public void setX(int i, int v) { x[i] = v; }




 368 
 369         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 370 
 371         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 372         public void removePropertyChangeListener(PropertyChangeListener l) {}
 373     }
 374 
 375     // JDK-8132732
 376     public static class G08 {
 377 
 378         private final static String TESTCASE =
 379             "non-indexed (annotated) + indexed getters";
 380 
 381         private final int x[] = {X, X, X};
 382 
 383         @BeanProperty(
 384             description  = DESCRIPTION,
 385             bound        = BOUND,
 386             expert       = EXPERT,
 387             hidden       = HIDDEN,
 388             preferred    = PREFERRED,
 389             required     = REQUIRED,
 390             visualUpdate = UPDATE,
 391             enumerationValues = {V_NAME})
 392         public int[] getX() { return x; }
 393 
 394         public int getX(int i) { return x[i]; }




 395 
 396         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 397         public void removePropertyChangeListener(PropertyChangeListener l) {}
 398     }
 399 
 400     // JDK-8132732
 401     public static class S08 {
 402 
 403         private final static String TESTCASE =
 404             "non-indexed (annotated) + indexed setters";
 405 
 406         private int x[] = new int[3];
 407 
 408         @BeanProperty(
 409             description  = DESCRIPTION,
 410             bound        = BOUND,
 411             expert       = EXPERT,
 412             hidden       = HIDDEN,
 413             preferred    = PREFERRED,
 414             required     = REQUIRED,
 415             visualUpdate = UPDATE,
 416             enumerationValues = {V_NAME})
 417         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 418 
 419         public void setX(int i, int v) { x[i] = v; }




 420 
 421         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 422         public void removePropertyChangeListener(PropertyChangeListener l) {}
 423     }
 424 
 425     // JDK-8132732
 426     public static class G09 {
 427 
 428         private final static String TESTCASE = "two annotated getters";
 429 
 430         private final int x[] = {X, X, X};
 431 
 432         @BeanProperty(
 433             description  = DESCRIPTION,
 434             bound        = BOUND,
 435             expert       = EXPERT,
 436             hidden       = HIDDEN,
 437             preferred    = PREFERRED,
 438             required     = REQUIRED,
 439             visualUpdate = UPDATE,
 440             enumerationValues = {V_NAME})
 441         public int[] getX() { return x; }
 442 
 443         @BeanProperty(
 444             description  = DESCRIPTION_2,
 445             bound        = !BOUND,
 446             expert       = !EXPERT,
 447             hidden       = !HIDDEN,
 448             preferred    = !PREFERRED,
 449             required     = !REQUIRED,
 450             visualUpdate = !UPDATE)
 451         public int getX(int i) { return x[i]; }




 452 
 453         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 454         public void removePropertyChangeListener(PropertyChangeListener l) {}
 455     }
 456 
 457     // JDK-8132732
 458     public static class S09 {
 459 
 460         private final static String TESTCASE = "two annotated setters";
 461 
 462         private int x[] = new int[3];
 463 
 464         @BeanProperty(
 465             description  = DESCRIPTION,
 466             bound        = BOUND,
 467             expert       = EXPERT,
 468             hidden       = HIDDEN,
 469             preferred    = PREFERRED,
 470             required     = REQUIRED,
 471             visualUpdate = UPDATE,
 472             enumerationValues = {V_NAME})
 473         public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
 474 
 475         @BeanProperty(
 476             description  = DESCRIPTION_2,
 477             bound        = !BOUND,
 478             expert       = !EXPERT,
 479             hidden       = !HIDDEN,
 480             preferred    = !PREFERRED,
 481             required     = !REQUIRED,
 482             visualUpdate = !UPDATE)
 483         public void setX(int i, int v) { x[i] = v; }




 484 
 485 
 486         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 487         public void removePropertyChangeListener(PropertyChangeListener l) {}
 488     }
 489 
 490     public static class G10 {
 491 
 492         private final static String TESTCASE =
 493             "getter + similarly named field";
 494 
 495         public int prop, Prop, setProp, getProp;
 496 
 497         @BeanProperty(
 498             description  = DESCRIPTION,
 499             bound        = BOUND,
 500             expert       = EXPERT,
 501             hidden       = HIDDEN,
 502             preferred    = PREFERRED,
 503             required     = REQUIRED,


 788             required     = REQUIRED,
 789             visualUpdate = UPDATE,
 790             enumerationValues = {V_NAME})
 791         public int getX() { return x; }
 792 
 793         @BeanProperty(
 794             description  = DESCRIPTION_2,
 795             bound        = !BOUND,
 796             expert       = !EXPERT,
 797             hidden       = !HIDDEN,
 798             preferred    = !PREFERRED,
 799             required     = !REQUIRED,
 800             visualUpdate = !UPDATE)
 801         public void setX(int v) { x = v; }
 802 
 803 
 804         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 805         public void removePropertyChangeListener(PropertyChangeListener l) {}
 806     }
 807 
 808     public static class Self {
 809 
 810         private final static String TESTCASE = "trivial singleton";
 811 
 812         private static Self instance = null;
 813         private Self() {}
 814 
 815         @BeanProperty(
 816             description  = DESCRIPTION,
 817             bound        = BOUND,
 818             expert       = EXPERT,
 819             hidden       = HIDDEN,
 820             preferred    = PREFERRED,
 821             required     = REQUIRED,
 822             visualUpdate = UPDATE)
 823         public Self getSelf() {
 824             if (instance == null) { instance = new Self(); }
 825             return instance;
 826         }
 827 
 828         public void addPropertyChangeListener(PropertyChangeListener l)    {}
 829         public void removePropertyChangeListener(PropertyChangeListener l) {}
 830     }
 831 
 832     public static class SelfArr {
 833 
 834         private final static String TESTCASE = "trivial singleton + array";
 835 
 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;
 876         }
 877 
 878         PropertyDescriptor d = descriptors[0];
 879 
 880         String descr = d.getShortDescription();
 881         boolean ok = descr.equals(DESCRIPTION);
 882         if (!ok) { System.out.println("invalid description: " + descr +
 883                 ", expected: " + DESCRIPTION); }
 884 
 885         ok &= check("isBound",  d.isBound(),  BOUND);
 886         ok &= check("isExpert", d.isExpert(), EXPERT);
 887         ok &= check("isHidden", d.isHidden(), HIDDEN);
 888         ok &= check("isPreferred", d.isPreferred(), PREFERRED);
 889         ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
 890         ok &= check("visualUpdate",
 891             (boolean) d.getValue("visualUpdate"), UPDATE);
 892 
 893         if (!checkVals) { return ok; }
 894 
 895         Object vals[] = (Object[]) d.getValue("enumerationValues");
 896         if (vals == null) {
 897             System.out.println("null enumerationValues");
 898             return false;
 899         }
 900 
 901         boolean okVals = (
 902             (vals.length == 3) &&
 903              vals[0].toString().equals(V_SHORT) &&
 904              vals[1].toString().equals(V)       &&
 905              vals[2].toString().equals(V_NAME));
 906 
 907         if (!okVals) { System.out.println("invalid enumerationValues"); }
 908 
 909         return (ok && okVals);
 910     }
 911 
 912     private static boolean checkAlternativeInfo(BeanInfo i) {
 913 
 914         System.out.println("checking alternative info...");


 935         ok &= check("visualUpdate",
 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,
 977             // G12.class, S12.class, // TODO: please update after 8132163 fix
 978             G13.class, // S13.class, // TODO: please update after 8154756 fix
 979             // G14.class, S14.class, // TODO: please update after 8132888 fix or
 980                                      // remove these cases if it is not an issue
 981             // GS.class, // TODO: please update after 8132973 fix
 982             getX.class, setX.class,
 983             Self.class, SelfArr.class
 984         };
 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 }
< prev index next >