2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.heat.services.tree;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
24 import org.openecomp.core.utilities.file.FileContentHandler;
25 import org.openecomp.core.utilities.file.FileUtils;
26 import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
30 public class HeatTreeManagerTest {
33 public void testHeatTreeCreation() throws IOException {
35 FileContentHandler fileContentMap = new FileContentHandler();
36 URL url = this.getClass().getResource("/heatTreeValidationOutput");
38 File templateDir = new File(url.getFile());
39 File[] files = templateDir.listFiles();
41 if (files == null || files.length == 0) {
45 for (File file : files) {
46 fileContentMap.addFile(file.getName(), getFileContent(file));
49 HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap);
50 heatTreeManager.createTree();
51 HeatStructureTree tree = heatTreeManager.getTree();
52 Assert.assertNotNull(tree);
53 Assert.assertEquals(tree.getHeat().size(), 2);
57 public void testHeatTreeArtifactsCreated() throws IOException {
59 FileContentHandler fileContentMap = new FileContentHandler();
60 URL url = this.getClass().getResource("/heatTreeArtifactsValidationOutput");
62 File templateDir = new File(url.getFile());
63 File[] files = templateDir.listFiles();
65 if (files == null || files.length == 0) {
69 for (File file : files) {
70 fileContentMap.addFile(file.getName(), getFileContent(file));
73 HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap);
74 heatTreeManager.createTree();
75 HeatStructureTree tree = heatTreeManager.getTree();
76 Assert.assertNotNull(tree);
77 Assert.assertEquals(tree.getHeat().size(), 3);
78 verifyHeatArtifacts(tree, "ocgmgr.yaml", 1);
79 verifyHeatArtifacts(tree, "ocgapp.yaml", 0);
80 verifyHeatArtifacts(tree, "base_ocg.yaml", 0);
84 private void verifyHeatArtifacts(HeatStructureTree tree, String heatName, int expectedArtifactNum ) {
85 HeatStructureTree heat = HeatStructureTree.getHeatStructureTreeByName(tree.getHeat(), heatName);
86 Assert.assertNotNull(heat);
87 if (expectedArtifactNum > 0) {
88 Assert.assertNotNull(heat.getArtifacts());
89 Assert.assertEquals(heat.getArtifacts().size(), expectedArtifactNum);
91 Assert.assertNull(heat.getArtifacts());
96 private byte[] getFileContent(File file) throws IOException {
97 try(InputStream inputStream = new FileInputStream(file)) {
98 return FileUtils.toByteArray(inputStream);