56d23a210b5319a0058aa9f08f8539017e162626
[ccsdk/cds.git] / components / model-catalog / blueprint-model / archetype-blueprint / src / main / resources / archetype-resources / Tests / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / service / BlueprintVelocityTemplateTest.kt
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - CCSDK\r
4  * ================================================================================\r
5  * Copyright (C) 2022 Tech Mahindra\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.onap.ccsdk.cds.controllerblueprints.core.service\r
21 \r
22 import kotlinx.coroutines.runBlocking\r
23 import org.junit.Test\r
24 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService\r
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils\r
26 import kotlin.test.BeforeTest\r
27 import java.io.File\r
28 import java.util.*\r
29 import kotlin.test.assertEquals\r
30 import kotlin.test.assertNotNull\r
31 \r
32 \r
33 class BlueprintVelocityTemplateTest {\r
34     private val velocityHome = System.getenv("velocity_path")\r
35 \r
36 \r
37     @BeforeTest\r
38     fun setup() {\r
39         val properties = Properties()\r
40         properties["file.resource.loader.path"] = velocityHome\r
41     }\r
42     @Test\r
43     fun testVelocityGeneratedContent() {\r
44         runBlocking {\r
45             val template = JacksonUtils.getContent("Templates/base-config-velocity-template.vtl")\r
46             val json = JacksonUtils.getContent("Templates/base-config-data-velocity.json")\r
47             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
48             assertNotNull(content, "failed to generate content for velocity template")\r
49         }\r
50     }\r
51     @Test\r
52     fun `no value variable should evaluate to default value - standalone template mesh test`() {\r
53         runBlocking {\r
54             val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
55             val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
56             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
57             val expected = "sample-hostname\n\${node0_backup_router_address}"\r
58             assertEquals(expected, content, "No value variable should use default value")\r
59         }\r
60     }\r
61     @Test\r
62     fun `Expected value variable from file`() {\r
63         runBlocking {\r
64             val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
65             val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
66             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
67             val expected = File("Tests/kotlin/default-variable-value-data.txt").readText()\r
68             assertEquals(expected, content, "expected value variable from file")\r
69         }\r
70 \r
71     }\r
72 }