diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2018-05-10 13:28:06 +0300 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-05-14 10:02:09 +0000 |
commit | a5c4a996f58bfff602124fd4e38c0d2ec70d68f2 (patch) | |
tree | 521871829eb7138d6d4c7d47958bcf524e49d6dc /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager | |
parent | d618ad69ee066ef0aac5a075bc4705543eb87103 (diff) |
Refactor HEAT tree test for error handling
Change-Id: Ibd19cecc948896dcca240ab6fc65c394a1034d11
Issue-ID: SDC-836
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager')
2 files changed, 53 insertions, 69 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java index baa0d8da3f..1ee1e2a85d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/HeatTreeManagerTest.java @@ -1,47 +1,42 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorsoftwareproduct.tree; -import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.datatypes.error.ErrorMessage; -import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.heat.services.tree.HeatTreeManager; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; +import org.testng.Assert; +import org.testng.annotations.Test; public class HeatTreeManagerTest extends TreeBaseTest { @Test - public void testHeatTreeManager() { + public void testHeatTreeManager() throws IOException, URISyntaxException { - INPUT_DIR = "./tree/valid_tree/input/"; - HeatTreeManager heatTreeManager = initHeatTreeManager(); + HeatTreeManager heatTreeManager = initHeatTreeManager("./tree/valid_tree/input/"); heatTreeManager.createTree(); Map<String, List<ErrorMessage>> errorMap = new HashMap<>(); @@ -57,10 +52,9 @@ public class HeatTreeManagerTest extends TreeBaseTest { } @Test - public void testHeatTreeManagerMissingManifest() { + public void testHeatTreeManagerMissingManifest() throws IOException, URISyntaxException { - INPUT_DIR = "./tree/missing_manifest/input/"; - HeatTreeManager heatTreeManager = initHeatTreeManager(); + HeatTreeManager heatTreeManager = initHeatTreeManager("./tree/missing_manifest/input/"); heatTreeManager.createTree(); Map<String, List<ErrorMessage>> errorMap = new HashMap<>(); @@ -73,15 +67,15 @@ public class HeatTreeManagerTest extends TreeBaseTest { heatTreeManager.addErrors(errorMap); HeatStructureTree tree = heatTreeManager.getTree(); Assert.assertNotNull(tree); - Assert.assertEquals(tree.getHeat(), null); + Assert.assertNull(tree.getHeat()); } @Test - public void testResourceGroupShowsAsNestedFileInTree() throws IOException { - INPUT_DIR = "./tree/nested_resource_group"; - HeatTreeManager heatTreeManager = initHeatTreeManager(); + public void testResourceGroupShowsAsNestedFileInTree() throws IOException, URISyntaxException { + + HeatTreeManager heatTreeManager = initHeatTreeManager("./tree/nested_resource_group"); heatTreeManager.createTree(); HeatStructureTree tree = heatTreeManager.getTree(); @@ -102,9 +96,9 @@ public class HeatTreeManagerTest extends TreeBaseTest { @Test - public void testVolumeNestedFileIsNotUnderVolumeSubTree() { - INPUT_DIR = "./tree/nested_volume"; - HeatTreeManager heatTreeManager = initHeatTreeManager(); + public void testVolumeNestedFileIsNotUnderVolumeSubTree() throws IOException, URISyntaxException { + + HeatTreeManager heatTreeManager = initHeatTreeManager("./tree/nested_volume"); heatTreeManager.createTree(); HeatStructureTree tree = heatTreeManager.getTree(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java index 2174a6894a..324260e490 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/TreeBaseTest.java @@ -1,68 +1,58 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorsoftwareproduct.tree; -import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.sdc.heat.services.tree.HeatTreeManager; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; - import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; /** * Created by SHALOMB on 6/8/2016. */ -public class TreeBaseTest { - - private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); +public abstract class TreeBaseTest { - String INPUT_DIR; + HeatTreeManager initHeatTreeManager(String inputDirectory) throws URISyntaxException, IOException { + URL url = Thread.currentThread().getContextClassLoader().getResource(inputDirectory); + if (url == null) { + throw new FileNotFoundException("Directory " + inputDirectory + " not found in classpath"); + } - HeatTreeManager initHeatTreeManager() { - HeatTreeManager heatTreeManager = new HeatTreeManager(); + File inputDir = new File(url.toURI()); - URL url = Thread.currentThread().getContextClassLoader().getResource(INPUT_DIR); + File[] files = inputDir.listFiles(); + if (files == null) { + throw new IllegalArgumentException("Directory " + inputDirectory + " does not contain files"); + } - File inputDir = null; - try { - inputDir = new File(url.toURI()); - } catch (URISyntaxException exception) { - log.debug("",exception); - } + HeatTreeManager heatTreeManager = new HeatTreeManager(); + for (File inputFile : files) { - if(inputDir != null) { - File[] files = inputDir.listFiles(); - for (File inputFile : files) { - try { - heatTreeManager.addFile(inputFile.getName(), FileUtils.loadFileToInputStream( - INPUT_DIR.replace("/", File.separator) + File.separator + inputFile.getName())); - } catch (Exception e) { - throw e; + String path = inputDirectory.replace("/", File.separator) + File.separator + inputFile.getName(); + try (InputStream inputStream = FileUtils.loadFileToInputStream(path)) { + heatTreeManager.addFile(inputFile.getName(), inputStream); + } } - } - } - return heatTreeManager; - } -} + return heatTreeManager; + } +}
\ No newline at end of file |