020edc78e5edfb70ad5379a666e8f7cf3e0ff586
[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.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
22 import kotlin.test.assertNotNull
23
24 class BluePrintDSLTest {
25
26     @Test
27     fun testOperationDSLWorkflow() {
28
29         val blueprint = blueprint("sample-bp", "1.0.0",
30                 "brindasanth@onap.com", "sample, blueprints") {
31
32             artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
33
34             // For New Component Definition
35             component("resource-resolution", "component-script-executor", "1.0.0",
36                     "Resource Resolution component.") {
37                 implementation(180)
38                 // Attributes ( Properties which will be set during execution)
39                 attribute("template1-data", "string", true, "")
40
41                 // Properties
42                 property("string-value1", "string", true, "sample")
43                 property("string-value2", "string", true, getInput("key-1"))
44                 // Inputs
45                 input("json-content", "json", true, """{ "name" : "cds"}""")
46                 input("template-content", "string", true, getArtifact("template1"))
47                 // Outputs
48                 output("self-attribute-expression", "json", true, getAttribute("template1-data"))
49                 // Artifacts
50                 artifact("template1", "artifact-template-velocity", "Templates/template1.vtl")
51             }
52
53             // Already definitions Registered Components
54             registryComponent("activate-restconf", "component-resource-resolution", "1.0.0",
55                     "RestconfExecutor", "Resource Resolution component.") {
56                 implementation(180)
57                 // Properties
58                 property("string-value1", "data")
59                 // Inputs
60                 input("json-content", """{ "name" : "cds"}""")
61                 // Outputs
62                 output("self-attribute-expression", getAttribute("template1-data"))
63                 // Artifacts
64                 artifact("template2", "artifact-template-velocity", "Templates/template1.vtl")
65
66             }
67
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")
73             }
74         }
75         assertNotNull(blueprint.components, "failed to get components")
76         assertNotNull(blueprint.workflows, "failed to get workflows")
77         //println(blueprint.asJsonString(true))
78
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))
83     }
84
85     @Test
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"}""")
93             topologyTemplate {
94                 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
95                         description = "sample activation") {
96                     inputs {
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"))
106                     }
107                     outputs {
108                         property("self-attribute-expression", getAttribute("key-1"))
109                     }
110                 }
111                 // Other way of defining Node Template with artifacts, implementation
112                 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
113                     operation("ResourceResolutionExecutor", "") {
114                         implementation(180)
115                         inputs {
116                             property("boolean-value", true)
117                             property("string-value", "sample")
118                         }
119                         outputs {
120                             property("resolve-expression", getAttribute("key-1"))
121                         }
122                     }
123                     artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
124                 }
125
126                 workflow("resource-resolution", "to resolve resources") {
127                     step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
128                 }
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") {
133                         success("END")
134                         failure("END")
135                     }
136                     inputs {
137                         property("request-content", "json", true)
138                     }
139                     outputs {
140                         property("response-content", "json", true) {
141                             value(getAttribute("key-1"))
142                             defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
143                         }
144                     }
145                 }
146             }
147         }
148
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))
153     }
154
155     @Test
156     fun testServiceTemplateWorkflow() {
157         val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
158                 "brindasanth@onap.com", "sample, blueprints") {
159             topologyTemplate {
160                 workflowNodeTemplate("activate", "component-resource-resolution", "") {
161                     operation("ResourceResolutionExecutor", "") {
162                         inputs {
163                             property("string-value", "sample")
164                         }
165                     }
166                 }
167             }
168         }
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))
172     }
173
174 }