InputStream use fix in PropertiesUtil

- use PropertiesUtil.loadFromFile to read the properties
- test added

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
Laszlo Hornyak 2013-10-24 22:37:14 +02:00
parent 5e1ea1a3e4
commit 58477834b6
2 changed files with 14 additions and 1 deletions

View File

@ -130,7 +130,7 @@ public class PropertiesUtil {
File commandsFile = findConfigFile(configFile);
if (commandsFile != null) {
try {
preProcessedCommands.load(new FileInputStream(commandsFile));
loadFromFile(preProcessedCommands, commandsFile);
} catch (FileNotFoundException fnfex) {
// in case of a file within a jar in classpath, try to open stream using url
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);

View File

@ -18,6 +18,7 @@ package com.cloud.utils;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
@ -30,6 +31,7 @@ public class PropertiesUtilsTest {
File configFile = PropertiesUtil.findConfigFile("notexistingresource");
Assert.assertNull(configFile);
}
@Test
public void loadFromFile() throws IOException {
File file = File.createTempFile("test", ".properties");
@ -38,4 +40,15 @@ public class PropertiesUtilsTest {
PropertiesUtil.loadFromFile(properties, file);
Assert.assertEquals("b", properties.get("a"));
}
@Test
public void processConfigFile() throws IOException {
File tempFile = File.createTempFile("temp", ".properties");
FileUtils.writeStringToFile(tempFile, "a=b\nc=d\n");
Map<String, String> config = PropertiesUtil
.processConfigFile(new String[] { tempFile.getAbsolutePath() });
Assert.assertEquals("b", config.get("a"));
Assert.assertEquals("d", config.get("c"));
tempFile.delete();
}
}