mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
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:
parent
5e1ea1a3e4
commit
58477834b6
@ -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);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user