Fixed resources not being closed in config tests 67/20167/2
authorvempo <vitaliy.emporopulo@amdocs.com>
Mon, 23 Oct 2017 15:14:56 +0000 (18:14 +0300)
committervempo <vitaliy.emporopulo@amdocs.com>
Mon, 23 Oct 2017 15:39:42 +0000 (18:39 +0300)
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>
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ConfigSourceLocationTest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/DynamicConfigurationTest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NodeSpecificCLITest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationForNodeConfigTest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/NotificationOnPropValTest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/UnregisterNotificationTest.java
common/openecomp-common-configuration-management/openecomp-configuration-management-test/src/test/java/org/openecomp/config/test/ValidateNodeConfigTest.java

index 7eb591c..731826b 100644 (file)
@@ -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
index 1ca41f8..2140e84 100644 (file)
@@ -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();
         }
     }
 }
index 795780b..43729cb 100644 (file)
@@ -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();
         }
     }
 
index 3d1579e..9d71910 100644 (file)
@@ -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();
         }
     }
 }
index 8a46150..7354cd1 100644 (file)
@@ -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();
         }
     }
 }
index a53f3c2..e387f13 100644 (file)
@@ -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();
         }
     }
 }
index 03a6786..8f7d703 100644 (file)
@@ -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();
         }
     }