Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceDefinitionDSLTest.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 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.assertEquals
22 import kotlin.test.assertNotNull
23
24 class ResourceDefinitionDSLTest {
25
26     @Test
27     fun testResourceDefinitionDSL() {
28         val testResourceDefinition = BlueprintTypes.resourceDefinition(
29             "service-instance-id",
30             "VFW Service Instance Name"
31         ) {
32             tags("service-instance-name, vfw, resources")
33             updatedBy("brindasanth@onap.com")
34             property("string", true)
35             sources {
36                 sourceInput("input", "") {}
37                 sourceDefault("default", "") {}
38                 sourceDb("sdnctl", "") {
39                     definedProperties {
40                         type("SQL")
41                         query("SELECT name FROM SERVICE_INSTANCE WHERE id = \$id")
42                         endpointSelector("db-source-endpoint")
43                         inputKeyMapping {
44                             map("id", "\$service-instance-id")
45                         }
46                         outputKeyMapping {
47                             map("service-instance-name", "\$name")
48                         }
49                         keyDependencies(arrayListOf("service-instance-id"))
50                     }
51                 }
52                 sourceRest("odl-mdsal", "") {
53                     definedProperties {
54                         type("JSON")
55                         endpointSelector("rest-source-endpoint")
56                         expressionType("JSON_PATH")
57                         urlPath("/service-instance/\$id")
58                         path(".\$name")
59                         verb("GET")
60                         payload("sample payload")
61                         inputKeyMapping {
62                             map("id", "\$service-instance-id")
63                         }
64                         outputKeyMapping {
65                             map("service-instance-name", "\$name")
66                         }
67                         keyDependencies(arrayListOf("service-instance-id"))
68                     }
69                 }
70                 sourceCapability("custom-component", "") {
71                     definedProperties {
72                         type("kotlin")
73                         scriptClassReference("Scripts/ServiceInstance.kt")
74                         keyDependencies(arrayListOf("service-instance-id"))
75                     }
76                 }
77             }
78         }
79         // println(resourceDefinition.asJsonString(true))
80         assertNotNull(testResourceDefinition, "failed to generate testResourceDefinition")
81
82         val testResourceDefinitions = BlueprintTypes.resourceDefinitions {
83             resourceDefinition(testResourceDefinition)
84         }
85         assertNotNull(testResourceDefinitions, "failed to generate testResourceDefinitions")
86         assertEquals(1, testResourceDefinitions.size, "testResourceDefinitions size doesn't match")
87     }
88
89     @Test
90     fun testResourceAssignment() {
91         val testResourceAssignment = BlueprintTypes.resourceAssignment(
92             "instance-name",
93             "service-instance-name", "odl-mdsal"
94         ) {
95             inputParameter(true)
96             property("string", true)
97             dependencies(arrayListOf("service-instance-id"))
98         }
99         // println(resourceAssignment.asJsonString(true))
100         assertNotNull(testResourceAssignment, "failed to generate resourceAssignment")
101
102         val testResourceAssignments = BlueprintTypes.resourceAssignments {
103             resourceAssignment(testResourceAssignment)
104             resourceAssignment(
105                 "instance-name1",
106                 "service-instance-name", "odl-mdsal"
107             ) {
108                 inputParameter(true)
109                 property("string", true)
110                 dependencies(arrayListOf("service-instance-id"))
111             }
112         }
113         // println(testResourceAssignments.asJsonString(true))
114         assertNotNull(testResourceAssignments, "failed to generate testResourceAssignments")
115         assertEquals(2, testResourceAssignments.size, "testResourceAssignments size doesn't match")
116     }
117 }