From a5c4a996f58bfff602124fd4e38c0d2ec70d68f2 Mon Sep 17 00:00:00 2001 From: vempo Date: Thu, 10 May 2018 13:28:06 +0300 Subject: Refactor HEAT tree test for error handling Change-Id: Ibd19cecc948896dcca240ab6fc65c394a1034d11 Issue-ID: SDC-836 Signed-off-by: vempo --- .../heat/services/tree/HeatTreeManagerTest.java | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/test/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/test/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerTest.java index c43c55721e..6e8901c3ce 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/test/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-core/src/test/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerTest.java @@ -16,26 +16,21 @@ package org.openecomp.sdc.heat.services.tree; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.testng.Assert; import org.testng.annotations.Test; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL;; - - public class HeatTreeManagerTest { - private Logger logger = LoggerFactory.getLogger(HeatTreeManagerTest.class); - @Test - public void testHeatTreeCreation() { + public void testHeatTreeCreation() throws IOException { FileContentHandler fileContentMap = new FileContentHandler(); URL url = this.getClass().getResource("/heatTreeValidationOutput"); @@ -59,7 +54,7 @@ public class HeatTreeManagerTest { } @Test - public void testHeatTreeArtifactsCreated() { + public void testHeatTreeArtifactsCreated() throws IOException { FileContentHandler fileContentMap = new FileContentHandler(); URL url = this.getClass().getResource("/heatTreeArtifactsValidationOutput"); @@ -88,23 +83,19 @@ public class HeatTreeManagerTest { private void verifyHeatArtifacts(HeatStructureTree tree, String heatName, int expectedArtifactNum ) { HeatStructureTree heat = HeatStructureTree.getHeatStructureTreeByName(tree.getHeat(), heatName); - if(expectedArtifactNum > 0) { + Assert.assertNotNull(heat); + if (expectedArtifactNum > 0) { Assert.assertNotNull(heat.getArtifacts()); Assert.assertEquals(heat.getArtifacts().size(), expectedArtifactNum); } else { Assert.assertNull(heat.getArtifacts()); } - } - private byte[] getFileContent(File file) { - try { - return FileUtils.toByteArray(new FileInputStream(file)); - } catch (IOException e) { - logger.debug("",e); + private byte[] getFileContent(File file) throws IOException { + try(InputStream inputStream = new FileInputStream(file)) { + return FileUtils.toByteArray(inputStream); } - - return new byte[0]; } } -- cgit 1.2.3-korg