InstanceHelpers { public static void fixOverriddenExports( Instance instance ) { if( ! instance.overriddenExports.isEmpty()) { Map<String,String> componentExports = ComponentHelpers.findAllExportedVariables( instance.getComponent()); Iterator<Map.Entry<String,String>> iter = instance.overriddenExports.entrySet().iterator(); while( iter.hasNext()) { Map.Entry<String,String> entry = iter.next(); String value = componentExports.get( entry.getKey()); if( Objects.equals( value, entry.getValue())) iter.remove(); } } } private  InstanceHelpers(); static String computeInstancePath( Instance inst ); static boolean haveSamePath( Instance i1, Instance i2 ); static String findInstanceName( String instancePath ); static List<Instance> buildHierarchicalList( Instance inst ); static void insertChild( Instance parent, Instance child ); static Map<String,String> findAllExportedVariables( Instance instance ); static Instance findInstanceByPath( AbstractApplication application, String instancePath ); static Instance findInstanceByPath( Instance rootInstance, String instancePath ); static List<Instance> findInstancesByComponentName( AbstractApplication application, String componentName ); static Instance findRootInstance( Instance instance ); static Instance findScopedInstance( Instance instance ); static List<Instance> findAllScopedInstances( AbstractApplication app ); static List<Instance> getAllInstances( AbstractApplication application ); static boolean tryToInsertChildInstance( AbstractApplication application, Instance parentInstance, Instance childInstance ); static boolean hasChildWithThisName( AbstractApplication application, Instance parentInstance, String nameToSearch ); static File findInstanceDirectoryOnAgent( Instance instance ); static int countInstances( String instancePath ); static Instance replicateInstance( Instance instance ); static boolean isTarget( Instance instance ); static void removeOffScopeInstances( Instance scopedInstance ); static String findRootInstancePath( String scopedInstancePath ); static void fixOverriddenExports( Instance instance );  }
@Test public void testFixOverriddenExports() { Component comp = new Component("comp"); comp.addExportedVariable( new ExportedVariable( "comp.export1", "c1" )); comp.addExportedVariable( new ExportedVariable( "comp.export2", "c2" )); comp.addExportedVariable( new ExportedVariable( "comp.export3", "c3" )); Instance inst = new Instance("inst").component(comp); Assert.assertEquals( 0, inst.overriddenExports.size()); InstanceHelpers.fixOverriddenExports(inst); Assert.assertEquals( 0, inst.overriddenExports.size()); inst.overriddenExports.put( "inst.export1", "i1" ); inst.overriddenExports.put( "comp.export2", "c2" ); inst.overriddenExports.put( "comp.export3", "i3" ); InstanceHelpers.fixOverriddenExports(inst); Assert.assertEquals( 3, comp.exportedVariables.size()); Assert.assertEquals( "c1", comp.exportedVariables.get("comp.export1").getValue()); Assert.assertEquals( "c2", comp.exportedVariables.get("comp.export2").getValue()); Assert.assertEquals( "c3", comp.exportedVariables.get("comp.export3").getValue()); Assert.assertEquals( 2, inst.overriddenExports.size()); Assert.assertEquals( "i1", inst.overriddenExports.get("inst.export1")); Assert.assertEquals( "i3", inst.overriddenExports.get("comp.export3")); }