@Test
public void testApplication() {

	ApplicationTemplate app = new ApplicationTemplate();
	Iterator<ModelError> iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_NAME, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setName( "My Application #!" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_NAME, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setName( "My Application (test)" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setName( "My Application" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setVersion( "Snapshot Build #2401" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setVersion( "3.2.4" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GRAPHS, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setGraphs( new Graphs());
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_NO_ROOT_COMPONENT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	Component comp = new Component( "root" ).installerName( Constants.TARGET_INSTALLER );
	app.getGraphs().getRootComponents().add( comp );
	Assert.assertEquals( 0, RuntimeModelValidator.validate( app ).size());
	app.externalExports.put( "comp.!nvalid", "ko" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_INVALID_VARIABLE_NAME, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_INVALID_EXTERNAL_EXPORT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.externalExports.remove( "comp.!nvalid" );
	app.externalExports.put( "comp.valid", "!invalid" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_INVALID_EXTERNAL_EXPORT, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_INVALID_VARIABLE_NAME, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.externalExports.put( "comp.valid", "ok" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.RM_INVALID_EXTERNAL_EXPORT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.externalExports.remove( "comp.valid" );
	comp.addExportedVariable( new ExportedVariable( "test", "default" ));
	app.externalExports.put( "root.test", "alias" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setExternalExportsPrefix( "inval!d prefix" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
	app.setExternalExportsPrefix( "prefix" );
	Assert.assertEquals( 0, RuntimeModelValidator.validate( app ).size());
	comp.addExportedVariable( new ExportedVariable( "test-bis", "default" ));
	app.externalExports.put( "root.test-bis", "alias" );
	iterator = RuntimeModelValidator.validate( app ).iterator();
	Assert.assertEquals( ErrorCode.RM_ALREADY_DEFINED_EXTERNAL_EXPORT, iterator.next().getErrorCode());
	Assert.assertFalse( iterator.hasNext());
}