1 /* 2 * Copyright (c) 2017, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package myapp4; 27 28 import java.lang.reflect.UndeclaredThrowableException; 29 import javafx.beans.property.adapter.JavaBeanDoubleProperty; 30 import javafx.beans.property.adapter.JavaBeanDoublePropertyBuilder; 31 import javafx.beans.property.adapter.JavaBeanObjectProperty; 32 import javafx.beans.property.adapter.JavaBeanObjectPropertyBuilder; 33 import javafx.beans.property.adapter.ReadOnlyJavaBeanStringProperty; 34 import javafx.beans.property.adapter.ReadOnlyJavaBeanStringPropertyBuilder; 35 import myapp4.pkg1.POJO; 36 import myapp4.pkg1.RefClass; 37 38 import static myapp4.Constants.*; 39 40 /** 41 * Modular test application for testing JavaFX beans. 42 * This is launched by ModuleLauncherTest. 43 */ 44 public class AppBeansUnexported { 45 46 /** 47 * @param args the command line arguments 48 */ 49 public static void main(String[] args) { 50 try { 51 new AppBeansUnexported().doTest(); 52 System.exit(ERROR_NONE); 53 } catch (Throwable t) { 54 t.printStackTrace(System.err); 55 System.exit(ERROR_ASSERTION_FAILURE); 56 } 57 } 58 59 private void checkException(UndeclaredThrowableException ex) { 60 Throwable cause = ex.getCause(); 61 if (! (cause instanceof IllegalAccessException)) { 62 System.err.println("ERROR: unexpected cause: " + cause); 63 throw ex; 64 } 65 66 String message = cause.getMessage(); 67 if (message == null) { 68 System.err.println("ERROR: detail message of cause is null"); 69 throw ex; 70 } 71 72 boolean badMessage = false; 73 if (!message.contains(" cannot access class ")) badMessage = true; 74 if (!message.contains(" does not open ")) badMessage = true; 75 if (!message.endsWith(" to javafx.base")) badMessage = true; 76 if (badMessage) { 77 System.err.println("ERROR: detail message not formatted correctly: " + message); 78 throw ex; 79 } 80 } 81 82 public void doTest() throws Exception { 83 String name = "test object"; 84 double val = 1.2; 85 RefClass obj = new RefClass(); 86 87 POJO bean = new POJO(name, val, obj); 88 89 JavaBeanDoubleProperty valProp = JavaBeanDoublePropertyBuilder.create() 90 .bean(bean) 91 .name("val") 92 .build(); 93 94 try { 95 valProp.get(); 96 throw new AssertionError("ERROR: did not get the expected exception"); 97 } catch (UndeclaredThrowableException ex) { 98 checkException(ex); 99 } 100 101 val = 2.5; 102 try { 103 valProp.set(val); 104 throw new AssertionError("ERROR: did not get the expected exception"); 105 } catch (UndeclaredThrowableException ex) { 106 checkException(ex); 107 } 108 109 JavaBeanObjectProperty<RefClass> objProp = JavaBeanObjectPropertyBuilder.create() 110 .bean(bean) 111 .name("obj") 112 .build(); 113 114 try { 115 objProp.get(); 116 throw new AssertionError("ERROR: did not get the expected exception"); 117 } catch (UndeclaredThrowableException ex) { 118 checkException(ex); 119 } 120 121 obj = new RefClass(); 122 try { 123 objProp.set(obj); 124 throw new AssertionError("ERROR: did not get the expected exception"); 125 } catch (UndeclaredThrowableException ex) { 126 checkException(ex); 127 } 128 129 ReadOnlyJavaBeanStringProperty namePropRO = ReadOnlyJavaBeanStringPropertyBuilder.create() 130 .bean(bean) 131 .name("name") 132 .build(); 133 134 try { 135 namePropRO.get(); 136 throw new AssertionError("ERROR: did not get the expected exception"); 137 } catch (UndeclaredThrowableException ex) { 138 checkException(ex); 139 } 140 } 141 142 }