2 * Copyright © 2016-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.vendorsoftwareproduct.tree;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.net.URISyntaxException;
25 import org.openecomp.core.utilities.file.FileUtils;
26 import org.openecomp.sdc.heat.services.tree.HeatTreeManager;
29 * Created by SHALOMB on 6/8/2016.
31 public abstract class TreeBaseTest {
33 HeatTreeManager initHeatTreeManager(String inputDirectory) throws URISyntaxException, IOException {
35 URL url = Thread.currentThread().getContextClassLoader().getResource(inputDirectory);
37 throw new FileNotFoundException("Directory " + inputDirectory + " not found in classpath");
40 File inputDir = new File(url.toURI());
42 File[] files = inputDir.listFiles();
44 throw new IllegalArgumentException("Directory " + inputDirectory + " does not contain files");
47 HeatTreeManager heatTreeManager = new HeatTreeManager();
48 for (File inputFile : files) {
50 String path = inputDirectory.replace("/", File.separator) + File.separator + inputFile.getName();
51 try (InputStream inputStream = FileUtils.loadFileToInputStream(path)) {
52 heatTreeManager.addFile(inputFile.getName(), inputStream);
56 return heatTreeManager;