2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.db.catalog.test;
24 import static org.junit.Assert.*;
26 import java.io.BufferedWriter;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.OutputStreamWriter;
31 import java.io.Writer;
32 import java.util.HashSet;
34 import org.junit.Test;
36 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
37 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
42 public class HeatTemplateTest {
45 public final void heatTemplateTest () {
46 HeatTemplate heatTemplate = new HeatTemplate ();
47 heatTemplate.setTemplateBody ("testBody");
48 assertTrue (heatTemplate.getHeatTemplate ().equals ("testBody"));
49 assertTrue (heatTemplate.toString ().contains ("8 chars"));
50 heatTemplate.setTemplateBody (null);
51 assertTrue (heatTemplate.toString ().contains ("Not defined"));
52 HashSet<HeatTemplateParam> set = new HashSet<> ();
53 HeatTemplateParam param = new HeatTemplateParam ();
54 param.setParamName ("param name");
55 param.setParamType ("string");
56 param.setRequired (false);
58 HeatTemplateParam param2 = new HeatTemplateParam ();
59 param2.setParamName ("param 2");
60 param2.setParamType ("string");
61 param2.setRequired (true);
63 heatTemplate.setParameters (set);
64 String heatStr = heatTemplate.toString ();
65 assertTrue (heatStr.contains ("param name"));
66 assertTrue (heatStr.toString ().contains ("param 2(reqd)"));
70 tempFile = File.createTempFile ("heatTemplate", "test");
71 tempFile.deleteOnExit ();
72 try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (tempFile),
74 writer.write ("something\n");
75 writer.write ("something2\n");
77 heatTemplate.setTemplatePath (tempFile.getAbsolutePath ());
78 assertTrue (heatTemplate.getHeatTemplate ().contains ("something2"));
79 } catch (IOException e) {
81 fail ("Exception caught");