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 {
25 fun testServiceTemplate() {
26 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
27 "brindasanth@onap.com", "sample, blueprints") {
28 metadata("release", "1806")
29 import("Definition/data_types.json")
30 dsl("rest-endpoint", """{ "selector" : "odl-selector"}""")
31 dsl("db-endpoint", """{ "selector" : "db-selector"}""")
33 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
34 description = "sample activation") {
36 property("json-content", """{ "name" : "cds"}""")
37 property("array-content", """["controller", "blueprints"]""")
38 property("int-value", 234)
39 property("boolean-value", true)
40 property("string-value", "sample")
41 property("input-expression", getInput("key-1"))
42 property("self-property-expression", getProperty("key-1"))
43 property("self-artifact-expression", getArtifact("key-1"))
44 property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1"))
47 property("self-attribute-expression", getAttribute("key-1"))
50 // Other way of defining Node Template with artifacts, implementation
51 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
52 operation("ResourceResolutionExecutor", "") {
55 property("boolean-value", true)
56 property("string-value", "sample")
59 property("resolve-expression", getAttribute("key-1"))
62 artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
65 workflow("resource-resolution", "to resolve resources") {
66 step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
68 // Alternate way to define workflow
69 workflow("activate", "to resolve resources") {
70 // Alternate step definition
71 step("netconf-activate-call", "activate", "call activation component") {
76 property("request-content", "json", true)
79 property("response-content", "json", true) {
80 value(getAttribute("key-1"))
81 defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
88 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
89 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes")
90 assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], "failed to get nodeTypes(activate)")
91 //println(JacksonUtils.getJson(serviceTemplate, true))
95 fun testServiceTemplateWorkflow() {
96 val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
97 "brindasanth@onap.com", "sample, blueprints") {
99 workflowNodeTemplate("activate", "component-resource-resolution", "") {
100 operation("ResourceResolutionExecutor", "") {
102 property("string-value", "sample")
108 assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template")
109 assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)")
110 //println(JacksonUtils.getJson(serviceTemplate, true))