@Test public void testLoadApplication_descriptorErrorsAreResolved() throws Exception { File sourceDirectory = TestUtils.findTestFile( "/applications/mongo" ); File targetDirectory = this.folder.newFolder(); Utils.copyDirectory( sourceDirectory, targetDirectory ); File f = new File( targetDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR ); Assert.assertTrue( f.exists()); String fContent = Utils.readFileContent( f ); fContent = fContent.replaceAll( "(?i)application-version\\s*=.*", "application-version = @inval!d" ); Utils.writeStringInto( fContent, f ); ApplicationLoadResult result = RuntimeModelIo.loadApplication( targetDirectory ); Assert.assertNotNull( result ); Assert.assertNotNull( result.applicationTemplate ); Assert.assertEquals( 3, result.loadErrors.size()); Iterator<RoboconfError> it = result.loadErrors.iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, it.next().getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, it.next().getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, it.next().getErrorCode()); Assert.assertFalse( it.hasNext()); List<RoboconfError> errors = RoboconfErrorHelpers.resolveErrorsWithLocation( result ); Assert.assertEquals( 3, errors.size()); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, errors.get( 0 ).getErrorCode()); Assert.assertEquals( ParsingError.class, errors.get( 0 ).getClass()); Assert.assertEquals( f, ((ParsingError) errors.get( 0 )).getFile()); Assert.assertEquals( 3, ((ParsingError) errors.get( 0 )).getLine()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 1 ).getErrorCode()); Assert.assertEquals( ErrorCode.PROJ_NO_RESOURCE_DIRECTORY, errors.get( 2 ).getErrorCode()); }
public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, result ); } private  RuntimeModelIo(); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, 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 ); }
RuntimeModelIo { public static ApplicationLoadResult loadApplication( File projectDirectory ) { ApplicationLoadResult result = new ApplicationLoadResult(); ApplicationTemplate app = new ApplicationTemplate(); result.applicationTemplate = app; ApplicationTemplateDescriptor appDescriptor = null; File descDirectory = new File( projectDirectory, Constants.PROJECT_DIR_DESC ); DESC: if( ! descDirectory.exists()) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_NO_DESC_DIR, directory( projectDirectory )); result.loadErrors.add( error ); } else { File descriptorFile = new File( descDirectory, Constants.PROJECT_FILE_DESCRIPTOR ); if( ! descriptorFile.exists()) { result.loadErrors.add( new RoboconfError( ErrorCode.PROJ_NO_DESC_FILE )); break DESC; } try { appDescriptor = ApplicationTemplateDescriptor.load( descriptorFile ); app.setName( appDescriptor.getName()); app.setDescription( appDescriptor.getDescription()); app.setVersion( appDescriptor.getVersion()); app.setDslId( appDescriptor.getDslId()); app.setExternalExportsPrefix( appDescriptor.getExternalExportsPrefix()); app.setTags( appDescriptor.tags ); for( Map.Entry<String,String> entry : appDescriptor.externalExports.entrySet()) app.externalExports.put( entry.getKey(), app.getExternalExportsPrefix() + "." + entry.getValue()); result.objectToSource.put( appDescriptor, new SourceReference( appDescriptor, descriptorFile, 1 )); for( Map.Entry<String,Integer> entry : appDescriptor.propertyToLine.entrySet()) { result.objectToSource.put( entry.getKey(), new SourceReference( entry.getKey(), descriptorFile, entry.getValue())); } Collection<ModelError> errors = RuntimeModelValidator.validate( appDescriptor ); result.loadErrors.addAll( errors ); } catch( IOException e ) { RoboconfError error = new RoboconfError( ErrorCode.PROJ_READ_DESC_FILE, exception( e )); result.loadErrors.add( error ); } } return loadApplication( projectDirectory, appDescriptor, 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 );  }