@Override protected Node impl_drawNode() throws IOException { final Label label = new Label(); label.setId(LOADER_LOG_ID); FXMLLoader fxmlLoader = new FXMLLoader(resource); fxmlLoader.impl_setStaticLoad(true); try { fxmlLoader.load(); label.setText(SUCCESSFUL_STATIC_LOAD); } catch(LoadException e) { e.printStackTrace(); for(ParseTraceElement trace: fxmlLoader.impl_getParseTrace()) { label.setText(label.getText() + trace.toString() + '\n'); } } return label; }
@Override public Node impl_drawNode() throws IOException { Button button = null; InputStream is = null; FXMLLoader fxmlLoader = new FXMLLoader(); MyRootElement myRootElement = new MyRootElement(); try { is = resource.openStream(); fxmlLoader.load(is); fxmlLoader.setController(myRootElement); } catch (Exception e) { if(e instanceof LoadException && e.getMessage().contains("No controller specified.")) { return retRec; } e.printStackTrace(); System.out.println("message: " + e.getMessage()); reportGetterFailure("exception thrown."); } finally { is.close(); } reportGetterFailure("Controller is not null."); return redRectangle; }
@Test public void test_fxml_construction_of_area() throws IOException, LoadException { // FxmlTest.fxml is located in resources folder: src/integrationTest/resources/org/fxmisc/richtext/api/ FXMLLoader fxml = new FXMLLoader( getClass().getResource( "FxmlTest.fxml" ) ); StyleClassedTextArea area = (StyleClassedTextArea) fxml.load(); // fxml.load() will throw a LoadException if any properties failed to be set, // so if 'area' is not null then all properties are guaranteed to have been set. org.junit.Assert.assertNotNull( area ); FxmlTest ctrl = fxml.getController(); // Check that the controller was loaded and that it has the relevant // test methods which are referenced in the loaded fxml file. org.junit.Assert.assertNotNull( ctrl ); ctrl.testWithMouseEvent( null ); ctrl.testWithOutMouseEvent(); }
@Test public void load_with_type_single_invalid_file_failure() { final Try<? extends Node> failingLoadResult = this.easyFxml.loadNode(TEST_NODES.INVALID); this.assertPaneFailedLoadingAndDidNotRegister( failingLoadResult, this.controllerManager.getSingle(TEST_NODES.INVALID), LoadException.class ); }
@Test public void load_with_type_multiple_invalid_file_failure() { final Try<Pane> testPaneLoadResult = this.easyFxml.loadNode(TEST_NODES.INVALID, SELECTOR); this.assertPaneFailedLoadingAndDidNotRegister( testPaneLoadResult, this.controllerManager.getMultiple(TEST_NODES.INVALID, SELECTOR), LoadException.class ); }
@Override public Node impl_drawNode() throws IOException { VBox vb = new VBox(); vb.setId("vb_root"); Node node = null; FXMLLoader fxmlLoader = new FXMLLoader(); InputStream is = null; try { is = resource.openStream(); node = (Node) fxmlLoader.load(is); fxmlLoader.setRoot(vb); } catch (LoadException e) { e.printStackTrace(); System.out.println("message: " + e.getMessage()); return retRec; } catch (Exception exc) { exc.printStackTrace(); System.out.println("message: " + exc.getMessage()); reportGetterFailure("exception thrown."); } finally { is.close(); } // if(node.getId() == null || !node.getId().equals("default_root")) // { // reportGetterFailure("Root id: " + node.getId()); // } return redRectangle; }
@Test public void malformedFxmlFileShouldThrow() { thrown.expect(ViewfxException.class); thrown.expectMessage("Failed to load view from FXML file"); thrown.expectCause(instanceOf(LoadException.class)); viewLoader.load(Malformed.class); }