@Test
public void testInstanceOf() {

	FileDefinition file = new FileDefinition( new File( "some-file" ));
	BlockInstanceOf block = new BlockInstanceOf( file );
	block.setName( "component" );
	Collection<ParsingError> errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_MISSING_INSTANCE_NAME, errors.iterator().next().getErrorCode());
	block.getInnerBlocks().add( new BlockProperty( file, ParsingConstants.PROPERTY_INSTANCE_NAME, "Any name" ));
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 0, errors.size());
	block.getInnerBlocks().clear();
	block.getInnerBlocks().add( new BlockProperty( file, ParsingConstants.PROPERTY_INSTANCE_NAME, "Any name?" ));
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_INVALID_INSTANCE_NAME, errors.iterator().next().getErrorCode());
	block.getInnerBlocks().clear();
	block.getInnerBlocks().add( new BlockProperty( file, ParsingConstants.PROPERTY_INSTANCE_NAME, "AnyName" ));
	Assert.assertEquals( 0, ParsingModelValidator.validate( block ).size());
	block.setName( "_component" );
	Assert.assertEquals( 0, ParsingModelValidator.validate( block ).size());
	block.setName( "component#" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, errors.iterator().next().getErrorCode());
	block.setName( "component name" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, errors.iterator().next().getErrorCode());
	block.setName( "component n@me" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, errors.iterator().next().getErrorCode());
	block.setName( ".component" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_INVALID_NAME, errors.iterator().next().getErrorCode());
	block.setName( "component." );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_DOT_IS_NOT_ALLOWED, errors.iterator().next().getErrorCode());
	block.setName( "component.name" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_DOT_IS_NOT_ALLOWED, errors.iterator().next().getErrorCode());
	block.setName( "" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_EMPTY_COMPONENT_NAME, errors.iterator().next().getErrorCode());
	block.setName( "component-name" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 0, errors.size());
	block.setName( "component_name" );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 0, errors.size());
	block.setName( "name" );
	block.getInnerBlocks().add( new BlockProperty( file, ParsingConstants.PROPERTY_GRAPH_EXTENDS, "anyPropertyToOverride" ));
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 0, errors.size());
	AbstractBlock childBlock = new BlockProperty( file, ParsingConstants.PROPERTY_GRAPH_EXTENDS, "anyPropertyToOverride" );
	block.getInnerBlocks().add( childBlock );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 1, errors.size());
	Assert.assertEquals( ErrorCode.PM_DUPLICATE_PROPERTY, errors.iterator().next().getErrorCode());
	block.getInnerBlocks().remove( childBlock );
	childBlock = new BlockProperty( file, ParsingConstants.PROPERTY_GRAPH_EXTENDS, "anyPropertyToOverride" ) {
		@Override
		public int getInstructionType() {
			return 502;
		}
	};
	block.getInnerBlocks().add( childBlock );
	errors = ParsingModelValidator.validate( block );
	Assert.assertEquals( 2, errors.size());
	Iterator<ParsingError> iterator = errors.iterator();
	Assert.assertEquals( ErrorCode.PM_INVALID_BLOCK_TYPE, iterator.next().getErrorCode());
	Assert.assertEquals( ErrorCode.PM_INVALID_INSTANCE_ELEMENT, iterator.next().getErrorCode());
}