Commit 90f1566a by Dave Kantor

ATLAS-1539 Address coverity scan issues

parent 20fb5894
...@@ -32,23 +32,52 @@ public class ApplicationPropertiesTest { ...@@ -32,23 +32,52 @@ public class ApplicationPropertiesTest {
@Test @Test
public void testGetFileAsInputStream() throws Exception { public void testGetFileAsInputStream() throws Exception {
Configuration props = ApplicationProperties.get("test.properties"); Configuration props = ApplicationProperties.get("test.properties");
InputStream inStr = null;
// configured file as class loader resource // configured file as class loader resource
InputStream inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); try {
assertNotNull(inStr); inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
assertNotNull(inStr);
}
finally {
if (inStr != null) {
inStr.close();
}
}
// configured file from file system path // configured file from file system path
props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties"); props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties");
inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); try {
assertNotNull(inStr); inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
assertNotNull(inStr);
}
finally {
if (inStr != null) {
inStr.close();
}
}
// default file as class loader resource // default file as class loader resource
inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties"); try {
assertNotNull(inStr); inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
assertNotNull(inStr);
}
finally {
if (inStr != null) {
inStr.close();
}
}
// default file relative to working directory // default file relative to working directory
inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties"); try {
assertNotNull(inStr); inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties");
assertNotNull(inStr);
}
finally {
if (inStr != null) {
inStr.close();
}
}
// default file relative to atlas configuration directory // default file relative to atlas configuration directory
String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources"); String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources");
...@@ -57,6 +86,9 @@ public class ApplicationPropertiesTest { ...@@ -57,6 +86,9 @@ public class ApplicationPropertiesTest {
assertNotNull(inStr); assertNotNull(inStr);
} }
finally { finally {
if (inStr != null) {
inStr.close();
}
if (originalConfDirSetting != null) { if (originalConfDirSetting != null) {
System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting); System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting);
} }
...@@ -67,21 +99,31 @@ public class ApplicationPropertiesTest { ...@@ -67,21 +99,31 @@ public class ApplicationPropertiesTest {
// non-existent property and no default file // non-existent property and no default file
try { try {
ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null); inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null);
fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown"); fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
} }
catch (AtlasException e) { catch (AtlasException e) {
// good // good
} }
finally {
if (inStr != null) {
inStr.close();
}
}
// configured file not found in file system or classpath // configured file not found in file system or classpath
props.setProperty("jaas.properties.file", "does_not_exist.txt"); props.setProperty("jaas.properties.file", "does_not_exist.txt");
try { try {
ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null); inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown"); fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
} }
catch (AtlasException e) { catch (AtlasException e) {
// good // good
} }
finally {
if (inStr != null) {
inStr.close();
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment