@Test
public void testRecognizeImport() {

	String[] validLines = {
			"import facets.rcf;",
			"IMPORT facets.rcf;",
			"import http://some-host.com/some/path/facets.rcf;",
			"import http://some-host.com/some/path/?file=facets.rcf;",
			"   import   facets.rcf ;  ",
			"import facets.rcf; # with an inline comment"
	};
	// Comments do not matter here
	for( String line : validLines ) {
		FileDefinitionParser parser = new FileDefinitionParser( null, false );
		int code = parser.recognizeImport( line );
		FileDefinition def = parser.getFileRelations();
		Assert.assertEquals( "Expected a YES code for '" + line + "'", FileDefinitionParser.P_CODE_YES, code );
		Assert.assertEquals( "No parsing error was expected for '" + line + "'", 0, def.getParsingErrors().size());
		Assert.assertEquals( "Expected ONE block to be registered for '" + line + "'", 1, def.getBlocks().size());
		BlockImport imp = (BlockImport) def.getBlocks().iterator().next();
		Assert.assertEquals( "Expected ONE import block for '" + line + "'", AbstractBlock.IMPORT, imp.getInstructionType());
		Assert.assertFalse( "URI cannot be empty for '" + line + "'", Utils.isEmptyOrWhitespaces( imp.getUri()));
		Assert.assertEquals( "URI cannot have surrounding spaces '" + line + "'", imp.getUri(), imp.getUri().trim());
		Assert.assertNotSame( "URI cannot be the entire line for '" + line + "'", imp.getUri(), line );
		Assert.assertTrue( "The URI was not found in '" + line + "'", line.contains( imp.getUri()));
	}
	// In-line comments
	String[][] commentedLines = {
			{ "import facets.rcf;", "" },
			{ "import facets.rcf;", "# stuck comment" },
			{ "import facets.rcf;", "#" },
			{ "import facets.rcf;", "\t# some in-line comment   " }
	};
	for( String[] line : commentedLines ) {
		FileDefinitionParser parser = new FileDefinitionParser( null, false );
		String theLine = line[ 0 ] + line[ 1 ];
		int code = parser.recognizeImport( theLine );
		FileDefinition def  = parser.getFileRelations();
		Assert.assertEquals( "Expected a YES code for '" + theLine + "'", FileDefinitionParser.P_CODE_YES, code );
		Assert.assertEquals( "No parsing error was expected for '" + theLine + "'", 0, def.getParsingErrors().size());
		Assert.assertEquals( "Expected ONE block to be registered for '" + theLine + "'", 1, def.getBlocks().size());
		BlockImport imp = (BlockImport) def.getBlocks().iterator().next();
		Assert.assertEquals( "Expected ONE import block for '" + theLine + "'", AbstractBlock.IMPORT, imp.getInstructionType());
		String expected = Utils.isEmptyOrWhitespaces( line[ 1 ]) ? null : line[ 1 ];
		Assert.assertEquals( "Invalid in-line comment for '" + theLine + "'", expected, imp.getInlineComment());
	}
	// Invalid lines
	String[] invalidLines = {
			"imports facets.rcf;",
			"IPORT facets.rcf;",
			"facet",
			"",
			" #"
	};
	for( String line : invalidLines ) {
		FileDefinitionParser parser = new FileDefinitionParser( null, false );
		int code = parser.recognizeImport( line );
		Assert.assertEquals( "Expected a NO code for '" + line + "'", FileDefinitionParser.P_CODE_NO, code );
	}
	// Test error codes
	Map<String,ErrorCode> invalidLineToErrorCode = new LinkedHashMap<> ();
	invalidLineToErrorCode.put( "import facets.rcf", ErrorCode.P_IMPORT_ENDS_WITH_SEMI_COLON );
	invalidLineToErrorCode.put( "import facets.rcf ; facet toto {", ErrorCode.P_ONE_BLOCK_PER_LINE );
	invalidLineToErrorCode.put( "import facets.rcf ; invalid comment", ErrorCode.P_ONE_BLOCK_PER_LINE );
	invalidLineToErrorCode.put( "import facets.rcf ;;", ErrorCode.P_ONE_BLOCK_PER_LINE );
	for( Map.Entry<String,ErrorCode> entry : invalidLineToErrorCode.entrySet()) {
		String line = entry.getKey();
		FileDefinitionParser parser = new FileDefinitionParser( null, false );
		int code = parser.recognizeImport( entry.getKey());
		FileDefinition def = parser.getFileRelations();
		Assert.assertEquals( "Expected a YES code for '" + line + "'", FileDefinitionParser.P_CODE_YES, code );
		Assert.assertEquals( "A parsing error was expected for '" + line + "'", 1, def.getParsingErrors().size());
		Assert.assertEquals( "Expected ONE block to be registered for '" + line + "'", 1, def.getBlocks().size());
		Assert.assertEquals( "Expected ONE import block for '" + line + "'",
				AbstractBlock.IMPORT,
				def.getBlocks().iterator().next().getInstructionType());
		ParsingError error = def.getParsingErrors().iterator().next();
		Assert.assertEquals( "Expecting parsing error for '" + line + "'", entry.getValue().getCategory(), ErrorCategory.PARSING );
		Assert.assertEquals( "Invalid error code for '" + line + "'", entry.getValue(), error.getErrorCode());
	}
}