e3e19792f5e575b77b4781ced9739f40afd4a218
[sdc.git] /
1 /*
2  *
3  *  Copyright © 2017-2018 European Support Limited
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  * Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  * /
17  *
18  */
19
20 package org.openecomp.sdc.heat.services.tree;
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.net.URL;
27 import java.util.List;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.openecomp.core.utilities.file.FileUtils;
31 import org.openecomp.sdc.common.utils.SdcCommon;
32 import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
33
34 public class HeatTreeManagerTest {
35
36     @Test
37     public void testCreateTree() throws IOException {
38         HeatTreeManager heatTreeManager = new HeatTreeManager();
39         addFile(heatTreeManager, "mock/model/MANIFEST.json", SdcCommon.MANIFEST_NAME);
40         addFile(heatTreeManager, "mock/model/first.yaml", "first.yaml");
41         addFile(heatTreeManager, "mock/model/second.yaml", "second.yaml");
42         addFile(heatTreeManager, "mock/model/first.env", "first.env");
43         addFile(heatTreeManager, "mock/model/base_cscf_volume.yaml", "base_cscf_volume.yaml");
44         addFile(heatTreeManager, "mock/model/network.yml", "network.yml");
45         addFile(heatTreeManager, "mock/model/testHeat.yml", "testHeat.yml");
46         addFile(heatTreeManager, "mock/model/nested.yml", "nested.yml");
47         addFile(heatTreeManager, "mock/model/base_cscf_volume.env", "base_cscf_volume.env");
48
49         heatTreeManager.createTree();
50
51         HeatStructureTree heatStructureTree = heatTreeManager.getTree();
52         Assert.assertNotNull(heatStructureTree);
53         Assert.assertEquals(1, heatStructureTree.getHeat().size());
54         Assert.assertEquals(1, heatStructureTree.getNetwork().size());
55     }
56
57     private void addFile(HeatTreeManager heatTreeManager, String fileLocation, String fileName)
58             throws IOException {
59
60         List<URL> urlList = FileUtils.getAllLocations(fileLocation);
61         try (InputStream inputStream = new FileInputStream(new File(urlList.get(0).getPath()))) {
62             heatTreeManager.addFile(fileName, inputStream);
63         }
64     }
65 }