aa3cf3dabd799a3af60c7e702faeba868c622bfe
[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     @Test\r
35     fun testVelocityGeneratedContent() {\r
36         runBlocking {\r
37             val template = JacksonUtils.getContent("Templates/base-config-velocity-template.vtl")\r
38             val json = JacksonUtils.getContent("Templates/base-config-data-velocity.json")\r
39             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
40             assertNotNull(content, "failed to generate content for velocity template")\r
41         }\r
42     }\r
43     @Test\r
44     fun `no value variable should evaluate to default value - standalone template mesh test`() {\r
45         runBlocking {\r
46             val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
47             val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
48             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
49             val expected = "sample-hostname\n\${node0_backup_router_address}"\r
50             assertEquals(expected, content, "No value variable should use default value")\r
51         }\r
52     }\r
53     @Test\r
54     fun `Expected value variable from file`() {\r
55         runBlocking {\r
56             val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
57             val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
58             val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
59             val expected = File("Tests/kotlin/default-variable-value-data.txt").readText()\r
60             assertEquals(expected, content, "expected value variable from file")\r
61         }\r
62 \r
63     }\r
64 }