Initial OpenECOMP MSO commit
[so.git] / mso-catalog-db / src / test / java / org / openecomp / mso / db / catalog / test / HeatTemplateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.db.catalog.test;
22
23
24 import static org.junit.Assert.*;
25
26 import java.io.BufferedWriter;
27 import java.io.File;
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;
33
34 import org.junit.Test;
35
36 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
37 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
38
39 /**
40  */
41
42 public class HeatTemplateTest {
43         
44     @Test
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);
57         set.add (param);
58         HeatTemplateParam param2 = new HeatTemplateParam ();
59         param2.setParamName ("param 2");
60         param2.setParamType ("string");
61         param2.setRequired (true);
62         set.add (param2);
63         heatTemplate.setParameters (set);
64         String heatStr = heatTemplate.toString (); 
65         assertTrue (heatStr.contains ("param name"));
66         assertTrue (heatStr.toString ().contains ("param 2(reqd)"));
67
68         File tempFile;
69         try {
70             tempFile = File.createTempFile ("heatTemplate", "test");
71             tempFile.deleteOnExit ();
72             try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (tempFile),
73                                                                              "utf-8"))) {
74                 writer.write ("something\n");
75                 writer.write ("something2\n");
76             }
77             heatTemplate.setTemplatePath (tempFile.getAbsolutePath ());
78             assertTrue (heatTemplate.getHeatTemplate ().contains ("something2"));
79         } catch (IOException e) {
80             e.printStackTrace ();
81             fail ("Exception caught");
82         }
83     }
84
85 }