@Test public void validateProject() throws Exception { File dir = this.folder.newFolder(); CreationBean bean = new CreationBean() .projectDescription( "some desc" ).projectName( "my-project" ) .groupId( "net.roboconf" ).projectVersion( "1.0-SNAPSHOT" ).mavenProject( false ); ProjectUtils.createProjectSkeleton( dir, bean ); ProjectValidationResult result = ProjectValidator.validateProject( dir ); Assert.assertNotNull( result.getRawParsingResult()); List<RoboconfError> errors = result.getErrors(); Assert.assertEquals( 2, errors.size()); for( RoboconfError roboconfError : errors ) Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, roboconfError.getErrorCode()); File invalidGraphFile = new File( dir, Constants.PROJECT_DIR_GRAPH + "/invalid" + Constants.FILE_EXT_GRAPH ); Utils.writeStringInto( "comp {\n\tinst: script;\n}\n", invalidGraphFile ); File invalidInstanceFile = new File( dir, Constants.PROJECT_DIR_INSTANCES + "/invalid" + Constants.FILE_EXT_INSTANCES ); Utils.writeStringInto( "instance of inexisting {\n\tname: toto;\n}\n", invalidInstanceFile ); errors = ProjectValidator.validateProject( dir ).getErrors(); Assert.assertEquals( 6, errors.size()); Assert.assertEquals( ErrorCode.PM_PROPERTY_NOT_APPLIABLE, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.CO_INEXISTING_COMPONENT, errors.get( 1 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 2 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 3 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 4 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 5 ).getErrorCode()); List<File> unreachableFiles = new ArrayList<> (); unreachableFiles.add(((ParsingError) errors.get( 4 )).getFile()); unreachableFiles.add(((ParsingError) errors.get( 5 )).getFile()); Assert.assertTrue( unreachableFiles.contains( invalidInstanceFile )); Assert.assertTrue( unreachableFiles.contains( invalidGraphFile )); errors = new ArrayList<>( RuntimeModelIo.loadApplication( dir ).getLoadErrors()); Assert.assertEquals( 4, errors.size()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 1 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 2 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_UNREACHABLE_FILE, errors.get( 3 ).getErrorCode()); }
public static ProjectValidationResult validateProject( File appDirectory ) { File instancesDir = new File( appDirectory, Constants.PROJECT_DIR_INSTANCES ); boolean isRecipe = ! new File( appDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ).exists() && (! instancesDir.isDirectory() || Utils.listAllFiles( instancesDir ).isEmpty()); return validateProject( appDirectory, isRecipe ); }
ProjectValidator { public static ProjectValidationResult validateProject( File appDirectory ) { File instancesDir = new File( appDirectory, Constants.PROJECT_DIR_INSTANCES ); boolean isRecipe = ! new File( appDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ).exists() && (! instancesDir.isDirectory() || Utils.listAllFiles( instancesDir ).isEmpty()); return validateProject( appDirectory, isRecipe ); } }
ProjectValidator { public static ProjectValidationResult validateProject( File appDirectory ) { File instancesDir = new File( appDirectory, Constants.PROJECT_DIR_INSTANCES ); boolean isRecipe = ! new File( appDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ).exists() && (! instancesDir.isDirectory() || Utils.listAllFiles( instancesDir ).isEmpty()); return validateProject( appDirectory, isRecipe ); } private  ProjectValidator(); }
ProjectValidator { public static ProjectValidationResult validateProject( File appDirectory ) { File instancesDir = new File( appDirectory, Constants.PROJECT_DIR_INSTANCES ); boolean isRecipe = ! new File( appDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ).exists() && (! instancesDir.isDirectory() || Utils.listAllFiles( instancesDir ).isEmpty()); return validateProject( appDirectory, isRecipe ); } private  ProjectValidator(); static ProjectValidationResult validateProject( File appDirectory ); static ProjectValidationResult validateProject( File appDirectory, boolean isRecipe ); }
ProjectValidator { public static ProjectValidationResult validateProject( File appDirectory ) { File instancesDir = new File( appDirectory, Constants.PROJECT_DIR_INSTANCES ); boolean isRecipe = ! new File( appDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ).exists() && (! instancesDir.isDirectory() || Utils.listAllFiles( instancesDir ).isEmpty()); return validateProject( appDirectory, isRecipe ); } private  ProjectValidator(); static ProjectValidationResult validateProject( File appDirectory ); static ProjectValidationResult validateProject( File appDirectory, boolean isRecipe );  }