ComponentHelpers { public static Map<String,ImportedVariable> findAllImportedVariables( Component component ) { Map<String,ImportedVariable> result = new HashMap<> (); List<Component> extendedComponents = findAllExtendedComponents( component ); Collections.reverse( extendedComponents ); for( Component c : extendedComponents ) result.putAll( c.importedVariables ); return result; } private  ComponentHelpers(); static Component findComponent( Graphs graphs, String name ); static Component findComponent( AbstractApplication app, String name ); static Component findComponentFrom( Component component, String componentName ); static List<String> extractNames( Collection<? extends AbstractType> types ); static boolean isTarget( Component component ); static Collection<Component> findAllChildren( Component component ); static Collection<Component> findAllAncestors( Component component ); static String findComponentInstaller( Component component ); static Map<String,String> findAllExportedVariables( Component component ); static Map<String,String> findAllExportedVariables( AbstractType type ); static Map<String,String> findAllExportedVariables( Graphs graphs ); static Map<String,String> findAllExportedVariables( Facet facet ); static Map<String,ImportedVariable> findAllImportedVariables( Component component ); static Collection<Facet> findAllFacets( Component component ); static List<Component> findAllExtendedComponents( Component component ); static Collection<Facet> findAllExtendedFacets( Facet facet ); static Collection<Facet> findAllExtendingFacets( Facet facet ); static Collection<Component> findAllExtendingComponents( Component component ); static List<Component> findAllComponents( Graphs graphs ); static List<Component> findAllComponents( AbstractApplication app ); static String searchForLoop( Component component ); static String searchForInheritanceCycle( Facet facet ); static String searchForInheritanceCycle( Component component ); static Map<String,Boolean> findComponentDependenciesFor( Component component ); static Map<Component,Boolean> findComponentDependenciesFor( Component component, ApplicationTemplate app ); static Map<Component,Boolean> findComponentsThatDependOn( Component component, ApplicationTemplate app );  }
@Test public void testFindAllImportedVariables() { Component root = new Component( "root" ); Component serverWithApp = new Component( "server with app" ); Component serverWithAnotherApp = new Component( "server with another app" ); Component db = new Component( "database" ); root.addChild( db ); root.addChild( serverWithAnotherApp ); root.addChild( serverWithApp ); serverWithApp.addImportedVariable( new ImportedVariable( "database.ip", false, false )); serverWithApp.addImportedVariable( new ImportedVariable( "database.port", true, false )); serverWithApp.addExportedVariable( new ExportedVariable( "url", "something" )); serverWithAnotherApp.extendComponent( serverWithApp ); serverWithAnotherApp.addImportedVariable( new ImportedVariable( "database.port", false, false )); serverWithAnotherApp.addImportedVariable( new ImportedVariable( "whatever", false, false )); db.addExportedVariable( new ExportedVariable( "ip", null )); db.addExportedVariable( new ExportedVariable( "port", "3306" )); Assert.assertEquals( 0, ComponentHelpers.findAllImportedVariables( db ).size()); Assert.assertEquals( 0, ComponentHelpers.findAllImportedVariables( root ).size()); Map<String,ImportedVariable> imports = ComponentHelpers.findAllImportedVariables( serverWithApp ); Assert.assertEquals( 2, imports.size()); Assert.assertTrue( imports.containsKey( "database.ip" )); Assert.assertTrue( imports.containsKey( "database.port" )); Assert.assertTrue( imports.get( "database.port" ).isOptional()); Assert.assertFalse( imports.get( "database.ip" ).isOptional()); imports = ComponentHelpers.findAllImportedVariables( serverWithAnotherApp ); Assert.assertEquals( 3, imports.size()); Assert.assertTrue( imports.containsKey( "database.ip" )); Assert.assertTrue( imports.containsKey( "database.port" )); Assert.assertTrue( imports.containsKey( "whatever" )); Assert.assertFalse( imports.get( "database.ip" ).isOptional()); Assert.assertFalse( imports.get( "database.port" ).isOptional()); Assert.assertFalse( imports.get( "whatever" ).isOptional()); }