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;
33 import java.util.UUID;
35 import org.junit.Test;
37 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
38 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
43 public class HeatTemplateTest {
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());
61 HeatTemplateParam param2 = new HeatTemplateParam ();
62 param2.setParamName ("param 2");
63 param2.setParamType ("string");
64 param2.setRequired (true);
65 param2.setHeatTemplateArtifactUuid(UUID.randomUUID().toString());
67 heatTemplate.setParameters (set);
68 String heatStr = heatTemplate.toString ();
69 assertTrue (heatStr.contains ("param name"));
70 assertTrue (heatStr.toString ().contains ("param 2(reqd)"));
74 tempFile = File.createTempFile ("heatTemplate", "test");
75 tempFile.deleteOnExit ();
76 try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (tempFile),
78 writer.write ("something\n");
79 writer.write ("something2\n");
81 heatTemplate.setTemplateBody(tempFile.getAbsolutePath ());
82 assertTrue (heatTemplate.getHeatTemplate ().contains ("test"));
83 } catch (IOException e) {
85 fail ("Exception caught");