Merge "Reorder modifiers"
[so.git] / mso-catalog-db / src / test / java / org / openecomp / mso / db / catalog / test / HeatFilesTest.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 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
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.UUID;
33
34 import org.junit.Test;
35 import org.openecomp.mso.db.catalog.beans.HeatFiles;
36
37 /**
38  */
39
40 public class HeatFilesTest {
41
42         @Test
43         public final void heatFilesTest() {
44
45                 HeatFiles heatFiles = new HeatFiles();
46                 heatFiles.setFileBody("testBody");
47                 heatFiles.setArtifactUuid(UUID.randomUUID().toString());
48                 assertTrue(heatFiles.getFileBody().equals("testBody"));
49                 assertTrue(!heatFiles.toString().contains("8 chars"));
50                 heatFiles.setFileBody(null);
51                 assertTrue(!heatFiles.toString().contains("Not defined"));
52                 heatFiles.setVersion("12");
53                 assertTrue(heatFiles.getVersion().equals("12"));
54
55                 heatFiles.setFileName("File");
56                 assertTrue(heatFiles.getFileName().equalsIgnoreCase("File"));
57
58                 heatFiles.setCreated(null);
59                 assertTrue(heatFiles.getCreated() == null);
60                 heatFiles.setAsdcUuid("asdc");
61
62                 assertTrue(heatFiles.getAsdcUuid().equalsIgnoreCase("asdc"));
63
64                 heatFiles.setDescription("desc");
65                 assertTrue(heatFiles.getDescription().equalsIgnoreCase("desc"));
66                 
67                 
68                 heatFiles.setArtifactChecksum("artifactChecksum");
69                 assertTrue(heatFiles.getArtifactChecksum().equalsIgnoreCase("artifactChecksum"));
70                 File tempFile;
71                 try {
72                         tempFile = File.createTempFile("heatFiles", "test");
73                         tempFile.deleteOnExit();
74                         try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "utf-8"))) {
75                                 writer.write("something\n");
76                                 writer.write("something2\n");
77                         }
78                         heatFiles.setFileBody(tempFile.getAbsolutePath());
79                         assertTrue(heatFiles.getFileBody().contains("test"));
80                 } catch (IOException e) {
81                         e.printStackTrace();
82                         fail("Exception caught");
83                 }
84
85         }
86
87 }