FromGraphs { public FileDefinition buildFileDefinition( Graphs graphs, File targetFile, boolean addComment ) { FileDefinition result = new FileDefinition( targetFile ); result.setFileType( FileDefinition.GRAPH ); if( addComment ) { String s = "# File created from an in-memory model,\n# without a binding to existing files."; BlockComment initialComment = new BlockComment( result, s ); result.getBlocks().add( initialComment ); result.getBlocks().add( new BlockBlank( result, "\n" )); } Set<String> alreadySerializedNames = new HashSet<> (); for( Component c : ComponentHelpers.findAllComponents( graphs )) { if( alreadySerializedNames.contains( c.getName())) continue; alreadySerializedNames.add( c.getName()); result.getBlocks().addAll( buildComponent( result, c, addComment )); for( Facet f : ComponentHelpers.findAllFacets( c )) { if( alreadySerializedNames.contains( f.getName())) continue; alreadySerializedNames.add( f.getName()); result.getBlocks().addAll( buildFacet( result, f, addComment )); } } for( Facet f : graphs.getFacetNameToFacet().values()) { if( alreadySerializedNames.contains( f.getName())) continue; alreadySerializedNames.add( f.getName()); result.getBlocks().addAll( buildFacet( result, f, addComment )); } return result; }  FileDefinition buildFileDefinition( Graphs graphs, File targetFile, boolean addComment );  }
@Test public void testFromGraphs_noFacet() throws Exception { Graphs graphs = new Graphs(); Component cA = new Component( "A" ).installerName( Constants.TARGET_INSTALLER ); graphs.getRootComponents().add( cA ); cA.addExportedVariable( new ExportedVariable( "A.port", "9000" )); cA.addExportedVariable( new ExportedVariable( "A.ip", null )); cA.addImportedVariable( new ImportedVariable( "B.port", false, false )); cA.addImportedVariable( new ImportedVariable( "B.ip", true, false )); Component cB = new Component( "B" ).installerName( Constants.TARGET_INSTALLER ); graphs.getRootComponents().add( cB ); cB.addExportedVariable( new ExportedVariable( "port", "9000" )); cB.addExportedVariable( new ExportedVariable( "ip", null )); compareGraphs( graphs, false ); FileDefinition defToWrite = new FromGraphs().buildFileDefinition( graphs, null, false ); String s = ParsingModelIo.writeConfigurationFile( defToWrite, false, System.getProperty( "line.separator" )); Assert.assertTrue( s.contains( "port=\"9000\"" )); Assert.assertTrue( s.contains( "exports: ip, port=\"9000\";" )); }