@Test
public void testLoadApplication_Lamp_Legacy_2() throws Exception {

	File directory = TestUtils.findTestFile( "/applications/lamp-legacy-with-facets-and-so-on" );
	ApplicationLoadResult result = RuntimeModelIo.loadApplication( directory );
	Assert.assertNotNull( result );
	Assert.assertNotNull( result.applicationTemplate );
	Assert.assertEquals( 3, result.loadErrors.size());
	for( RoboconfError error : result.loadErrors )
		Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, error.getErrorCode());
	// Test the graph and descriptor
	Assert.assertEquals( "Legacy LAMP", result.applicationTemplate.getName());
	Assert.assertEquals( "A sample LAMP application", result.applicationTemplate.getDescription());
	Assert.assertEquals( "1.0.1-SNAPSHOT", result.applicationTemplate.getVersion());
	Assert.assertEquals( "roboconf-1.0", result.applicationTemplate.getDslId());
	Assert.assertNotNull( result.applicationTemplate.getGraphs());
	Graphs g = result.applicationTemplate.getGraphs();
	Assert.assertEquals( 3, g.getRootComponents().size());
	Set<String> rootComponentNames = new HashSet<> ();
	for( Component c : g.getRootComponents()) {
		rootComponentNames.add( c.getName());
		Assert.assertEquals( Constants.TARGET_INSTALLER, ComponentHelpers.findComponentInstaller( c ));
		Collection<Facet> facets = ComponentHelpers.findAllFacets( c );
		Assert.assertEquals( 1, facets.size());
		Assert.assertEquals( "Virtual_Machine", facets.iterator().next().getName());
		Assert.assertEquals( 3, ComponentHelpers.findAllChildren( c ).size());
		for( Component childComponent : ComponentHelpers.findAllChildren( c )) {
			Map<String,String> exportedVariables = ComponentHelpers.findAllExportedVariables( childComponent );
			Map<String,ImportedVariable> importedVariables = ComponentHelpers.findAllImportedVariables( childComponent );
			Collection<Component> children = ComponentHelpers.findAllChildren( childComponent );
			if( "Tomcat".equals( childComponent.getName())) {
				Assert.assertEquals( "puppet", childComponent.getInstallerName());
				Assert.assertEquals( 0, children.size());
				Assert.assertEquals( 1, childComponent.getFacets().size());
				Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName());
				Assert.assertEquals( 2, exportedVariables.size());
				Assert.assertTrue( exportedVariables.containsKey( "Tomcat.ip" ));
				Assert.assertEquals( "8009", exportedVariables.get( "Tomcat.portAJP" ));
				Assert.assertEquals( 2, importedVariables.size());
				Assert.assertFalse( importedVariables.get( "MySQL.ip" ).isOptional());
				Assert.assertFalse( importedVariables.get( "MySQL.ip" ).isExternal());
				Assert.assertFalse( importedVariables.get( "MySQL.port" ).isOptional());
				Assert.assertFalse( importedVariables.get( "MySQL.port" ).isExternal());
			} else if( "MySQL".equals( childComponent.getName())) {
				Assert.assertEquals( "puppet", childComponent.getInstallerName());
				Assert.assertEquals( 0, children.size());
				Assert.assertEquals( 1, childComponent.getFacets().size());
				Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName());
				Assert.assertEquals( 2, exportedVariables.size());
				Assert.assertTrue( exportedVariables.containsKey( "MySQL.ip" ));
				Assert.assertEquals( "3306", exportedVariables.get( "MySQL.port" ));
				Assert.assertEquals( 0, importedVariables.size());
			} else if( "Apache".equals( childComponent.getName())) {
				Assert.assertEquals( "puppet", childComponent.getInstallerName());
				Assert.assertEquals( 0, children.size());
				Assert.assertEquals( 0, exportedVariables.size());
				Assert.assertEquals( 1, childComponent.getFacets().size());
				Assert.assertEquals( "deployable", childComponent.getFacets().iterator().next().getName());
				Assert.assertEquals( 2, importedVariables.size());
				Assert.assertFalse( importedVariables.get( "Tomcat.ip" ).isOptional());
				Assert.assertFalse( importedVariables.get( "Tomcat.ip" ).isExternal());
				Assert.assertFalse( importedVariables.get( "Tomcat.portAJP" ).isOptional());
				Assert.assertFalse( importedVariables.get( "Tomcat.portAJP" ).isExternal());
			} else {
				Assert.fail( "Unrecognized child." );
			}
		}
	}
	// Check we got everything in the graph
	Assert.assertEquals( 3, rootComponentNames.size());
	Assert.assertTrue( rootComponentNames.contains( "VM" ));
	Assert.assertTrue( rootComponentNames.contains( "VM_EC2" ));
	Assert.assertTrue( rootComponentNames.contains( "VM_Openstack" ));
	Component vmOpenstack = ComponentHelpers.findComponent( g, "VM_Openstack" );
	Map<String,String> exportedVariables = ComponentHelpers.findAllExportedVariables( vmOpenstack );
	Assert.assertEquals( 4, exportedVariables.size());
	Assert.assertEquals( "else", exportedVariables.get( "VM_Openstack.something" ));
	Assert.assertNull( exportedVariables.get( "Virtual_Machine.ip" ));
	Assert.assertTrue( exportedVariables.containsKey( "Virtual_Machine.ip" ));
	Assert.assertTrue( exportedVariables.containsKey( "VM_Openstack.ip" ));
	Assert.assertTrue( exportedVariables.containsKey( "VM.ip" ));
	Assert.assertEquals( ComponentHelpers.findComponent( g, "VM" ), vmOpenstack.getExtendedComponent());
	Assert.assertNotNull( vmOpenstack.getExtendedComponent());
	// Test the instances
	Set<String> expectedPaths = new HashSet<> ();
	expectedPaths.add( "/Apache VM" );
	expectedPaths.add( "/Apache VM/Apache" );
	expectedPaths.add( "/MySQL VM" );
	expectedPaths.add( "/MySQL VM/MySQL" );
	expectedPaths.add( "/Tomcat VM 1" );
	expectedPaths.add( "/Tomcat VM 1/Tomcat" );
	expectedPaths.add( "/Tomcat VM 2" );
	expectedPaths.add( "/Tomcat VM 2/Tomcat" );
	expectedPaths.add( "/Tomcat VM 3" );
	expectedPaths.add( "/Tomcat VM 3/Tomcat" );
	Set<String> realPaths = new HashSet<> ();
	for( Instance inst : InstanceHelpers.getAllInstances( result.getApplicationTemplate()))
		realPaths.add( InstanceHelpers.computeInstancePath( inst ));
	Assert.assertEquals( expectedPaths.size(), realPaths.size());
	realPaths.removeAll( expectedPaths );
	Assert.assertEquals( 0, realPaths.size());
	Instance tomcat1 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 1/Tomcat" );
	Instance tomcat2 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 2/Tomcat" );
	Instance tomcat3 = InstanceHelpers.findInstanceByPath( result.getApplicationTemplate(), "/Tomcat VM 3/Tomcat" );
	Assert.assertEquals( tomcat1.getComponent(), tomcat2.getComponent());
	Assert.assertEquals( tomcat1.getComponent(), tomcat3.getComponent());
	Assert.assertEquals( tomcat1.channels, tomcat2.channels );
	Assert.assertEquals( tomcat1.channels, tomcat3.channels );
	Assert.assertEquals( 0, tomcat1.getChildren().size());
	Assert.assertEquals( 1, tomcat1.overriddenExports.size());
	Assert.assertEquals( "9021", tomcat1.overriddenExports.get( "portAJP" ));
	Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat1 ).get( "Tomcat.portAJP" ));
	Assert.assertEquals( 0, tomcat2.getChildren().size());
	Assert.assertEquals( 1, tomcat2.overriddenExports.size());
	Assert.assertEquals( "9021", tomcat2.overriddenExports.get( "portAJP" ));
	Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat2 ).get( "Tomcat.portAJP" ));
	Assert.assertEquals( 0, tomcat3.getChildren().size());
	Assert.assertEquals( 1, tomcat3.overriddenExports.size());
	Assert.assertEquals( "9021", tomcat3.overriddenExports.get( "portAJP" ));
	Assert.assertEquals( "9021", InstanceHelpers.findAllExportedVariables( tomcat3 ).get( "Tomcat.portAJP" ));
}