diff options
author | Steve Siani <alphonse.steve.siani.djissitchi@ibm.com> | 2019-04-03 15:23:27 -0400 |
---|---|---|
committer | Steve Siani <alphonse.steve.siani.djissitchi@ibm.com> | 2019-04-09 13:08:39 -0400 |
commit | f7d891db891f4fb8db103236d4010de1b7739378 (patch) | |
tree | c7a7fff4bca0ec2ac3536442463ad8494fd07196 /ms/controllerblueprints/modules/blueprint-core/src/test/kotlin | |
parent | f2b17fe1579222ffc251d48bf9475dc3fcfc1206 (diff) |
Jinja template for Blueprint template service
Change-Id: Iec777e4500c2a040faccc8375b1d2dd24c27cb7f
Issue-ID: CCSDK-1193
Signed-off-by: Steve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/test/kotlin')
-rw-r--r-- | ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt | 79 |
1 files changed, 73 insertions, 6 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt index 6a193c37e..e4227180b 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt @@ -1,6 +1,8 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * + * Modifications Copyright © 2019 IBM, Bell Canada. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,20 +18,85 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service +import kotlinx.coroutines.runBlocking import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.BeforeTest import kotlin.test.assertNotNull +@RunWith(SpringRunner::class) class BluePrintTemplateServiceTest { + lateinit var blueprintRuntime: BluePrintRuntimeService<*> + + @BeforeTest + fun setup() { + val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) + } + @Test - fun testGenerateContent() { + fun testVelocityGeneratedContent() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/base-config-velocity-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-velocity.json") - val template = JacksonUtils.getClassPathFileContent("templates/base-config-template.vtl") - val json = JacksonUtils.getClassPathFileContent("templates/base-config-data.json") + val content = BluePrintVelocityTemplateService.generateContent(template, json) + assertNotNull(content, "failed to generate content for velocity template") + } - val content = BluePrintTemplateService.generateContent(template, json) - assertNotNull(content, "failed to generate content for velocity template") + } + + @Test + fun testJinjaGeneratedContent() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/base-config-jinja-template.jinja") + val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json") + + var element: MutableMap<String, Any> = mutableMapOf() + element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1")) + + val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element) + assertNotNull(content, "failed to generate content for velocity template") + } } -}
\ No newline at end of file + + @Test + fun testVelocityGeneratedContentFromFiles() { + runBlocking { + val bluePrintTemplateService = BluePrintTemplateService(blueprintRuntime, + "resource-assignment", "baseconfig-template") + val templateFile = "templates/base-config-velocity-template.vtl" + val jsonFile = "templates/base-config-data-velocity.json" + + val content = bluePrintTemplateService.generateContentFromFiles( + templateFile, jsonFile, false, mutableMapOf()) + assertNotNull(content, "failed to generate content for velocity template") + } + + } + + @Test + fun testJinjaGeneratedContentFromFiles() { + runBlocking { + var element: MutableMap<String, Any> = mutableMapOf() + element["additional_array"] = arrayListOf(hashMapOf("name" to "Element1", "location" to "Region0"), hashMapOf("name" to "Element2", "location" to "Region1")) + + val bluePrintTemplateService = BluePrintTemplateService(blueprintRuntime, + "resource-assignment", "another-template") + + val templateFile = "templates/base-config-jinja-template.jinja" + val jsonFile = "templates/base-config-data-jinja.json" + + val content = bluePrintTemplateService.generateContentFromFiles( + templateFile, + jsonFile, false, element) + assertNotNull(content, "failed to generate content for velocity template") + } + } +} + |