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.utils.BluePrintMetadataUtils
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
26 import org.springframework.test.context.junit4.SpringRunner
27 import kotlin.test.BeforeTest
28 import kotlin.test.assertNotNull
30 @RunWith(SpringRunner::class)
31 class BluePrintTemplateServiceTest {
33 lateinit var blueprintRuntime: BluePrintRuntimeService<*>
37 val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
38 blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
42 fun testVelocityGeneratedContent() {
44 val template = JacksonUtils.getClassPathFileContent("templates/base-config-velocity-template.vtl")
45 val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-velocity.json")
47 val content = BluePrintVelocityTemplateService.generateContent(template, json)
48 assertNotNull(content, "failed to generate content for velocity template")
54 fun testJinjaGeneratedContent() {
56 val template = JacksonUtils.getClassPathFileContent("templates/base-config-jinja-template.jinja")
57 val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json")
59 var element: MutableMap<String, Any> = mutableMapOf()
60 element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1"))
62 val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element)
63 assertNotNull(content, "failed to generate content for velocity template")
69 fun testVelocityGeneratedContentFromFiles() {
71 val bluePrintTemplateService = BluePrintTemplateService(blueprintRuntime,
72 "resource-assignment", "baseconfig-template")
73 val templateFile = "templates/base-config-velocity-template.vtl"
74 val jsonFile = "templates/base-config-data-velocity.json"
76 val content = bluePrintTemplateService.generateContentFromFiles(
77 templateFile, jsonFile, false, mutableMapOf())
78 assertNotNull(content, "failed to generate content for velocity template")
84 fun testJinjaGeneratedContentFromFiles() {
86 var element: MutableMap<String, Any> = mutableMapOf()
87 element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1"))
89 val bluePrintTemplateService = BluePrintTemplateService(blueprintRuntime,
90 "resource-assignment", "another-template")
92 val templateFile = "templates/base-config-jinja-template.jinja"
93 val jsonFile = "templates/base-config-data-jinja.json"
95 val content = bluePrintTemplateService.generateContentFromFiles(
97 jsonFile, false, element)
98 assertNotNull(content, "failed to generate content for velocity template")