RuntimeModelIo { public static ApplicationLoadResult loadApplicationFlexibly( File projectDirectory ) { File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); ApplicationLoadResult result; if( descDirectory.exists()) { result = loadApplication( projectDirectory ); } else { ApplicationTemplateDescriptor appDescriptor = new ApplicationTemplateDescriptor(); appDescriptor.setName( Constants.GENERATED ); appDescriptor.setDslId( Constants.GENERATED ); appDescriptor.setVersion( Constants.GENERATED ); ApplicationLoadResult alr = new ApplicationLoadResult(); alr.applicationTemplate = new ApplicationTemplate( Constants.GENERATED ).dslId( Constants.GENERATED ).version( Constants.GENERATED ); File graphDirectory = new File( projectDirectory, Constants.PROJECT_DIR_GRAPH ); File[] graphFiles = graphDirectory.listFiles( new GraphFileFilter()); if( graphFiles != null && graphFiles.length > 0 ) appDescriptor.setGraphEntryPoint( graphFiles[ 0 ].getName()); result = loadApplication( projectDirectory, appDescriptor, alr ); } return result; } private  RuntimeModelIo(); static ApplicationLoadResult loadApplication( File projectDirectory ); static ApplicationLoadResult loadApplicationFlexibly( File projectDirectory ); static Graphs loadGraph( File graphFile, File graphDirectory, ApplicationLoadResult alr ); static InstancesLoadResult loadInstances( File instancesFile, File rootDirectory, Graphs graph, String applicationName ); static void writeInstances( File targetFile, Collection<Instance> rootInstances );  }
@Test public void testApplicationWithMissingGraph() throws Exception { File dir = this.folder.newFolder(); Assert.assertTrue( new File( dir, Constants.PROJECT_DIR_DESC ).mkdir()); Assert.assertTrue( new File( dir, Constants.PROJECT_DIR_GRAPH ).mkdir()); Assert.assertTrue( new File( dir, Constants.PROJECT_DIR_INSTANCES ).mkdir()); Assert.assertTrue( new File( dir, Constants.PROJECT_DIR_INSTANCES + "/model.instances" ).createNewFile()); ApplicationTemplateDescriptor desc = new ApplicationTemplateDescriptor(); desc.setName( "app name" ); desc.setVersion( "3.0" ); desc.setInstanceEntryPoint( "model.instances" ); desc.setDslId( "roboconf-1.0" ); ApplicationTemplateDescriptor.save( new File( dir, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ), desc ); Iterator<RoboconfError> it = RuntimeModelIo.loadApplicationFlexibly( dir ).loadErrors.iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, it.next().getErrorCode()); Assert.assertEquals( ErrorCode.CO_GRAPH_COULD_NOT_BE_BUILT, it.next().getErrorCode()); }
@Test public void testParsingWithInvalidRecipeProject_1() throws Exception { File dir = TestUtils.findTestFile( "/reusable.recipe.with.errors.1" ); Assert.assertTrue( dir.exists()); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( dir ); RoboconfErrorHelpers.filterErrorsForRecipes( alr ); Assert.assertEquals( 1, alr.getLoadErrors().size()); Assert.assertEquals( ErrorCode.RM_UNRESOLVABLE_VARIABLE, alr.getLoadErrors().iterator().next().getErrorCode()); RoboconfError error = alr.getLoadErrors().iterator().next(); Assert.assertEquals( 1, error.getDetails().length ); Assert.assertEquals( ErrorDetailsKind.VARIABLE, error.getDetails()[ 0 ].getErrorDetailsKind()); Assert.assertTrue( error.getDetails()[ 0 ].getElementName().contains( "f.*" )); }
@Test public void testParsingWithInvalidRecipeProject_2() throws Exception { File dir = TestUtils.findTestFile( "/reusable.recipe.with.errors.2" ); Assert.assertTrue( dir.exists()); ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( dir ); RoboconfErrorHelpers.filterErrorsForRecipes( alr ); List<RoboconfError> errors = new ArrayList<>( alr.getLoadErrors()); Assert.assertEquals( 2, errors.size()); Assert.assertEquals( ErrorCode.RM_COMPONENT_IMPORTS_EXPORTS, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 1 ).getErrorCode()); }