@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()); }
public static Collection<ParsingError> validate( FileDefinition definitionFile ) { Collection<ParsingError> result = new ArrayList<> (); result.addAll( definitionFile.getParsingErrors()); for( AbstractBlock block : definitionFile.getBlocks()) result.addAll( validate( block )); return result; }
ParsingModelValidator { public static Collection<ParsingError> validate( FileDefinition definitionFile ) { Collection<ParsingError> result = new ArrayList<> (); result.addAll( definitionFile.getParsingErrors()); for( AbstractBlock block : definitionFile.getBlocks()) result.addAll( validate( block )); return result; } }
ParsingModelValidator { public static Collection<ParsingError> validate( FileDefinition definitionFile ) { Collection<ParsingError> result = new ArrayList<> (); result.addAll( definitionFile.getParsingErrors()); for( AbstractBlock block : definitionFile.getBlocks()) result.addAll( validate( block )); return result; } private  ParsingModelValidator(); }
ParsingModelValidator { public static Collection<ParsingError> validate( FileDefinition definitionFile ) { Collection<ParsingError> result = new ArrayList<> (); result.addAll( definitionFile.getParsingErrors()); for( AbstractBlock block : definitionFile.getBlocks()) result.addAll( validate( block )); return result; } private  ParsingModelValidator(); static Collection<ParsingError> validate( FileDefinition definitionFile ); static Collection<ParsingError> validate( AbstractBlock block ); static Collection<ParsingError> validate( BlockImport block ); static Collection<ParsingError> validate( BlockComponent block ); static Collection<ParsingError> validate( BlockInstanceOf block ); static Collection<ParsingError> validate( BlockFacet block ); static Collection<ParsingError> validate( BlockProperty block ); static Collection<ParsingError> validate( BlockComment block ); static Collection<ParsingError> validate( BlockBlank block ); }
ParsingModelValidator { public static Collection<ParsingError> validate( FileDefinition definitionFile ) { Collection<ParsingError> result = new ArrayList<> (); result.addAll( definitionFile.getParsingErrors()); for( AbstractBlock block : definitionFile.getBlocks()) result.addAll( validate( block )); return result; } private  ParsingModelValidator(); static Collection<ParsingError> validate( FileDefinition definitionFile ); static Collection<ParsingError> validate( AbstractBlock block ); static Collection<ParsingError> validate( BlockImport block ); static Collection<ParsingError> validate( BlockComponent block ); static Collection<ParsingError> validate( BlockInstanceOf block ); static Collection<ParsingError> validate( BlockFacet block ); static Collection<ParsingError> validate( BlockProperty block ); static Collection<ParsingError> validate( BlockComment block ); static Collection<ParsingError> validate( BlockBlank block );  }