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.jsonAsJsonType
21 import kotlin.test.assertNotNull
23 class BluePrintDSLTest {
26 fun testOperationDSLWorkflow() {
28 val blueprint = blueprint("sample-bp", "1.0.0",
29 "brindasanth@onap.com", "sample, blueprints") {
31 // For New Component Definition
32 component("resource-resolution", "component-resource-resolution", "1.0.0",
33 "Resource Resolution Call") {
35 // Attributes ( Properties which will be set during execution)
36 attribute("template1-data", "string", true, "")
39 property("string-value1", "string", true, "sample")
40 property("string-value2", "string", true, getInput("key-1"))
42 input("json-content", "json", true, """{ "name" : "cds"}""")
43 input("template-content", "string", true, getArtifact("template1"))
45 output("self-attribute-expression", "json", true, getAttribute("template1-data"))
47 artifacts("template1", "artifact-velocity", "Templates/template1.vtl")
50 workflow("resource-resolution-process", "") {
51 input("json-content", "json", true, "")
52 input("key-1", "string", true, "")
53 output("status", "string", true, "success")
54 step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke")
57 assertNotNull(blueprint.components, "failed to get components")
58 assertNotNull(blueprint.workflows, "failed to get workflows")
59 //println(blueprint.asJsonString(true))
63 fun testServiceTemplate() {
64 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
65 "brindasanth@onap.com", "sample, blueprints") {
66 metadata("release", "1806")
67 import("Definition/data_types.json")
68 dsl("rest-endpoint", """{ "selector" : "odl-selector"}""")
69 dsl("db-endpoint", """{ "selector" : "db-selector"}""")
71 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
72 description = "sample activation") {
74 property("json-content", """{ "name" : "cds"}""")
75 property("array-content", """["controller", "blueprints"]""")
76 property("int-value", 234)
77 property("boolean-value", true)
78 property("string-value", "sample")
79 property("input-expression", getInput("key-1"))
80 property("self-property-expression", getProperty("key-1"))
81 property("self-artifact-expression", getArtifact("key-1"))
82 property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1"))
85 property("self-attribute-expression", getAttribute("key-1"))
88 // Other way of defining Node Template with artifacts, implementation
89 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
90 operation("ResourceResolutionExecutor", "") {
93 property("boolean-value", true)
94 property("string-value", "sample")
97 property("resolve-expression", getAttribute("key-1"))
100 artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
103 workflow("resource-resolution", "to resolve resources") {
104 step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
106 // Alternate way to define workflow
107 workflow("activate", "to resolve resources") {
108 // Alternate step definition
109 step("netconf-activate-call", "activate", "call activation component") {
114 property("request-content", "json", true)
117 property("response-content", "json", true) {
118 value(getAttribute("key-1"))
119 defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
126 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
127 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
128 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
129 //println(serviceTemplate.asJsonString(true))
133 fun testServiceTemplateWorkflow() {
134 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
135 "brindasanth@onap.com", "sample, blueprints") {
137 workflowNodeTemplate("activate", "component-resource-resolution", "") {
138 operation("ResourceResolutionExecutor", "") {
140 property("string-value", "sample")
146 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
147 assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
148 //println(serviceTemplate.asJsonString(true))