diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-23 18:14:56 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-23 18:39:42 +0300 |
commit | 7ef9ac0d813c9c2a029879a0137de1865d980b73 (patch) | |
tree | 5f9e167ab7b39b085aa784c9537c74f8d3322d4c /common/openecomp-common-configuration-management/openecomp-configuration-management-test/src | |
parent | 1a480bc8be16c11991760e009c22cb9a555067bd (diff) |
Fixed resources not being closed in config tests
Fixed static analysis violations in the openecomp-configuration-management-test
module of SDC onboarding - high-severity issues like not releasing resources
(e.g. FileInputStream), and some minor code cleanup.
Change-Id: I6f8e64577499213d06f5ff3a22ea39f6a46fdccd
Issue-ID: SDC-291
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'common/openecomp-common-configuration-management/openecomp-configuration-management-test/src')
7 files changed, 39 insertions, 39 deletions
diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ConfigSourceLocationTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ConfigSourceLocationTest.java index 7eb591c6d2..731826b53c 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ConfigSourceLocationTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ConfigSourceLocationTest.java @@ -33,10 +33,10 @@ public class ConfigSourceLocationTest { Properties props = new Properties(); props.setProperty("maxCachedBufferSize", "1024"); props.setProperty("artifact.maxsize", "1024"); - File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Config Property at Conventional Resource"); - out.close(); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Config Property at Conventional Resource"); + } } @Test diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/DynamicConfigurationTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/DynamicConfigurationTest.java index 1ca41f8a81..2140e84873 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/DynamicConfigurationTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/DynamicConfigurationTest.java @@ -39,10 +39,10 @@ public class DynamicConfigurationTest { props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20"); props.setProperty("_config.namespace",NAMESPACE); props.setProperty("_config.mergeStrategy","override"); - File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Override Config Property at Conventional Resource"); - out.close(); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } //Verify configuration with Configuration without wait. This should fetch cached value Assert.assertEquals("14" , config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH)); @@ -60,7 +60,7 @@ public class DynamicConfigurationTest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } } diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NodeSpecificCLITest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NodeSpecificCLITest.java index 795780b83b..43729cbaf2 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NodeSpecificCLITest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NodeSpecificCLITest.java @@ -51,10 +51,10 @@ public class NodeSpecificCLITest { Properties props = new Properties(); props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "50"); props.setProperty("_config.namespace",NAMESPACE); - File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Node Config Property"); - out.close(); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } Thread.sleep(35000); @@ -86,7 +86,7 @@ public class NodeSpecificCLITest { //Verify maxlength on other nodes by deleting node specific configuration if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } Thread.sleep(35000); @@ -103,7 +103,7 @@ public class NodeSpecificCLITest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationForNodeConfigTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationForNodeConfigTest.java index 3d1579e25e..9d719103df 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationForNodeConfigTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationForNodeConfigTest.java @@ -25,7 +25,7 @@ import java.util.Properties; public class NotificationForNodeConfigTest { public final static String NAMESPACE = "NotificationForNodeConfig"; - public String updatedValue = null; + private String updatedValue = null; @Before public void setUp() throws IOException { @@ -42,10 +42,10 @@ public class NotificationForNodeConfigTest { Properties props = new Properties(); props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "30"); props.setProperty("_config.namespace",NAMESPACE); - File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Node Config Property"); - out.close(); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } Thread.sleep(35000); @@ -55,9 +55,9 @@ public class NotificationForNodeConfigTest { config.addConfigurationChangeListener(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, new NodePropValListener()); props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "80"); - out = new FileOutputStream( f ); - props.store(out, "Updated Node Config Property"); - out.close(); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Updated Node Config Property"); + } Thread.sleep(35000); @@ -79,7 +79,7 @@ public class NotificationForNodeConfigTest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } } diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationOnPropValTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationOnPropValTest.java index 8a461503ae..7354cd19f7 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationOnPropValTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationOnPropValTest.java @@ -25,7 +25,7 @@ public class NotificationOnPropValTest { public final static String NAMESPACE = "NotificationOnPropVal"; - public String updatedValue = null; + private String updatedValue = null; @Before public void setUp() throws IOException { @@ -45,10 +45,10 @@ public class NotificationOnPropValTest { props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "20"); props.setProperty("_config.namespace",NAMESPACE); props.setProperty("_config.mergeStrategy","override"); - File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Override Config Property at Conventional Resource"); - out.close(); + File f = new File(TestUtil.jsonSchemaLoc + "config.properties"); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } Thread.sleep(35000); @@ -70,7 +70,7 @@ public class NotificationOnPropValTest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } } diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/UnregisterNotificationTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/UnregisterNotificationTest.java index a53f3c2d40..e387f13e93 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/UnregisterNotificationTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/UnregisterNotificationTest.java @@ -25,7 +25,7 @@ import java.util.Properties; public class UnregisterNotificationTest { public final static String NAMESPACE = "UnregisterNotification"; - public String updatedValue = null; + private String updatedValue = null; @Before public void setUp() throws IOException { @@ -70,9 +70,9 @@ public class UnregisterNotificationTest { props.setProperty("_config.namespace",NAMESPACE); props.setProperty("_config.mergeStrategy","override"); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Override Config Property at Conventional Resource"); - out.close(); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Override Config Property at Conventional Resource"); + } } private class PropertyListener implements ConfigurationChangeListener { @@ -88,7 +88,7 @@ public class UnregisterNotificationTest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } } diff --git a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ValidateNodeConfigTest.java b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ValidateNodeConfigTest.java index 03a6786275..8f7d703468 100644 --- a/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ValidateNodeConfigTest.java +++ b/common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ValidateNodeConfigTest.java @@ -40,9 +40,9 @@ public class ValidateNodeConfigTest { props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "56"); props.setProperty("_config.namespace","ValidateNodeConfig"); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); - OutputStream out = new FileOutputStream( f ); - props.store(out, "Node Config Property"); - out.close(); + try (OutputStream out = new FileOutputStream(f)) { + props.store(out, "Node Config Property"); + } System.out.println(System.getProperty("node.config.location")); @@ -73,7 +73,7 @@ public class ValidateNodeConfigTest { TestUtil.cleanUp(); File f = new File(TestUtil.jsonSchemaLoc+"config.properties"); if(f.exists()) { - boolean isDeleted = f.delete(); + f.delete(); } } |