2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2019 IBM, Bell Canada.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.controllerblueprints.core.service
21 import kotlinx.coroutines.runBlocking
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
27 import org.springframework.test.context.junit4.SpringRunner
28 import kotlin.test.BeforeTest
29 import kotlin.test.assertEquals
30 import kotlin.test.assertNotNull
32 @RunWith(SpringRunner::class)
33 class BluePrintTemplateServiceTest {
35 lateinit var blueprintRuntime: BluePrintRuntimeService<*>
39 val blueprintBasePath: String =
40 ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
41 blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
45 fun testVelocityGeneratedContent() {
47 val template = JacksonUtils.getClassPathFileContent("templates/base-config-velocity-template.vtl")
48 val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-velocity.json")
50 val content = BluePrintVelocityTemplateService.generateContent(template, json)
51 assertNotNull(content, "failed to generate content for velocity template")
57 fun testJinjaGeneratedContent() {
59 val template = JacksonUtils.getClassPathFileContent("templates/master.jinja")
60 val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json")
62 var element: MutableMap<String, Any> = mutableMapOf()
63 element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"),
64 hashMapOf("name" to "Element2", "location" to "Region1"))
66 val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element)
67 assertNotNull(content, "failed to generate content for velocity template")
74 fun `no value variable should evaluate to default value - standalone template mesh test`() {
77 JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl")
78 val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json")
80 val content = BluePrintVelocityTemplateService.generateContent(template, json)
81 //first line represents a variable whose value was successfully retrieved, second line contains a variable
82 // whose value could not be evaluated
83 val expected = "sample-hostname\n\${node0_backup_router_address}"
84 assertEquals(expected, content, "No value variable should use default value")