@Test
public void testLoadApplicationErrors() throws Exception {

	File tempDirectory = this.folder.newFolder();
	// Descriptor
	Iterator<RoboconfError> iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_DESC_DIR, iterator.next().getErrorCode());
	File appDir = new File( tempDirectory, Constants.PROJECT_DIR_DESC );
	if( ! appDir.mkdir())
		throw new IOException( "Failed to create the descriptor directory." );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_DESC_FILE, iterator.next().getErrorCode());
	Properties props = new Properties();
	props.setProperty( ApplicationTemplateDescriptor.APPLICATION_NAME, "app-name" );
	props.setProperty( ApplicationTemplateDescriptor.APPLICATION_VERSION, "1.0" );
	props.setProperty( ApplicationTemplateDescriptor.APPLICATION_DSL_ID, "roboconf-1.0" );
	props.setProperty( ApplicationTemplateDescriptor.APPLICATION_GRAPH_EP, "main.graph" );
	Utils.writePropertiesFile( props, new File( appDir, Constants.PROJECT_FILE_DESCRIPTOR ));
	// Graph
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_GRAPH_DIR, iterator.next().getErrorCode());
	File graphDir = new File( tempDirectory, Constants.PROJECT_DIR_GRAPH );
	if( ! graphDir.mkdir())
		throw new IOException( "Failed to create the graph directory." );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_MISSING_GRAPH_EP, iterator.next().getErrorCode());
	File graphFile = new File( graphDir, "main.graph" );
	if( ! graphFile.createNewFile())
		throw new IOException( "Faild to create a graph file." );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.P_EMPTY_FILE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_NO_ROOT_COMPONENT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "   \n  \t\n\n ", graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.P_EMPTY_FILE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_NO_ROOT_COMPONENT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "[ not supported by our parser ]", graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.P_UNRECOGNIZED_BLOCK, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_A_GRAPH, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "  \n\n [ not supported by our parser ] \n\n ", graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.P_UNRECOGNIZED_BLOCK, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_A_GRAPH, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "comp", graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.P_O_C_BRACKET_MISSING, iterator.next().getErrorCode());
	String fileContent = "my Toto {\n\tname: toto;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, iterator.next().getErrorCode());
	fileContent = "instanceof Toto {\n\tname: toto;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, iterator.next().getErrorCode());
	fileContent = "instance of Toto {\n\tname: toto;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), graphFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.CO_NOT_A_GRAPH, iterator.next().getErrorCode());
	fileContent = "facet MyFacet {\n}\n\nA {\n\tinstaller: target;\n\tfacets: MyFacet;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), graphFile );
	// Instances
	Collection<RoboconfError> errors = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors;
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.iterator().next().getErrorCode());
	props.setProperty( ApplicationTemplateDescriptor.APPLICATION_INSTANCES_EP, "init.instances" );
	Utils.writePropertiesFile( props, new File( appDir, Constants.PROJECT_FILE_DESCRIPTOR ));
	File instDir = new File( tempDirectory, Constants.PROJECT_DIR_INSTANCES );
	if( ! instDir.mkdir())
		throw new IOException( "Failed to create the instances directory." );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PROJ_MISSING_INSTANCE_EP, iterator.next().getErrorCode());
	File instancesFile = new File( instDir, "init.instances" );
	if( ! instancesFile.createNewFile())
		throw new IOException( "Failed to create " + instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.P_EMPTY_FILE, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "   \n  \t\n\n ", instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.P_EMPTY_FILE, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "[ not supported by our parser ]", instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.P_UNRECOGNIZED_BLOCK, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_INSTANCES, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "  \n\n [ not supported by our parser ] \n\n ", instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.P_UNRECOGNIZED_BLOCK, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_INSTANCES, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Utils.writeStringInto( "  \n\n ip \n\n ", instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.P_O_C_BRACKET_MISSING, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_INSTANCES, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	fileContent = "facet MyFacet {\n}\n\nA {\n\tinstaller: script;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), instancesFile );
	iterator = RuntimeModelIo.loadApplication( tempDirectory ).loadErrors.iterator();
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.CO_NOT_INSTANCES, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	fileContent = "instance of A {\n\tname: toto;\n}";
	Utils.copyStream( new ByteArrayInputStream( fileContent.getBytes( "UTF-8" )), instancesFile );
	errors =  RuntimeModelIo.loadApplication( tempDirectory ).loadErrors;
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.iterator().next().getErrorCode());
}