PluginFile implements PluginInterface { Properties readProperties( Instance instance ) throws PluginException { Properties result = null; File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); File file = new File( instanceDirectory, FILE_NAME ); try { if( file.exists()) { result = Utils.readPropertiesFile( file ); } else { this.logger.warning( file + " does not exist or is invalid. There is no instruction for the plugin." ); result = new Properties(); } } catch( IOException e ) { throw new PluginException( e ); } return result; }  @Override String getPluginName(); @Override void setNames( String applicationName, String rootInstanceName ); @Override void initialize( Instance instance ); @Override void deploy( Instance instance ); @Override void start( Instance instance ); @Override void update( Instance instance, Import importChanged, InstanceStatus statusChanged ); @Override void stop( Instance instance ); @Override void undeploy( Instance instance ); static final String PLUGIN_NAME; }
@Test public void testReadProperties() throws Exception { Instance instance = new Instance( "inst" ).component( new Component( "comp" ).installerName( "something" )); PluginFile plugin = new PluginFile(); File instanceDirectory = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); Utils.deleteFilesRecursively( instanceDirectory ); Properties properties = plugin.readProperties( instance ); Assert.assertEquals( 0, properties.size()); Assert.assertTrue( instanceDirectory.mkdirs()); File file = new File( instanceDirectory, PluginFile.FILE_NAME ); String content = "toto = 1\ntiti=something\n1.re.s = pou"; Utils.writeStringInto( content, file ); properties = plugin.readProperties( instance ); Assert.assertEquals( 3, properties.size()); Assert.assertEquals( "1", properties.getProperty( "toto" )); Assert.assertEquals( "something", properties.getProperty( "titi" )); Assert.assertEquals( "pou", properties.getProperty( "1.re.s" )); Utils.deleteFilesRecursively( instanceDirectory ); }