ComponentHelpers { public static Map<String,String> findAllExportedVariables( Component component ) { return findAllExportedVariables( component, new HashSet<Component>( 0 )); } 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 testFindAllExportedVariables_simple() { Component comp = new Component( "comp" ); Map<String,String> exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 0, exports.size()); comp.addExportedVariable( new ExportedVariable( "test", "ok" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 1, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); }
@Test public void testFindAllExportedVariables_withFacet() { Component comp = new Component( "comp" ); comp.addExportedVariable( new ExportedVariable( "test", "ok" )); Facet f = new Facet( "facet" ); f.addExportedVariable( new ExportedVariable( "property", "value" )); comp.associateFacet( f ); Map<String,String> exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "value", exports.get( "facet.property" )); Assert.assertEquals( "value", exports.get( "comp.property" )); comp.addExportedVariable( new ExportedVariable( "facet.property", "something different" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "something different", exports.get( "facet.property" )); Assert.assertEquals( "something different", exports.get( "comp.property" )); comp.exportedVariables.remove( "facet.property" ); comp.addExportedVariable( new ExportedVariable( "property", "great" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "great", exports.get( "facet.property" )); Assert.assertEquals( "great", exports.get( "comp.property" )); comp.exportedVariables.remove( "property" ); comp.addExportedVariable( new ExportedVariable( "comp.property", "ha! ha!" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "value", exports.get( "facet.property" )); Assert.assertEquals( "ha! ha!", exports.get( "comp.property" )); Map<String,String> abstractExports = ComponentHelpers.findAllExportedVariables((AbstractType) comp); Assert.assertEquals( abstractExports.size(), exports.size()); abstractExports = ComponentHelpers.findAllExportedVariables((AbstractType) f); Assert.assertEquals( 1, abstractExports.size()); }
@Test public void testFindAllExportedVariables_withComponentExtension() { Component comp = new Component( "comp" ); comp.addExportedVariable( new ExportedVariable( "test", "ok" )); Component parent = new Component( "parent" ); parent.addExportedVariable( new ExportedVariable( "property", "value" )); comp.extendComponent( parent ); Map<String,String> exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "value", exports.get( "parent.property" )); Assert.assertEquals( "value", exports.get( "comp.property" )); comp.addExportedVariable( new ExportedVariable( "parent.property", "something different" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "something different", exports.get( "parent.property" )); Assert.assertEquals( "something different", exports.get( "comp.property" )); comp.exportedVariables.remove( "parent.property" ); comp.addExportedVariable( new ExportedVariable( "property", "great" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "great", exports.get( "parent.property" )); Assert.assertEquals( "great", exports.get( "comp.property" )); comp.exportedVariables.remove( "property" ); comp.addExportedVariable( new ExportedVariable( "comp.property", "ha! ha!" )); exports = ComponentHelpers.findAllExportedVariables( comp ); Assert.assertEquals( 3, exports.size()); Assert.assertEquals( "ok", exports.get( "comp.test" )); Assert.assertEquals( "value", exports.get( "parent.property" )); Assert.assertEquals( "ha! ha!", exports.get( "comp.property" )); }
@Test public void testFindAllExportedVariables_veryComplex() { 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 ); serverWithAnotherApp.extendComponent( serverWithApp ); Facet serverFacet = new Facet( "server facet" ); Facet anotherServerFacet = new Facet( "another server facet" ); anotherServerFacet.extendFacet( serverFacet ); serverFacet.addExportedVariable( new ExportedVariable( "url-suffix", "some/path" )); serverWithApp.associateFacet( anotherServerFacet ); serverWithApp.addExportedVariable( new ExportedVariable( "ip", null )); serverWithApp.addExportedVariable( new ExportedVariable( serverWithApp.getName() + ".port", "8080" )); serverWithApp.addExportedVariable( new ExportedVariable( "env", "test" )); serverWithAnotherApp.addExportedVariable( new ExportedVariable( serverFacet.getName() + ".url-suffix", "another/path" )); serverWithAnotherApp.addExportedVariable( new ExportedVariable( "whatever", "something" )); serverWithAnotherApp.addExportedVariable( new ExportedVariable( "env", "prod" )); db.addExportedVariable( new ExportedVariable( "ip", null )); db.addExportedVariable( new ExportedVariable( "port", "3306" )); Assert.assertEquals( 0, ComponentHelpers.findAllExportedVariables( root ).size()); Map<String,String> exports = ComponentHelpers.findAllExportedVariables( db ); Assert.assertEquals( 2, exports.size()); Assert.assertTrue( exports.containsKey( "database.ip" )); Assert.assertNull( exports.get( "database.ip" )); Assert.assertEquals( "3306", exports.get( "database.port" )); exports = ComponentHelpers.findAllExportedVariables( serverWithApp ); Assert.assertEquals( 5, exports.size()); Assert.assertTrue( exports.containsKey( serverWithApp.getName() + ".ip" )); Assert.assertNull( exports.get( serverWithApp.getName() + ".ip" )); Assert.assertEquals( "8080", exports.get( serverWithApp.getName() + ".port" )); Assert.assertEquals( "test", exports.get( serverWithApp.getName() + ".env" )); Assert.assertEquals( "some/path", exports.get( serverWithApp.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverFacet.getName() + ".url-suffix" )); exports = ComponentHelpers.findAllExportedVariables( serverWithAnotherApp ); Assert.assertEquals( 10, exports.size()); Assert.assertTrue( exports.containsKey( serverWithApp.getName() + ".ip" )); Assert.assertNull( exports.get( serverWithApp.getName() + ".ip" )); Assert.assertTrue( exports.containsKey( serverWithAnotherApp.getName() + ".ip" )); Assert.assertNull( exports.get( serverWithAnotherApp.getName() + ".ip" )); Assert.assertEquals( "8080", exports.get( serverWithApp.getName() + ".port" )); Assert.assertEquals( "8080", exports.get( serverWithAnotherApp.getName() + ".port" )); Assert.assertEquals( "another/path", exports.get( serverFacet.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverWithApp.getName() + ".url-suffix" )); Assert.assertEquals( "some/path", exports.get( serverWithAnotherApp.getName() + ".url-suffix" )); Assert.assertEquals( "something", exports.get( serverWithAnotherApp.getName() + ".whatever" )); Assert.assertEquals( "prod", exports.get( serverWithApp.getName() + ".env" )); Assert.assertEquals( "prod", exports.get( serverWithAnotherApp.getName() + ".env" )); }