dff0f943ff2849b89b1769e54778b4c98b94c763
[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     @Test
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"}""")
32             topologyTemplate {
33                 nodeTemplateOperation(nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor",
34                         description = "sample activation") {
35                     inputs {
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"))
45                     }
46                     outputs {
47                         property("self-attribute-expression", getAttribute("key-1"))
48                     }
49                 }
50                 // Other way of defining Node Template with artifacts, implementation
51                 nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") {
52                     operation("ResourceResolutionExecutor", "") {
53                         implementation(180)
54                         inputs {
55                             property("boolean-value", true)
56                             property("string-value", "sample")
57                         }
58                         outputs {
59                             property("resolve-expression", getAttribute("key-1"))
60                         }
61                     }
62                     artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl")
63                 }
64
65                 workflow("resource-resolution", "to resolve resources") {
66                     step("resource-resolution-call", "resolve", "Resource Resolution component invoke")
67                 }
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") {
72                         success("END")
73                         failure("END")
74                     }
75                     inputs {
76                         property("request-content", "json", true)
77                     }
78                     outputs {
79                         property("response-content", "json", true) {
80                             value(getAttribute("key-1"))
81                             defaultValue("""{ "status" : "success"}""".jsonAsJsonType())
82                         }
83                     }
84                 }
85             }
86         }
87
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))
92     }
93
94     @Test
95     fun testServiceTemplateWorkflow() {
96         val serviceTemplate = serviceTemplate("sample-bp", "1.0.0",
97                 "brindasanth@onap.com", "sample, blueprints") {
98             topologyTemplate {
99                 workflowNodeTemplate("activate", "component-resource-resolution", "") {
100                     operation("ResourceResolutionExecutor", "") {
101                         inputs {
102                             property("string-value", "sample")
103                         }
104                     }
105                 }
106             }
107         }
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))
111     }
112
113 }