TargetValidator { public static List<ModelError> parseTargetProperties( File projectDirectory, Component c ) { List<ModelError> errors; File dir = ResourceUtils.findInstanceResourcesDirectory( projectDirectory, c ); if( dir.isDirectory() && ! Utils.listAllFiles( dir, Constants.FILE_EXT_PROPERTIES ).isEmpty()) errors = parseDirectory( dir, c ); else errors = new ArrayList<>( 0 ); return errors; } TargetValidator( String propertiesFileContent );  TargetValidator( File propertiesFile );  TargetValidator( File propertiesFile, Object modelObject ); void validate(); List<ModelError> getErrors(); Properties getProperties(); static List<ModelError> parseDirectory( File directory ); static List<ModelError> parseDirectory( File directory, Component c ); static List<ModelError> parseTargetProperties( File projectDirectory, Component c );  }
@Test public void testParseTargetProperties_ok() throws Exception { File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" ); Utils.createDirectory( dir ); Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.properties" )); List<ModelError> errors = TargetValidator.parseTargetProperties( dir.getParentFile().getParentFile(), new Component( "c" )); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_TARGET_NO_NAME, errors.get( 0 ).getErrorCode()); }
@Test public void testParseTargetProperties_inexistingDirectory() throws Exception { List<ModelError> errors = TargetValidator.parseTargetProperties( new File( "whatever" ), new Component( "c" )); Assert.assertEquals( 0, errors.size()); }
@Test public void testParseTargetProperties_noFile() throws Exception { File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" ); Utils.createDirectory( dir ); List<ModelError> errors = TargetValidator.parseTargetProperties( dir, new Component( "c" )); Assert.assertEquals( 0, errors.size()); }
@Test public void testParseTargetProperties_noProperties() throws Exception { File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" ); Utils.createDirectory( dir ); Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.not-properties" )); List<ModelError> errors = TargetValidator.parseTargetProperties( dir, new Component( "c" )); Assert.assertEquals( 0, errors.size()); }