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.asJsonPrimitive
22 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
23 import kotlin.test.assertNotNull
25 class BluePrintDSLTest {
28 fun testOperationDSLWorkflow() {
30 val blueprint = blueprint("sample-bp", "1.0.0",
31 "brindasanth@onap.com", "sample, blueprints") {
33 artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
35 // For New Component Definition
36 component("resource-resolution", "component-script-executor", "1.0.0",
37 "Resource Resolution component.") {
39 // Attributes ( Properties which will be set during execution)
40 attribute("template1-data", "string", true, "")
43 property("string-value1", "string", true, "sample")
44 property("string-value2", "string", true, getInput("key-1"))
46 input("json-content", "json", true, """{ "name" : "cds"}""")
47 input("template-content", "string", true, getArtifact("template1"))
49 output("self-attribute-expression", "json", true, getAttribute("template1-data"))
51 artifact("template1", "artifact-template-velocity", "Templates/template1.vtl")
54 // Already definitions Registered Components
55 registryComponent("activate-restconf", "component-resource-resolution", "1.0.0",
56 "RestconfExecutor", "Resource Resolution component.") {
59 property("string-value1", "data")
61 input("json-content", """{ "name" : "cds"}""")
63 output("self-attribute-expression", getAttribute("template1-data"))
65 artifact("template2", "artifact-template-velocity", "Templates/template1.vtl")
69 workflow("resource-resolution-process", "Resource Resolution wf") {
70 input("json-content", "json", true, "")
71 input("key-1", "string", true, "")
72 output("status", "string", true, "success")
73 step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke")
76 assertNotNull(blueprint.components, "failed to get components")
77 assertNotNull(blueprint.workflows, "failed to get workflows")
78 //println(blueprint.asJsonString(true))
80 val serviceTemplateGenerator = BluePrintServiceTemplateGenerator(blueprint)
81 val serviceTemplate = serviceTemplateGenerator.serviceTemplate()
82 assertNotNull(serviceTemplate.topologyTemplate, "failed to get service topology template")
83 //println(serviceTemplate.asJsonString(true))
87 fun testServiceTemplate() {
88 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
89 "brindasanth@onap.com", "sample, blueprints") {
90 metadata("release", "1806")
91 import("Definition/data_types.json")
92 dsl("rest-endpoint", """{ "selector" : "odl-selector"}""")
93 dsl("db-endpoint", """{ "selector" : "db-selector"}""")
95 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
96 description = "sample activation") {
98 property("json-content", """{ "name" : "cds"}""")
99 property("array-content", """["controller", "blueprints"]""")
100 property("int-value", 234)
101 property("boolean-value", true)
102 property("string-value", "sample")
103 property("input-expression", getInput("key-1"))
104 property("self-property-expression", getProperty("key-1"))
105 property("self-artifact-expression", getArtifact("key-1"))
106 property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1"))
109 property("self-attribute-expression", getAttribute("key-1"))
112 // Other way of defining Node Template with artifacts, implementation
113 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
114 operation("ResourceResolutionExecutor", "") {
117 property("boolean-value", true)
118 property("string-value", "sample")
121 property("resolve-expression", getAttribute("key-1"))
124 artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
127 workflow("resource-resolution", "to resolve resources") {
128 step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
130 // Alternate way to define workflow
131 workflow("activate", "to resolve resources") {
132 // Alternate step definition
133 step("netconf-activate-call", "activate", "call activation component") {
138 property("request-content", "json", true)
141 property("response-content", "json", true) {
142 value(getAttribute("key-1"))
143 defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
150 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
151 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
152 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
153 //println(serviceTemplate.asJsonString(true))
157 fun testNodeTypePropertyConstrains() {
158 val nodeType = nodeType("data-node", "1.0.0", "tosca.Nodes.root", "") {
159 property("ip-address", "string", true, "") {
160 defaultValue("127.0.0.1")
162 validValues(arrayListOf("""127.0.0.1""".asJsonPrimitive()))
169 property("disk-space", "string", true, "") {
172 validValues("""["200KB", "400KB"]""")
174 inRange("""["100KB", "500KB" ]""")
179 validValues("""[ 200, 400]""")
180 greaterOrEqual("10KB")
187 assertNotNull(nodeType, "failed to get nodeType")
188 // println(nodeType.asJsonString(true))
192 fun testServiceTemplateWorkflow() {
193 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
194 "brindasanth@onap.com", "sample, blueprints") {
196 workflowNodeTemplate("activate", "component-resource-resolution", "") {
197 operation("ResourceResolutionExecutor", "") {
199 property("string-value", "sample")
205 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
206 assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
207 //println(serviceTemplate.asJsonString(true))