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 myapp6; 27 28 import java.io.IOException; 29 import java.net.URL; 30 import javafx.application.Application; 31 import javafx.application.Platform; 32 import javafx.collections.ObservableList; 33 import javafx.fxml.FXMLLoader; 34 import javafx.fxml.LoadException; 35 import javafx.scene.Node; 36 import javafx.scene.layout.StackPane; 37 import javafx.scene.text.Text; 38 import javafx.stage.Stage; 39 import myapp6.pkg1.AnnotatedController; 40 import myapp6.pkg1.CustomNode; 41 import myapp6.pkg1.SimpleController; 42 43 import static myapp6.Constants.*; 44 45 /** 46 * Modular test application for testing FXML. 47 * This is launched by ModuleLauncherTest. 48 */ 49 public class AppFXMLUnexported extends Application { 50 51 /** 52 * @param args the command line arguments 53 */ 54 public static void main(String[] args) { 55 try { 56 Application.launch(args); 57 } catch (Throwable t) { 58 System.err.println("ERROR: caught unexpected exception: " + t); 59 t.printStackTrace(System.err); 60 System.exit(ERROR_UNEXPECTED_EXCEPTION); 61 } 62 } 63 64 // Load test FXML file -- no controller 65 private void doTestNone() throws IOException { 66 final URL fxmlURL = Util.getURL(SimpleController.class, "TestNone"); 67 68 FXMLLoader loader = new FXMLLoader(fxmlURL); 69 Node fxmlRoot = loader.load(); 70 71 // Verify that the root node is a StackPane with the expected ID 72 Util.assertNotNull(fxmlRoot); 73 Util.assertTrue("fxmlRoot is not instance of StackPane", fxmlRoot instanceof StackPane); 74 Util.assertEquals("RootTestNone", fxmlRoot.getId()); 75 } 76 77 // Load test FXML file with reference to CustomNode -- no controller 78 private void doTestCustomNode() throws IOException { 79 final URL fxmlURL = Util.getURL(SimpleController.class, "TestCustomNode"); 80 81 FXMLLoader loader = new FXMLLoader(fxmlURL); 82 try { 83 Node fxmlRoot = loader.load(); 84 throw new AssertionError("ERROR: did not get the expected exception"); 85 } catch (LoadException ex) { 86 ex.printStackTrace(); 87 } 88 } 89 90 // Load test FXML file -- SimpleController 91 private void doTestSimple() throws IOException { 92 final URL fxmlURL = Util.getURL(SimpleController.class, "TestSimple"); 93 94 FXMLLoader loader = new FXMLLoader(fxmlURL); 95 try { 96 Node fxmlRoot = loader.load(); 97 throw new AssertionError("ERROR: did not get the expected exception"); 98 } catch (LoadException ex) { 99 ex.printStackTrace(); 100 } 101 } 102 103 // Load test FXML file -- AnnotatedController 104 private void doTestAnnotated() throws IOException { 105 final URL fxmlURL = Util.getURL(SimpleController.class, "TestAnnotated"); 106 107 FXMLLoader loader = new FXMLLoader(fxmlURL); 108 try { 109 Node fxmlRoot = loader.load(); 110 throw new AssertionError("ERROR: did not get the expected exception"); 111 } catch (LoadException ex) { 112 ex.printStackTrace(); 113 } 114 } 115 116 @Override 117 public void start(Stage stage) { 118 try { 119 doTestNone(); 120 doTestCustomNode(); 121 doTestSimple(); 122 doTestAnnotated(); 123 } catch (AssertionError ex) { 124 ex.printStackTrace(System.err); 125 System.exit(ERROR_ASSERTION_FAILURE); 126 } catch (Error | Exception ex) { 127 System.err.println("ERROR: caught unexpected exception: " + ex); 128 ex.printStackTrace(System.err); 129 System.exit(ERROR_UNEXPECTED_EXCEPTION); 130 } 131 Platform.exit(); 132 } 133 134 @Override public void stop() { 135 System.exit(ERROR_NONE); 136 } 137 138 }