ParsingModelIo { public static FileDefinition readConfigurationFile( File relationsFile, boolean ignoreComments ) { FileDefinitionParser parser = new FileDefinitionParser( relationsFile, ignoreComments ); return parser.read(); } private  ParsingModelIo(); static FileDefinition readConfigurationFile( File relationsFile, boolean ignoreComments ); static String writeConfigurationFile( FileDefinition relationsFile, boolean writeComments, String lineSeparator ); static void saveRelationsFile( FileDefinition relationsFile, boolean writeComments, String lineSeparator ); static void saveRelationsFileInto(
			File targetFile,
			FileDefinition relationsFile,
			boolean writeComments,
			String lineSeparator );  }
@Test public void testFileTypes() throws Exception { Map<String,Integer> fileNameToFileType = new LinkedHashMap<> (); fileNameToFileType.put( "commented-import-1.graph", FileDefinition.AGGREGATOR ); fileNameToFileType.put( "only-import-1.graph", FileDefinition.AGGREGATOR ); fileNameToFileType.put( "commented-import-3.graph", FileDefinition.AGGREGATOR ); fileNameToFileType.put( "only-component-3.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "only-component-4.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "real-lamp-all-in-one.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "real-lamp-all-in-one-flex.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "real-lamp-components.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "commented-component-2.graph", FileDefinition.GRAPH ); fileNameToFileType.put( "instance-single.instances", FileDefinition.INSTANCE ); fileNameToFileType.put( "instance-multiple.instances", FileDefinition.INSTANCE ); fileNameToFileType.put( "instance-imbricated-3.instances", FileDefinition.INSTANCE ); for( Map.Entry<String,Integer> entry : fileNameToFileType.entrySet()) { File f = TestUtils.findTestFile( PATH + "/" + entry.getKey()); FileDefinition rel = ParsingModelIo.readConfigurationFile( f, false ); Assert.assertEquals( "Invalid file type for " + entry.getKey(), entry.getValue().intValue(), rel.getFileType()); Assert.assertEquals( entry.getKey(), 0, rel.getParsingErrors().size()); } }
@Test public void testInvalidFileType() throws Exception { File f = TestUtils.findTestFile( "/configurations/invalid/mix.txt" ); FileDefinition def = ParsingModelIo.readConfigurationFile( f, true ); Assert.assertEquals( 1, def.getParsingErrors().size()); Assert.assertEquals( ErrorCode.P_INVALID_FILE_TYPE, def.getParsingErrors().iterator().next().getErrorCode()); }
@Test public void testComplexInstances() throws Exception { File f = TestUtils.findTestFile( "/configurations/valid/complex-instances.instances" ); FileDefinition def = ParsingModelIo.readConfigurationFile( f, true ); Assert.assertEquals( 0, def.getParsingErrors().size()); List<AbstractBlock> toProcess = new ArrayList<> (); toProcess.addAll( def.getBlocks()); List<BlockInstanceOf> instances = new ArrayList<> (); while( ! toProcess.isEmpty()) { AbstractBlock currentBlock = toProcess.remove( 0 ); if( currentBlock.getInstructionType() == AbstractBlock.INSTANCEOF ) { BlockInstanceOf blockInstanceOf = (BlockInstanceOf) currentBlock; instances.add( blockInstanceOf ); toProcess.addAll( blockInstanceOf.getInnerBlocks()); } } Assert.assertEquals( 8, instances.size()); }