ComponentHelpers { public static List<Component> findAllComponents( Graphs graphs ) { Set<Component> result = new HashSet<> (); Set<Component> toProcess = new HashSet<> (); toProcess.addAll( graphs.getRootComponents()); while( ! toProcess.isEmpty()) { Component current = toProcess.iterator().next(); result.add( current ); toProcess.addAll( findAllExtendedComponents( current )); toProcess.addAll( findAllExtendingComponents( current )); toProcess.addAll( findAllChildren( current )); toProcess.addAll( findAllAncestors( current )); toProcess.removeAll( result ); } return new ArrayList<>( 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 testFindAllComponents_simple() { ApplicationTemplate app = new ApplicationTemplate(); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); Graphs graphs = new Graphs(); app.setGraphs( graphs ); Component comp1 = new Component( "comp1" ); graphs.getRootComponents().add( comp1 ); Assert.assertEquals( 1, ComponentHelpers.findAllComponents( app ).size()); comp1.addChild( new Component( "comp-2" )); Assert.assertEquals( 2, ComponentHelpers.findAllComponents( app ).size()); Component comp3 = new Component( "comp_3" ); graphs.getRootComponents().add( comp3 ); comp3.addChild( new Component( "comp-2" )); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); }
@Test public void testFindAllComponents_complex1() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); Assert.assertEquals( 10, ComponentHelpers.findAllComponents( app ).size()); }
@Test public void testFindAllComponents_appInstance() { ApplicationTemplate tpl = ComplexApplicationFactory1.newApplication(); Application app = new Application( tpl ); Assert.assertEquals( 10, ComponentHelpers.findAllComponents( app ).size()); app = new Application( null ); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); }
@Test public void testFindAllComponents_extended() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); app.getGraphs().getRootComponents().clear(); Component root1 = new Component( "root1" ).installerName( Constants.TARGET_INSTALLER ); Component root2 = new Component( "root2" ); Component root3 = new Component( "root3" ); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root1 ); Assert.assertEquals( 1, ComponentHelpers.findAllComponents( app ).size()); root2.extendComponent( root1 ); Assert.assertEquals( 2, ComponentHelpers.findAllComponents( app ).size()); root3.extendComponent( root2 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root2 ); app.getGraphs().getRootComponents().add( root3 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); Component childComponent = new Component( "child" ).installerName( "script" ); root3.addChild( childComponent ); Assert.assertEquals( 4, ComponentHelpers.findAllComponents( app ).size()); }