2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
22 import kotlin.test.assertNotNull
24 class BluePrintDSLTest {
27 fun testOperationDSLWorkflow() {
29 val blueprint = blueprint("sample-bp", "1.0.0",
30 "brindasanth@onap.com", "sample, blueprints") {
32 artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
34 // For New Component Definition
35 component("resource-resolution", "component-script-executor", "1.0.0",
36 "Resource Resolution component.") {
38 // Attributes ( Properties which will be set during execution)
39 attribute("template1-data", "string", true, "")
42 property("string-value1", "string", true, "sample")
43 property("string-value2", "string", true, getInput("key-1"))
45 input("json-content", "json", true, """{ "name" : "cds"}""")
46 input("template-content", "string", true, getArtifact("template1"))
48 output("self-attribute-expression", "json", true, getAttribute("template1-data"))
50 artifact("template1", "artifact-template-velocity", "Templates/template1.vtl")
53 // Already definitions Registered Components
54 registryComponent("activate-restconf", "component-resource-resolution", "1.0.0",
55 "RestconfExecutor", "Resource Resolution component.") {
58 property("string-value1", "data")
60 input("json-content", """{ "name" : "cds"}""")
62 output("self-attribute-expression", getAttribute("template1-data"))
64 artifact("template2", "artifact-template-velocity", "Templates/template1.vtl")
68 workflow("resource-resolution-process", "Resource Resolution wf") {
69 input("json-content", "json", true, "")
70 input("key-1", "string", true, "")
71 output("status", "string", true, "success")
72 step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke")
75 assertNotNull(blueprint.components, "failed to get components")
76 assertNotNull(blueprint.workflows, "failed to get workflows")
77 //println(blueprint.asJsonString(true))
79 val serviceTemplateGenerator = BluePrintServiceTemplateGenerator(blueprint)
80 val serviceTemplate = serviceTemplateGenerator.serviceTemplate()
81 assertNotNull(serviceTemplate.topologyTemplate, "failed to get service topology template")
82 //println(serviceTemplate.asJsonString(true))
86 fun testServiceTemplate() {
87 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
88 "brindasanth@onap.com", "sample, blueprints") {
89 metadata("release", "1806")
90 import("Definition/data_types.json")
91 dsl("rest-endpoint", """{ "selector" : "odl-selector"}""")
92 dsl("db-endpoint", """{ "selector" : "db-selector"}""")
94 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
95 description = "sample activation") {
97 property("json-content", """{ "name" : "cds"}""")
98 property("array-content", """["controller", "blueprints"]""")
99 property("int-value", 234)
100 property("boolean-value", true)
101 property("string-value", "sample")
102 property("input-expression", getInput("key-1"))
103 property("self-property-expression", getProperty("key-1"))
104 property("self-artifact-expression", getArtifact("key-1"))
105 property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1"))
108 property("self-attribute-expression", getAttribute("key-1"))
111 // Other way of defining Node Template with artifacts, implementation
112 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
113 operation("ResourceResolutionExecutor", "") {
116 property("boolean-value", true)
117 property("string-value", "sample")
120 property("resolve-expression", getAttribute("key-1"))
123 artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
126 workflow("resource-resolution", "to resolve resources") {
127 step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
129 // Alternate way to define workflow
130 workflow("activate", "to resolve resources") {
131 // Alternate step definition
132 step("netconf-activate-call", "activate", "call activation component") {
137 property("request-content", "json", true)
140 property("response-content", "json", true) {
141 value(getAttribute("key-1"))
142 defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
149 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
150 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
151 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
152 //println(serviceTemplate.asJsonString(true))
156 fun testServiceTemplateWorkflow() {
157 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
158 "brindasanth@onap.com", "sample, blueprints") {
160 workflowNodeTemplate("activate", "component-resource-resolution", "") {
161 operation("ResourceResolutionExecutor", "") {
163 property("string-value", "sample")
169 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
170 assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
171 //println(serviceTemplate.asJsonString(true))