Add declarative acceptance tests
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint / capability_cli / Scripts / kotlin / cba / capability / cli / CapabilityCliDefinitions.kt
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 cba.capability.cli
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTemplateComponentScriptExecutor
20 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.artifactTypeTemplateVelocity
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTypeComponent
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions
28
29 class CapabilityCliDefinitions : AbstractBluePrintDefinitions() {
30
31     override fun serviceTemplate(): ServiceTemplate {
32         return defaultServiceTemplate()
33     }
34 }
35
36 fun CapabilityCliDefinitions.defaultServiceTemplate() =
37         serviceTemplate(name = "capability-cli",
38                 version = "1.0.0",
39                 author = "Brinda Santh Muthuramalingam",
40                 tags = "brinda, tosca") {
41
42             dsl("device-properties", """{
43                   "type": "basic-auth",
44                   "host": { "get_input": "hostname"  },
45                   "username": { "get_input": "username" },
46                   "password": { "get_input": "password" }
47                 }""".trimIndent())
48
49             topologyTemplate {
50
51                 workflow(id = "check", description = "CLI Check Workflow") {
52                     inputs {
53                         property(id = "hostname", type = "string", required = true, description = "")
54                         property(id = "username", type = "string", required = true, description = "")
55                         property(id = "password", type = "string", required = true, description = "")
56                         property(id = "data", type = "json", required = true, description = "")
57                     }
58                     outputs {
59                         property(id = "status", required = true, type = "string", description = "") {
60                             value("success")
61                         }
62                     }
63                     step(id = "check", target = "check", description = "Calling check script node")
64                 }
65
66                 val checkComponent = BluePrintTypes.nodeTemplateComponentScriptExecutor(id = "check", description = "") {
67                     definedOperation(description = "") {
68                         inputs {
69                             type("kotlin")
70                             scriptClassReference("cba.capability.cli.Check")
71                         }
72                         outputs {
73                             status(getAttribute("status"))
74                             responseData("""{ "data" : "Here I am "}""")
75                         }
76                     }
77                     artifact(id = "command-template", type = "artifact-template-velocity",
78                             file = "Templates/check-command-template.vtl")
79                 }
80                 nodeTemplate(checkComponent)
81             }
82
83             artifactType(BluePrintTypes.artifactTypeTemplateVelocity())
84             nodeType(BluePrintTypes.nodeTypeComponent())
85             nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
86
87         }