From 43645dccbaced7a45b37f9e05221186231c39d74 Mon Sep 17 00:00:00 2001 From: vempo Date: Tue, 24 Oct 2017 11:20:03 +0300 Subject: Fixed resources not being closed in tests Fixed static analysis violations in a few modules of SDC onboarding - high-severity issues like not releasing resources (e.g. FileInputStream). Did some minor code cleanup. Change-Id: I89a229ad6bc150951f1f3cc437b3a175a663e203 Issue-ID: SDC-291 Signed-off-by: vempo --- .../openecomp/sdc/heat/datatypes/model/EnvironmentTest.java | 13 +++++++------ .../heat/datatypes/model/HeatOrchestrationTemplateTest.java | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'openecomp-be/lib/openecomp-heat-lib/src') diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java index fc01e2e8b0..6312e5a575 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java @@ -23,16 +23,18 @@ package org.openecomp.sdc.heat.datatypes.model; import org.junit.Test; import org.openecomp.sdc.tosca.services.YamlUtil; +import java.io.IOException; import java.io.InputStream; public class EnvironmentTest { @Test - public void testYamlToServiceTemplateObj() { + public void testYamlToServiceTemplateObj() throws IOException { YamlUtil yamlUtil = new YamlUtil(); - InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/envSettings.env"); - Environment envVars = yamlUtil.yamlToObject(yamlFile, Environment.class); - envVars.toString(); + try (InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/envSettings.env")) { + Environment envVars = yamlUtil.yamlToObject(yamlFile, Environment.class); + envVars.toString(); + } } @Test @@ -46,9 +48,8 @@ public class EnvironmentTest { if (heatResourceName.length() == lastIndexOfUnderscore) { System.out.println(heatResourceName); } else { - String heatResourceNameSuffix = heatResourceName.substring(lastIndexOfUnderscore + 1); + try { - int heatResourceNameSuffixInt = Integer.parseInt(heatResourceNameSuffix); System.out.println(heatResourceName.substring(0, lastIndexOfUnderscore)); } catch (NumberFormatException ignored) { System.out.println(heatResourceName); diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java index 3715b0f999..dd8abdc0b9 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java @@ -26,6 +26,7 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.services.YamlUtil; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; @@ -37,12 +38,13 @@ public class HeatOrchestrationTemplateTest { private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); @Test - public void testYamlToServiceTemplateObj() { + public void testYamlToServiceTemplateObj() throws IOException { YamlUtil yamlUtil = new YamlUtil(); - InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/testHeat.yml"); - HeatOrchestrationTemplate heatOrchestrationTemplate = - yamlUtil.yamlToObject(yamlFile, HeatOrchestrationTemplate.class); - heatOrchestrationTemplate.toString(); + try (InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/testHeat.yml")) { + HeatOrchestrationTemplate heatOrchestrationTemplate = + yamlUtil.yamlToObject(yamlFile, HeatOrchestrationTemplate.class); + heatOrchestrationTemplate.toString(); + } } @Test -- cgit 1.2.3-korg