@Test public void testApplicationDescriptor() { ApplicationTemplateDescriptor desc = new ApplicationTemplateDescriptor(); Iterator<ModelError> iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_NAME, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_DSL_ID, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setName( "My Application #!" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_NAME, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_DSL_ID, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setName( "My Àppliçation" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_DSL_ID, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setName( "My Application" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_VERSION, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_DSL_ID, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setVersion( "Snapshot Build #2401" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_APPLICATION_VERSION, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_DSL_ID, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setDslId( "roboconf-1.0" ); desc.setVersion( "1.4" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_GEP, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setGraphEntryPoint( "graph.graph" ); Assert.assertEquals( 0, RuntimeModelValidator.validate( desc ).size()); desc.invalidExternalExports.add( "oops" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.PROJ_INVALID_EXTERNAL_EXPORTS, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.invalidExternalExports.clear(); desc.externalExports.put( "comp.valid", "ok" ); desc.externalExports.put( "comp.!nvalid", "ko" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_VARIABLE_NAME, iterator.next().getErrorCode()); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.externalExports.remove( "comp.!nvalid" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_MISSING_APPLICATION_EXPORT_PREFIX, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); desc.setExternalExportsPrefix( "prefix" ); Assert.assertEquals( 0, RuntimeModelValidator.validate( desc ).size()); desc.externalExports.put( "comp.valid", "!nvalid" ); iterator = RuntimeModelValidator.validate( desc ).iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_VARIABLE_NAME, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); }
public static Collection<ModelError> validate( Component component ) { Collection<ModelError> errors = new ArrayList<> (); if( Utils.isEmptyOrWhitespaces( component.getName())) errors.add( new ModelError( RM_EMPTY_COMPONENT_NAME, component )); else if( ! component.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_NAME, component, component( component ))); else if( component.getName().contains( "." )) errors.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, component, component( component ))); String installerName = ComponentHelpers.findComponentInstaller( component ); if( Utils.isEmptyOrWhitespaces( installerName )) errors.add( new ModelError( RM_EMPTY_COMPONENT_INSTALLER, component, component( component ))); else if( ! installerName.matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_INSTALLER, component, component( component ))); else if( ComponentHelpers.findAllAncestors( component ).isEmpty() && ! Constants.TARGET_INSTALLER.equals( installerName )) errors.add( new ModelError( RM_ROOT_INSTALLER_MUST_BE_TARGET, component, component( component ))); for( ExportedVariable exportedVariable : component.exportedVariables.values()) { String exportedVarName = exportedVariable.getName(); if( Utils.isEmptyOrWhitespaces( exportedVarName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( exportedVarName ))); else if( ! exportedVarName.matches( ParsingConstants.PATTERN_ID )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( exportedVarName ))); if( exportedVariable.isRandom()) { if( exportedVariable.getRandomKind() == null ) errors.add( new ModelError( RM_INVALID_RANDOM_KIND, component, unrecognized( exportedVariable.getRawKind()))); if( exportedVariable.getValue() != null ) errors.add( new ModelError( RM_NO_VALUE_FOR_RANDOM, component, variable( exportedVarName ))); } } Map<String,String> allExportedVariables = ComponentHelpers.findAllExportedVariables( component ); for( Component superType : ComponentHelpers.findAllExtendedComponents( component )) allExportedVariables.put( superType.getName() + "." + Constants.WILDCARD, null ); for( Facet superFacet : ComponentHelpers.findAllFacets( component )) allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null ); for( ImportedVariable var : ComponentHelpers.findAllImportedVariables( component ).values()) { String varName = var.getName(); String patternForImports = ParsingConstants.PATTERN_ID; patternForImports += "(\\.\\*)?"; if( Utils.isEmptyOrWhitespaces( varName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( varName ))); else if( ! varName.matches( patternForImports )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( varName ))); if( var.isOptional()) continue; if( allExportedVariables.containsKey( varName )) errors.add( new ModelError( RM_COMPONENT_IMPORTS_EXPORTS, component, variable( varName ))); } String cycle = ComponentHelpers.searchForInheritanceCycle( component ); if( cycle != null ) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS_INHERITANCE, component, cycle( cycle ))); cycle = ComponentHelpers.searchForLoop( component ); if( cycle != null && cycle.startsWith( component.getName())) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS, component, cycle( cycle ))); return errors; }
RuntimeModelValidator { public static Collection<ModelError> validate( Component component ) { Collection<ModelError> errors = new ArrayList<> (); if( Utils.isEmptyOrWhitespaces( component.getName())) errors.add( new ModelError( RM_EMPTY_COMPONENT_NAME, component )); else if( ! component.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_NAME, component, component( component ))); else if( component.getName().contains( "." )) errors.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, component, component( component ))); String installerName = ComponentHelpers.findComponentInstaller( component ); if( Utils.isEmptyOrWhitespaces( installerName )) errors.add( new ModelError( RM_EMPTY_COMPONENT_INSTALLER, component, component( component ))); else if( ! installerName.matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_INSTALLER, component, component( component ))); else if( ComponentHelpers.findAllAncestors( component ).isEmpty() && ! Constants.TARGET_INSTALLER.equals( installerName )) errors.add( new ModelError( RM_ROOT_INSTALLER_MUST_BE_TARGET, component, component( component ))); for( ExportedVariable exportedVariable : component.exportedVariables.values()) { String exportedVarName = exportedVariable.getName(); if( Utils.isEmptyOrWhitespaces( exportedVarName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( exportedVarName ))); else if( ! exportedVarName.matches( ParsingConstants.PATTERN_ID )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( exportedVarName ))); if( exportedVariable.isRandom()) { if( exportedVariable.getRandomKind() == null ) errors.add( new ModelError( RM_INVALID_RANDOM_KIND, component, unrecognized( exportedVariable.getRawKind()))); if( exportedVariable.getValue() != null ) errors.add( new ModelError( RM_NO_VALUE_FOR_RANDOM, component, variable( exportedVarName ))); } } Map<String,String> allExportedVariables = ComponentHelpers.findAllExportedVariables( component ); for( Component superType : ComponentHelpers.findAllExtendedComponents( component )) allExportedVariables.put( superType.getName() + "." + Constants.WILDCARD, null ); for( Facet superFacet : ComponentHelpers.findAllFacets( component )) allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null ); for( ImportedVariable var : ComponentHelpers.findAllImportedVariables( component ).values()) { String varName = var.getName(); String patternForImports = ParsingConstants.PATTERN_ID; patternForImports += "(\\.\\*)?"; if( Utils.isEmptyOrWhitespaces( varName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( varName ))); else if( ! varName.matches( patternForImports )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( varName ))); if( var.isOptional()) continue; if( allExportedVariables.containsKey( varName )) errors.add( new ModelError( RM_COMPONENT_IMPORTS_EXPORTS, component, variable( varName ))); } String cycle = ComponentHelpers.searchForInheritanceCycle( component ); if( cycle != null ) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS_INHERITANCE, component, cycle( cycle ))); cycle = ComponentHelpers.searchForLoop( component ); if( cycle != null && cycle.startsWith( component.getName())) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS, component, cycle( cycle ))); return errors; } }
RuntimeModelValidator { public static Collection<ModelError> validate( Component component ) { Collection<ModelError> errors = new ArrayList<> (); if( Utils.isEmptyOrWhitespaces( component.getName())) errors.add( new ModelError( RM_EMPTY_COMPONENT_NAME, component )); else if( ! component.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_NAME, component, component( component ))); else if( component.getName().contains( "." )) errors.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, component, component( component ))); String installerName = ComponentHelpers.findComponentInstaller( component ); if( Utils.isEmptyOrWhitespaces( installerName )) errors.add( new ModelError( RM_EMPTY_COMPONENT_INSTALLER, component, component( component ))); else if( ! installerName.matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_INSTALLER, component, component( component ))); else if( ComponentHelpers.findAllAncestors( component ).isEmpty() && ! Constants.TARGET_INSTALLER.equals( installerName )) errors.add( new ModelError( RM_ROOT_INSTALLER_MUST_BE_TARGET, component, component( component ))); for( ExportedVariable exportedVariable : component.exportedVariables.values()) { String exportedVarName = exportedVariable.getName(); if( Utils.isEmptyOrWhitespaces( exportedVarName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( exportedVarName ))); else if( ! exportedVarName.matches( ParsingConstants.PATTERN_ID )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( exportedVarName ))); if( exportedVariable.isRandom()) { if( exportedVariable.getRandomKind() == null ) errors.add( new ModelError( RM_INVALID_RANDOM_KIND, component, unrecognized( exportedVariable.getRawKind()))); if( exportedVariable.getValue() != null ) errors.add( new ModelError( RM_NO_VALUE_FOR_RANDOM, component, variable( exportedVarName ))); } } Map<String,String> allExportedVariables = ComponentHelpers.findAllExportedVariables( component ); for( Component superType : ComponentHelpers.findAllExtendedComponents( component )) allExportedVariables.put( superType.getName() + "." + Constants.WILDCARD, null ); for( Facet superFacet : ComponentHelpers.findAllFacets( component )) allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null ); for( ImportedVariable var : ComponentHelpers.findAllImportedVariables( component ).values()) { String varName = var.getName(); String patternForImports = ParsingConstants.PATTERN_ID; patternForImports += "(\\.\\*)?"; if( Utils.isEmptyOrWhitespaces( varName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( varName ))); else if( ! varName.matches( patternForImports )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( varName ))); if( var.isOptional()) continue; if( allExportedVariables.containsKey( varName )) errors.add( new ModelError( RM_COMPONENT_IMPORTS_EXPORTS, component, variable( varName ))); } String cycle = ComponentHelpers.searchForInheritanceCycle( component ); if( cycle != null ) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS_INHERITANCE, component, cycle( cycle ))); cycle = ComponentHelpers.searchForLoop( component ); if( cycle != null && cycle.startsWith( component.getName())) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS, component, cycle( cycle ))); return errors; } private  RuntimeModelValidator(); }
RuntimeModelValidator { public static Collection<ModelError> validate( Component component ) { Collection<ModelError> errors = new ArrayList<> (); if( Utils.isEmptyOrWhitespaces( component.getName())) errors.add( new ModelError( RM_EMPTY_COMPONENT_NAME, component )); else if( ! component.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_NAME, component, component( component ))); else if( component.getName().contains( "." )) errors.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, component, component( component ))); String installerName = ComponentHelpers.findComponentInstaller( component ); if( Utils.isEmptyOrWhitespaces( installerName )) errors.add( new ModelError( RM_EMPTY_COMPONENT_INSTALLER, component, component( component ))); else if( ! installerName.matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_INSTALLER, component, component( component ))); else if( ComponentHelpers.findAllAncestors( component ).isEmpty() && ! Constants.TARGET_INSTALLER.equals( installerName )) errors.add( new ModelError( RM_ROOT_INSTALLER_MUST_BE_TARGET, component, component( component ))); for( ExportedVariable exportedVariable : component.exportedVariables.values()) { String exportedVarName = exportedVariable.getName(); if( Utils.isEmptyOrWhitespaces( exportedVarName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( exportedVarName ))); else if( ! exportedVarName.matches( ParsingConstants.PATTERN_ID )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( exportedVarName ))); if( exportedVariable.isRandom()) { if( exportedVariable.getRandomKind() == null ) errors.add( new ModelError( RM_INVALID_RANDOM_KIND, component, unrecognized( exportedVariable.getRawKind()))); if( exportedVariable.getValue() != null ) errors.add( new ModelError( RM_NO_VALUE_FOR_RANDOM, component, variable( exportedVarName ))); } } Map<String,String> allExportedVariables = ComponentHelpers.findAllExportedVariables( component ); for( Component superType : ComponentHelpers.findAllExtendedComponents( component )) allExportedVariables.put( superType.getName() + "." + Constants.WILDCARD, null ); for( Facet superFacet : ComponentHelpers.findAllFacets( component )) allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null ); for( ImportedVariable var : ComponentHelpers.findAllImportedVariables( component ).values()) { String varName = var.getName(); String patternForImports = ParsingConstants.PATTERN_ID; patternForImports += "(\\.\\*)?"; if( Utils.isEmptyOrWhitespaces( varName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( varName ))); else if( ! varName.matches( patternForImports )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( varName ))); if( var.isOptional()) continue; if( allExportedVariables.containsKey( varName )) errors.add( new ModelError( RM_COMPONENT_IMPORTS_EXPORTS, component, variable( varName ))); } String cycle = ComponentHelpers.searchForInheritanceCycle( component ); if( cycle != null ) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS_INHERITANCE, component, cycle( cycle ))); cycle = ComponentHelpers.searchForLoop( component ); if( cycle != null && cycle.startsWith( component.getName())) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS, component, cycle( cycle ))); return errors; } private  RuntimeModelValidator(); static Collection<ModelError> validate( Component component ); static Collection<ModelError> validate( Facet facet ); static Collection<ModelError> validate( Graphs graphs, File projectDirectory ); static Collection<ModelError> validate( Graphs graphs ); static Collection<ModelError> validate( Instance instance ); static Collection<ModelError> validate( Collection<Instance> instances ); static Collection<ModelError> validate( ApplicationTemplate app ); static Collection<ModelError> validate( ApplicationTemplateDescriptor descriptor ); }
RuntimeModelValidator { public static Collection<ModelError> validate( Component component ) { Collection<ModelError> errors = new ArrayList<> (); if( Utils.isEmptyOrWhitespaces( component.getName())) errors.add( new ModelError( RM_EMPTY_COMPONENT_NAME, component )); else if( ! component.getName().matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_NAME, component, component( component ))); else if( component.getName().contains( "." )) errors.add( new ModelError( RM_DOT_IS_NOT_ALLOWED, component, component( component ))); String installerName = ComponentHelpers.findComponentInstaller( component ); if( Utils.isEmptyOrWhitespaces( installerName )) errors.add( new ModelError( RM_EMPTY_COMPONENT_INSTALLER, component, component( component ))); else if( ! installerName.matches( ParsingConstants.PATTERN_FLEX_ID )) errors.add( new ModelError( RM_INVALID_COMPONENT_INSTALLER, component, component( component ))); else if( ComponentHelpers.findAllAncestors( component ).isEmpty() && ! Constants.TARGET_INSTALLER.equals( installerName )) errors.add( new ModelError( RM_ROOT_INSTALLER_MUST_BE_TARGET, component, component( component ))); for( ExportedVariable exportedVariable : component.exportedVariables.values()) { String exportedVarName = exportedVariable.getName(); if( Utils.isEmptyOrWhitespaces( exportedVarName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( exportedVarName ))); else if( ! exportedVarName.matches( ParsingConstants.PATTERN_ID )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( exportedVarName ))); if( exportedVariable.isRandom()) { if( exportedVariable.getRandomKind() == null ) errors.add( new ModelError( RM_INVALID_RANDOM_KIND, component, unrecognized( exportedVariable.getRawKind()))); if( exportedVariable.getValue() != null ) errors.add( new ModelError( RM_NO_VALUE_FOR_RANDOM, component, variable( exportedVarName ))); } } Map<String,String> allExportedVariables = ComponentHelpers.findAllExportedVariables( component ); for( Component superType : ComponentHelpers.findAllExtendedComponents( component )) allExportedVariables.put( superType.getName() + "." + Constants.WILDCARD, null ); for( Facet superFacet : ComponentHelpers.findAllFacets( component )) allExportedVariables.put( superFacet.getName() + "." + Constants.WILDCARD, null ); for( ImportedVariable var : ComponentHelpers.findAllImportedVariables( component ).values()) { String varName = var.getName(); String patternForImports = ParsingConstants.PATTERN_ID; patternForImports += "(\\.\\*)?"; if( Utils.isEmptyOrWhitespaces( varName )) errors.add( new ModelError( RM_EMPTY_VARIABLE_NAME, component, variable( varName ))); else if( ! varName.matches( patternForImports )) errors.add( new ModelError( RM_INVALID_VARIABLE_NAME, component, variable( varName ))); if( var.isOptional()) continue; if( allExportedVariables.containsKey( varName )) errors.add( new ModelError( RM_COMPONENT_IMPORTS_EXPORTS, component, variable( varName ))); } String cycle = ComponentHelpers.searchForInheritanceCycle( component ); if( cycle != null ) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS_INHERITANCE, component, cycle( cycle ))); cycle = ComponentHelpers.searchForLoop( component ); if( cycle != null && cycle.startsWith( component.getName())) errors.add( new ModelError( RM_CYCLE_IN_COMPONENTS, component, cycle( cycle ))); return errors; } private  RuntimeModelValidator(); static Collection<ModelError> validate( Component component ); static Collection<ModelError> validate( Facet facet ); static Collection<ModelError> validate( Graphs graphs, File projectDirectory ); static Collection<ModelError> validate( Graphs graphs ); static Collection<ModelError> validate( Instance instance ); static Collection<ModelError> validate( Collection<Instance> instances ); static Collection<ModelError> validate( ApplicationTemplate app ); static Collection<ModelError> validate( ApplicationTemplateDescriptor descriptor );  }