e7f24d629c7dc70ca62bca58280c2595ff74bd94
[ccsdk/cds.git] /
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
18
19 import org.junit.Test
20 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
21 import kotlin.test.assertNotNull
22
23 class BluePrintDSLTest {
24
25     @Test
26     fun testOperationDSLWorkflow() {
27
28         val blueprint = blueprint("sample-bp", "1.0.0",
29                 "brindasanth@onap.com", "sample, blueprints") {
30
31             // For New Component Definition
32             component("resource-resolution", "component-resource-resolution", "1.0.0",
33                     "Resource Resolution Call") {
34                 implementation(180)
35                 // Attributes ( Properties which will be set during execution)
36                 attribute("template1-data", "string", true, "")
37
38                 // Properties
39                 property("string-value1", "string", true, "sample")
40                 property("string-value2", "string", true, getInput("key-1"))
41                 // Inputs
42                 input("json-content", "json", true, """{ "name" : "cds"}""")
43                 input("template-content", "string", true, getArtifact("template1"))
44                 // Outputs
45                 output("self-attribute-expression", "json", true, getAttribute("template1-data"))
46                 // Artifacts
47                 artifacts("template1", "artifact-velocity", "Templates/template1.vtl")
48             }
49
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")
55             }
56         }
57         assertNotNull(blueprint.components, "failed to get components")
58         assertNotNull(blueprint.workflows, "failed to get workflows")
59         //println(blueprint.asJsonString(true))
60     }
61
62     @Test
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"}""")
70             topologyTemplate {
71                 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
72                         description = "sample activation") {
73                     inputs {
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"))
83                     }
84                     outputs {
85                         property("self-attribute-expression", getAttribute("key-1"))
86                     }
87                 }
88                 // Other way of defining Node Template with artifacts, implementation
89                 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
90                     operation("ResourceResolutionExecutor", "") {
91                         implementation(180)
92                         inputs {
93                             property("boolean-value", true)
94                             property("string-value", "sample")
95                         }
96                         outputs {
97                             property("resolve-expression", getAttribute("key-1"))
98                         }
99                     }
100                     artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
101                 }
102
103                 workflow("resource-resolution", "to resolve resources") {
104                     step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
105                 }
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") {
110                         success("END")
111                         failure("END")
112                     }
113                     inputs {
114                         property("request-content", "json", true)
115                     }
116                     outputs {
117                         property("response-content", "json", true) {
118                             value(getAttribute("key-1"))
119                             defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
120                         }
121                     }
122                 }
123             }
124         }
125
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))
130     }
131
132     @Test
133     fun testServiceTemplateWorkflow() {
134         val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
135                 "brindasanth@onap.com", "sample, blueprints") {
136             topologyTemplate {
137                 workflowNodeTemplate("activate", "component-resource-resolution", "") {
138                     operation("ResourceResolutionExecutor", "") {
139                         inputs {
140                             property("string-value", "sample")
141                         }
142                     }
143                 }
144             }
145         }
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))
149     }
150
151 }