@Test
public void testLoadApplication_Lamp_Legacy_1() throws Exception {

	File directory = TestUtils.findTestFile( "/applications/lamp-legacy-with-only-components" );
	ApplicationLoadResult result = RuntimeModelIo.loadApplication( directory );
	Assert.assertNotNull( result );
	Assert.assertNotNull( result.applicationTemplate );
	Assert.assertEquals( 4, result.loadErrors.size());
	for( RoboconfError error : result.loadErrors )
		Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, error.getErrorCode());
	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());
	List<String> tags = Arrays.asList( "test", "lamp", "example" );
	Assert.assertEquals( new TreeSet<>( tags ), result.applicationTemplate.getTags());
	Assert.assertNotNull( result.applicationTemplate.getGraphs());
	Graphs g = result.applicationTemplate.getGraphs();
	Assert.assertEquals( 1, g.getRootComponents().size());
	Component vmComponent = g.getRootComponents().iterator().next();
	Assert.assertEquals( "VM", vmComponent.getName());
	Assert.assertEquals( "target", vmComponent.getInstallerName());
	Assert.assertEquals( 3, vmComponent.getChildren().size());
	for( Component childComponent : ComponentHelpers.findAllChildren( vmComponent )) {
		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( 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());
			SourceReference sr = result.getObjectToSource().get( childComponent );
			Assert.assertNotNull( sr );
			Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile());
			Assert.assertEquals( 22, sr.getLine());
		} else if( "MySQL".equals( childComponent.getName())) {
			Assert.assertEquals( "puppet", childComponent.getInstallerName());
			Assert.assertEquals( 0, children.size());
			Assert.assertEquals( 2, exportedVariables.size());
			Assert.assertTrue( exportedVariables.containsKey( "MySQL.ip" ));
			Assert.assertNull( exportedVariables.get( "MySQL.port" ));
			Assert.assertEquals( 0, importedVariables.size());
			SourceReference sr = result.getObjectToSource().get( childComponent );
			Assert.assertNotNull( sr );
			Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile());
			Assert.assertEquals( 16, sr.getLine());
		} else if( "Apache".equals( childComponent.getName())) {
			Assert.assertEquals( "puppet", childComponent.getInstallerName());
			Assert.assertEquals( 0, children.size());
			Assert.assertEquals( 0, exportedVariables.size());
			Assert.assertEquals( 2, childComponent.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());
			SourceReference sr = result.getObjectToSource().get( childComponent );
			Assert.assertNotNull( sr );
			Assert.assertEquals( new File( directory, "graph/lamp.graph" ), sr.getSourceFile());
			Assert.assertEquals( 30, sr.getLine());
		} else {
			Assert.fail( "Unrecognized child." );
		}
	}
	// Instances
	Assert.assertEquals( 3, result.applicationTemplate.getRootInstances().size());
	for( Instance i : result.applicationTemplate.getRootInstances()) {
		if( "Apache VM".equals( i.getName())) {
			Assert.assertEquals( "VM", i.getComponent().getName());
			Assert.assertEquals( 1, i.getChildren().size());
			Instance child = i.getChildren().iterator().next();
			Assert.assertEquals( 0, child.getChildren().size());
			Assert.assertEquals( i, child.getParent());
			Assert.assertEquals( "Apache", child.getName());
			Assert.assertEquals( "Apache", child.getComponent().getName());
		} else if( "MySQL VM".equals( i.getName())) {
			Assert.assertEquals( "VM", i.getComponent().getName());
			Assert.assertEquals( 1, i.getChildren().size());
			Instance child = i.getChildren().iterator().next();
			Assert.assertEquals( 0, child.getChildren().size());
			Assert.assertEquals( i, child.getParent());
			Assert.assertEquals( "MySQL", child.getName());
			Assert.assertEquals( "MySQL", child.getComponent().getName());
			Map<String,String> exportedVariables = InstanceHelpers.findAllExportedVariables( child );
			Assert.assertEquals( "3306", exportedVariables.get( "MySQL.port" ));
			Assert.assertNull( child.getComponent().exportedVariables.get( "MySQL.port" ));
			Assert.assertNotNull( child.getComponent().exportedVariables.get( "port" ));
			Assert.assertNull( child.getComponent().exportedVariables.get( "port" ).getValue());
		} else if( "Tomcat VM 1".equals( i.getName())) {
			Assert.assertEquals( "VM", i.getComponent().getName());
			Assert.assertEquals( 1, i.getChildren().size());
			Instance child = i.getChildren().iterator().next();
			Assert.assertEquals( 0, child.getChildren().size());
			Assert.assertEquals( i, child.getParent());
			Assert.assertEquals( "Tomcat", child.getName());
			Assert.assertEquals( "Tomcat", child.getComponent().getName());
		} else {
			Assert.fail( "Unrecognized instance." );
		}
	}
}