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;
19 import org.openecomp.core.utilities.file.FileContentHandler;
20 import org.openecomp.core.utilities.file.FileUtils;
21 import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
22 import org.testng.Assert;
23 import org.testng.annotations.Test;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
31 public class HeatTreeManagerTest {
34 public void testHeatTreeCreation() throws IOException {
36 FileContentHandler fileContentMap = new FileContentHandler();
37 URL url = this.getClass().getResource("/heatTreeValidationOutput");
39 File templateDir = new File(url.getFile());
40 File[] files = templateDir.listFiles();
42 if (files == null || files.length == 0) {
46 for (File file : files) {
47 fileContentMap.addFile(file.getName(), getFileContent(file));
50 HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap);
51 heatTreeManager.createTree();
52 HeatStructureTree tree = heatTreeManager.getTree();
53 Assert.assertNotNull(tree);
54 Assert.assertEquals(tree.getHeat().size(), 2);
58 public void testHeatTreeArtifactsCreated() throws IOException {
60 FileContentHandler fileContentMap = new FileContentHandler();
61 URL url = this.getClass().getResource("/heatTreeArtifactsValidationOutput");
63 File templateDir = new File(url.getFile());
64 File[] files = templateDir.listFiles();
66 if (files == null || files.length == 0) {
70 for (File file : files) {
71 fileContentMap.addFile(file.getName(), getFileContent(file));
74 HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap);
75 heatTreeManager.createTree();
76 HeatStructureTree tree = heatTreeManager.getTree();
77 Assert.assertNotNull(tree);
78 Assert.assertEquals(tree.getHeat().size(), 3);
79 verifyHeatArtifacts(tree, "ocgmgr.yaml", 1);
80 verifyHeatArtifacts(tree, "ocgapp.yaml", 0);
81 verifyHeatArtifacts(tree, "base_ocg.yaml", 0);
85 private void verifyHeatArtifacts(HeatStructureTree tree, String heatName, int expectedArtifactNum ) {
86 HeatStructureTree heat = HeatStructureTree.getHeatStructureTreeByName(tree.getHeat(), heatName);
87 Assert.assertNotNull(heat);
88 if (expectedArtifactNum > 0) {
89 Assert.assertNotNull(heat.getArtifacts());
90 Assert.assertEquals(heat.getArtifacts().size(), expectedArtifactNum);
92 Assert.assertNull(heat.getArtifacts());
97 private byte[] getFileContent(File file) throws IOException {
98 try(InputStream inputStream = new FileInputStream(file)) {
99 return FileUtils.toByteArray(inputStream);