diff options
Diffstat (limited to 'ms/controllerblueprints/modules')
4 files changed, 40 insertions, 1 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt index 496182ee7..43e6d221f 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt @@ -82,4 +82,3 @@ object BluePrintVelocityTemplateService { } } - 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 02505acad..6f961c8ed 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 @@ -26,6 +26,7 @@ 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.assertEquals import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @@ -97,5 +98,39 @@ class BluePrintTemplateServiceTest { assertNotNull(content, "failed to generate content for velocity template") } } + + @Test + fun `no value variable should evaluate to default value - standalone template mesh test`() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json") + + val content = BluePrintVelocityTemplateService.generateContent(template, json) + //first line represents a variable whose value was successfully retrieved, second line contains a variable + // whose value could not be evaluated + val expected = "sample-hostname\n\${node0_backup_router_address}" + assertEquals(expected, content, "No value variable should use default value") + } + } + + @Test + fun `no value variable should evaluate to default value - blueprint processing test`() { + runBlocking { + val bluePrintTemplateService = BluePrintTemplateService() + + val templateFile = "templates/default-variable-value-velocity-template.vtl" + val jsonFile = "templates/default-variable-value-data.json" + + val content = bluePrintTemplateService.generateContentFromFiles(templateFile, + BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf()) + + //first line represents a variable whose value was successfully retrieved, second line contains a variable + // whose value could not be evaluated + val expected = "sample-hostname\n\${node0_backup_router_address}" + assertEquals(expected, content, "No value variable should use default value") + } + + } + } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json new file mode 100755 index 000000000..940ca8d73 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json @@ -0,0 +1,3 @@ +{ + "node0_hostname": "sample-hostname" +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl new file mode 100755 index 000000000..ce2458e2e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl @@ -0,0 +1,2 @@ +$node0_hostname +${node0_backup_router_address}
\ No newline at end of file |