Merge "Resource resolution should return a string"
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / test / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / annotations / BluePrintsAnnotationsTest.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.controllerblueprints.core.annotations
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.asBluePrintsDataTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.asPropertyDefinitionMap
22 import kotlin.test.Test
23 import kotlin.test.assertNotNull
24
25 class BluePrintsAnnotationsTest {
26
27     @Test
28     fun testBluePrintWorkflowData() {
29         val wfInput = TestBluePrintsWorkflowInput::class.asPropertyDefinitionMap()
30         //println(wfInput.asJsonString(true))
31         assertNotNull(wfInput, "failed to generate wfInput property map")
32
33         val wfOutput = TestBluePrintsWorkflowOutput::class.asPropertyDefinitionMap()
34         //println(wfOutput.asJsonString(true))
35         assertNotNull(wfInput, "failed to generate wfOutput property map")
36     }
37
38     @Test
39     fun testBluePrintDataType() {
40         val dataTypes = TestBluePrintsDataType::class.asBluePrintsDataTypes()
41         //println(dataTypes.asJsonString(true))
42         assertNotNull(dataTypes, "failed to generate dataTypes definition")
43     }
44 }
45
46 @BluePrintsDataType(name = "dt-test-datatype", description = "I am test",
47         version = "1.0.0", derivedFrom = "tosca.datatypes.root")
48 data class TestBluePrintsDataType(
49         @BluePrintsProperty(description = "this stringData")
50         var stringData: String,
51         @BluePrintsProperty(description = "this stringDataWithValue")
52         @PropertyDefaultValue(value = "USA")
53         val stringDataWithValue: String,
54         @BluePrintsProperty(description = "this intDataWithValue")
55         @PropertyDefaultValue(value = "30")
56         val intDataWithValue: Int,
57         @BluePrintsProperty(description = "this booleanDataWithValue")
58         @PropertyDefaultValue(value = "true")
59         val booleanDataWithValue: Boolean,
60         @BluePrintsProperty(description = "this anyData")
61         val anyData: Any,
62         @BluePrintsProperty(description = "this jsonDataWithValue")
63         @PropertyDefaultValue(value = """{"data" : "1234"}""")
64         val jsonDataWithValue: JsonNode?,
65         @BluePrintsProperty(description = "listData")
66         val listData: MutableList<String>,
67         @BluePrintsProperty(description = "this mapData")
68         val mapData: MutableMap<String, String> = hashMapOf(),
69         @BluePrintsProperty(description = "this complexData")
70         val complexData: TestBluePrintsChildDataType?,
71         @BluePrintsProperty(description = "this complexDataList")
72         val complexDataList: MutableList<TestBluePrintsChildDataType>
73 )
74
75 data class TestBluePrintsChildDataType(val name: String)
76
77
78 @BluePrintsWorkflowInput
79 data class TestBluePrintsWorkflowInput(
80         @BluePrintsProperty(description = "this sample name")
81         @PropertyDefaultValue(value = "Brinda")
82         var name: String,
83         @BluePrintsProperty(description = "this sample name")
84         val place: String
85 )
86
87 @BluePrintsWorkflowOutput
88 data class TestBluePrintsWorkflowOutput(
89         @BluePrintsProperty(description = "this is dslExpression")
90         @DSLExpression("field1")
91         var dslExpression: String,
92
93         @BluePrintsProperty(description = "this is withNodeAttributeExpression")
94         @AttributeExpression(modelableEntityName = "sample-node", attributeName = "response-data")
95         var withNodeAttributeExpression: String,
96
97         @BluePrintsProperty(description = "this is withNodeAttributeExpressionSubAttribute")
98         @AttributeExpression(modelableEntityName = "sample-node", attributeName = "response-data",
99                 subAttributeName = ".\$field1")
100         var withNodeAttributeExpressionSubAttribute: String,
101
102         @BluePrintsProperty(description = "this is withAttributeExpressionSubAttribute")
103         @AttributeExpression(attributeName = "response-data", subAttributeName = ".\$field1")
104         var withAttributeExpressionSubAttribute: String,
105
106         @BluePrintsProperty(description = "this is withAttributeExpression")
107         @AttributeExpression(attributeName = "response-data")
108         var withAttributeExpression: String,
109
110         @BluePrintsProperty(description = "this is withAArtifactExpression")
111         @ArtifactExpression(modelableEntityName = "test-node", artifactName = "content-template")
112         var withAArtifactExpression: String,
113
114         @BluePrintsProperty(description = "this status")
115         val status: String = "success"
116 )