2 * ============LICENSE_START=======================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
20 package org.onap.ccsdk.cds.controllerblueprints.core.service
\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
29 import kotlin.test.assertEquals
\r
30 import kotlin.test.assertNotNull
\r
33 class BlueprintVelocityTemplateTest {
\r
35 fun testVelocityGeneratedContent() {
\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
44 fun `no value variable should evaluate to default value - standalone template mesh test`() {
\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
54 fun `Expected value variable from file`() {
\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