private String formatImport(Import imp) { StringBuilder sb = new StringBuilder(); sb.append( "'" ); sb.append(imp.getInstancePath()); sb.append( "' => { " ); sb.append( formatExportedVariables( imp.getExportedVars())); sb.append(" }"); return sb.toString(); }
imp.getExportedVars().put( entry.getKey(), entry.getValue()); imp.getExportedVars().put( importedVariable, exportedVariables.get( importedVariable ));
MsgCmdAddImport fakeMsg = new MsgCmdAddImport( addedAppName, imp.getComponentName(), imp.getInstancePath(), imp.getExportedVars()); try { processMsgAddImport( fakeMsg );
@Test public void testBuildTailoredImport() { String instancePath = "/whatever/this/is/a-test"; Component comp = new Component( "comp" ); comp.addImportedVariable( new ImportedVariable( "comp1.port", false, false )); comp.addImportedVariable( new ImportedVariable( "comp1.ip", false, false )); comp.addImportedVariable( new ImportedVariable( "comp2.option", true, false )); Instance inst = new Instance( "inst" ).component( comp ); // Null map Import imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", null ); Assert.assertEquals( instancePath, imp.getInstancePath()); Assert.assertEquals( 0, imp.getExportedVars().size()); // Empty map imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", new HashMap<String,String> ()); Assert.assertEquals( 0, imp.getExportedVars().size()); // Map with various variable Map<String,String> map = new HashMap<String,String> (); map.put( "comp1.ip", "127.0.0.1" ); map.put( "comp2.option", "ciao!" ); map.put( "not.a.valid.variable", "yeah" ); map.put( null, "null" ); map.put( "", "hop" ); imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", map ); Assert.assertEquals( instancePath, imp.getInstancePath()); Assert.assertEquals( 2, imp.getExportedVars().size()); Assert.assertEquals( "comp", imp.getComponentName()); Assert.assertEquals( "127.0.0.1", imp.getExportedVars().get( "comp1.ip" )); Assert.assertEquals( "ciao!", imp.getExportedVars().get( "comp2.option" )); }
@Test public void testBuildTailoredImport_withWildcard() { String instancePath = "/whatever/this/is/a-test"; Component comp = new Component( "comp" ); comp.addImportedVariable( new ImportedVariable( "comp1.*", false, false )); comp.addImportedVariable( new ImportedVariable( "comp2.option", true, false )); Instance inst = new Instance( "inst" ).component( comp ); // Null map Import imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", null ); Assert.assertEquals( instancePath, imp.getInstancePath()); Assert.assertEquals( 0, imp.getExportedVars().size()); // Empty map imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", new HashMap<String,String> ()); Assert.assertEquals( 0, imp.getExportedVars().size()); // Map with various variable Map<String,String> map = new HashMap<String,String> (); map.put( "comp1.ip", "127.0.0.1" ); map.put( "comp2.option", "ciao!" ); map.put( "not.a.valid.variable", "yeah" ); map.put( null, "null" ); map.put( "", "hop" ); imp = ImportHelpers.buildTailoredImport( inst, instancePath, "comp", map ); Assert.assertEquals( instancePath, imp.getInstancePath()); Assert.assertEquals( 2, imp.getExportedVars().size()); Assert.assertEquals( "comp", imp.getComponentName()); Assert.assertEquals( "127.0.0.1", imp.getExportedVars().get( "comp1.ip" )); Assert.assertEquals( "ciao!", imp.getExportedVars().get( "comp2.option" )); }