340b2b3246d92f1d7e5230be47e224d3a8977965
[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.blueprintsprocessor.functions.resource.resolution
18
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
20 import kotlin.test.Test
21 import kotlin.test.assertNotNull
22
23 class ResourceDefinitionSDLTest {
24
25     @Test
26     fun testResourceDefinitionDSL() {
27         val resourceDefinition = BluePrintTypes.resourceDefinition("service-instance-id") {
28             tags("service-instance-name, vfw, resources")
29             updatedBy("brindasanth@onap.com")
30             property("service-instance-name", "string", true, "VFW Service Instance Name")
31             sources {
32                 sourceInput("input", "") {}
33                 sourceDefault("default", "") {}
34                 sourceDb("sdnctl", "") {
35                     definedProperties {
36                         type("SQL")
37                         query("SELECT name FROM SERVICE_INSTANCE WHERE id = \$id")
38                         endpointSelector("db-source-endpoint")
39                         inputKeyMapping {
40                             map("id", "\$service-instance-id")
41                         }
42                         outputKeyMapping {
43                             map("service-instance-name", "\$name")
44                         }
45                         keyDependencies(arrayListOf("service-instance-id"))
46                     }
47                 }
48                 sourceRest("odl-mdsal", "") {
49                     definedProperties {
50                         type("JSON")
51                         endpointSelector("rest-source-endpoint")
52                         expressionType("JSON_PATH")
53                         urlPath("/service-instance/\$id")
54                         path(".\$name")
55                         verb("GET")
56                         payload("sample payload")
57                         inputKeyMapping {
58                             map("id", "\$service-instance-id")
59                         }
60                         outputKeyMapping {
61                             map("service-instance-name", "\$name")
62                         }
63                         keyDependencies(arrayListOf("service-instance-id"))
64                     }
65                 }
66                 sourceCapability("custom-component", "") {
67                     definedProperties {
68                         type("kotlin")
69                         scriptClassReference("Scripts/ServiceInstance.kt")
70                         keyDependencies(arrayListOf("service-instance-id"))
71                     }
72                 }
73             }
74         }
75         //println(resourceDefinition.asJsonString(true))
76         assertNotNull(resourceDefinition, "failed to generate resourceDefinition")
77     }
78 }