Change the header to SO
[so.git] / mso-catalog-db / src / test / java / org / openecomp / mso / db / catalog / test / HeatTemplateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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 import java.util.UUID;
34
35 import org.junit.Test;
36
37 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
38 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
39
40 /**
41  */
42
43 public class HeatTemplateTest {
44         
45     @Test
46     public final void heatTemplateTest () {
47         HeatTemplate heatTemplate = new HeatTemplate ();
48         heatTemplate.setTemplateBody ("testBody");
49         heatTemplate.setArtifactUuid(UUID.randomUUID().toString());
50         assertTrue (heatTemplate.getHeatTemplate ().equals ("testBody"));
51         assertTrue (heatTemplate.toString ().contains ("8 chars"));
52         heatTemplate.setTemplateBody (null);
53         assertTrue (heatTemplate.toString ().contains ("Not defined"));
54         HashSet<HeatTemplateParam> set = new HashSet<> ();
55         HeatTemplateParam param = new HeatTemplateParam ();
56         param.setParamName ("param name");
57         param.setParamType ("string");
58         param.setRequired (false);
59         param.setHeatTemplateArtifactUuid(UUID.randomUUID().toString());
60         set.add (param);
61         HeatTemplateParam param2 = new HeatTemplateParam ();
62         param2.setParamName ("param 2");
63         param2.setParamType ("string");
64         param2.setRequired (true);
65         param2.setHeatTemplateArtifactUuid(UUID.randomUUID().toString());
66         set.add (param2);
67         heatTemplate.setParameters (set);
68         String heatStr = heatTemplate.toString (); 
69         assertTrue (heatStr.contains ("param name"));
70         assertTrue (heatStr.toString ().contains ("param 2(reqd)"));
71
72         File tempFile;
73         try {
74             tempFile = File.createTempFile ("heatTemplate", "test");
75             tempFile.deleteOnExit ();
76             try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (tempFile),
77                                                                              "utf-8"))) {
78                 writer.write ("something\n");
79                 writer.write ("something2\n");
80             }
81             heatTemplate.setTemplateBody(tempFile.getAbsolutePath ());
82             assertTrue (heatTemplate.getHeatTemplate ().contains ("test"));
83         } catch (IOException e) {
84             e.printStackTrace ();
85             fail ("Exception caught");
86         }
87     }
88
89 }