ApplicationTemplateDescriptor { public static ApplicationTemplateDescriptor load( Properties properties ) { ApplicationTemplateDescriptor result = new ApplicationTemplateDescriptor(); result.name = getLegacyProperty( properties, APPLICATION_NAME, null ); result.description = getLegacyProperty( properties, APPLICATION_DESCRIPTION, null ); result.version = getLegacyProperty( properties, APPLICATION_VERSION, null ); result.dslId = getLegacyProperty( properties, APPLICATION_DSL_ID, null ); result.graphEntryPoint = properties.getProperty( APPLICATION_GRAPH_EP, null ); result.instanceEntryPoint = properties.getProperty( APPLICATION_INSTANCES_EP, null ); result.externalExportsPrefix = properties.getProperty( APPLICATION_EXTERNAL_EXPORTS_PREFIX, null ); final Pattern pattern = Pattern.compile( "([^=\\s]+)\\s+" + APPLICATION_EXTERNAL_EXPORTS_AS + "\\s+([^=\\s]+)", Pattern.CASE_INSENSITIVE ); String rawExports = properties.getProperty( APPLICATION_EXTERNAL_EXPORTS, "" ); for( String rawExport : Utils.splitNicely( rawExports, "," )) { Matcher m = pattern.matcher( rawExport ); if( m.matches()) result.externalExports.put( m.group( 1 ), m.group( 2 )); else result.invalidExternalExports.add( rawExport ); } String rawTags = properties.getProperty( APPLICATION_TAGS, "" ); result.tags.addAll( Utils.splitNicely( rawTags, "," )); return result; }  String getName(); void setName( String name ); String getDescription(); void setDescription( String description ); String getVersion(); void setVersion( String version ); String getExternalExportsPrefix(); void setExternalExportsPrefix( String externalExportsId ); String getGraphEntryPoint(); void setGraphEntryPoint( String graphEntryPoint ); String getInstanceEntryPoint(); void setInstanceEntryPoint( String instanceEntryPoint ); String getDslId(); void setDslId( String dslId ); static ApplicationTemplateDescriptor load( Properties properties ); static ApplicationTemplateDescriptor load( File f ); static void save( File f, ApplicationTemplateDescriptor descriptor ); static final String APPLICATION_NAME; static final String APPLICATION_VERSION; static final String APPLICATION_TAGS; static final String APPLICATION_DESCRIPTION; static final String APPLICATION_DSL_ID; static final String APPLICATION_GRAPH_EP; static final String APPLICATION_INSTANCES_EP; static final String APPLICATION_EXTERNAL_EXPORTS_PREFIX; static final String APPLICATION_EXTERNAL_EXPORTS; static final String APPLICATION_EXTERNAL_EXPORTS_AS; final Map<String,Integer> propertyToLine; final Map<String,String> externalExports; final Set<String> invalidExternalExports; final Set<String> tags; }
@Test public void testInvalidExternalExports_1() throws Exception { File f = this.folder.newFile(); Utils.writeStringInto( "exports = toto IS titi", f ); ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f ); Assert.assertEquals( 0, desc.externalExports.size()); Assert.assertEquals( 1, desc.invalidExternalExports.size()); Assert.assertEquals( "toto IS titi", desc.invalidExternalExports.iterator().next()); }
@Test public void testInvalidExternalExports_2() throws Exception { File f = this.folder.newFile(); Utils.writeStringInto( "exports: HAProxy.ip as lb-ip HAProxy.httpPort as lb-port", f ); ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f ); Assert.assertEquals( 0, desc.externalExports.size()); Assert.assertEquals( 1, desc.invalidExternalExports.size()); Assert.assertEquals( "HAProxy.ip as lb-ip HAProxy.httpPort as lb-port", desc.invalidExternalExports.iterator().next()); }
@Test public void testValidExternalExports() throws Exception { File f = this.folder.newFile(); Utils.writeStringInto( "exports: HAProxy.ip as lb-ip, HAProxy.httpPort as lb-port", f ); ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f ); Assert.assertEquals( 0, desc.invalidExternalExports.size()); Assert.assertEquals( 2, desc.externalExports.size()); Assert.assertEquals( "lb-ip", desc.externalExports.get( "HAProxy.ip" )); Assert.assertEquals( "lb-port", desc.externalExports.get( "HAProxy.httpPort" )); }
@Test public void testLineNumberResolution() throws Exception { File f = TestUtils.findTestFile( "/configurations/valid/app-template-descriptor.properties" ); Assert.assertTrue( f.exists()); ApplicationTemplateDescriptor desc = ApplicationTemplateDescriptor.load( f ); Assert.assertNotNull( desc ); Assert.assertEquals((Integer) 5, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_DESCRIPTION )); Assert.assertEquals((Integer) 12, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_DSL_ID )); Assert.assertEquals((Integer) 25, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_EXTERNAL_EXPORTS )); Assert.assertEquals((Integer) 19, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_EXTERNAL_EXPORTS_PREFIX )); Assert.assertEquals((Integer) 14, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_GRAPH_EP )); Assert.assertEquals((Integer) 15, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_INSTANCES_EP )); Assert.assertEquals((Integer) 2, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_NAME )); Assert.assertEquals((Integer) 29, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_TAGS )); Assert.assertEquals((Integer) 3, desc.propertyToLine.get( ApplicationTemplateDescriptor.APPLICATION_VERSION )); }