Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / grpc-lib / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / grpc / GrpcPropertiesDSLTest.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
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.grpc
18
19 import org.junit.Test
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
22 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
23 import kotlin.test.assertEquals
24 import kotlin.test.assertNotNull
25
26 class GrpcPropertiesDSLTest {
27
28     @Test
29     fun testGrpcServerPropertiesDSL() {
30         val serviceTemplate = serviceTemplate("grpc-properties-test", "1.0.0", "xxx.@xx.com", "grpc") {
31             topologyTemplate {
32                 relationshipTemplateGrpcServer("sample-tls-auth", "Grpc Server") {
33                     tlsAuth {
34                         port(40002)
35                         certChain("sample-cert-chains")
36                         privateKey("sample-private-key")
37                         trustCertCollection("sample-trust-cert-collection")
38                     }
39                 }
40                 relationshipTemplateGrpcServer("sample-token-auth", "Grpc Server") {
41                     tokenAuth {
42                         port(40002)
43                         token("sample-token")
44                     }
45                 }
46             }
47             relationshipTypeConnectsToGrpcServer()
48             relationshipTypeConnectsTo()
49         }
50
51         // println(serviceTemplate.asJsonString(true))
52         assertNotNull(serviceTemplate, "failed to create service template")
53         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
54         assertNotNull(relationshipTemplates, "failed to get relationship templates")
55         assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match")
56         assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth")
57         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
58
59         val relationshipTypes = serviceTemplate.relationshipTypes
60         assertNotNull(relationshipTypes, "failed to get relationship types")
61         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
62         assertNotNull(
63             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
64             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
65         )
66         assertNotNull(
67             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER],
68             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_SERVER}"
69         )
70     }
71
72     @Test
73     fun testGrpcClientPropertiesDSL() {
74         val serviceTemplate = serviceTemplate("grpc-properties-test", "1.0.0", "xxx.@xx.com", "grpc") {
75             topologyTemplate {
76                 relationshipTemplateGrpcClient("sample-tls-auth", "Grpc Server") {
77                     tlsAuth {
78                         host("localhost")
79                         port(40002)
80                         clientCertChain("sample-certchains")
81                         clientPrivateKey("sample-private-key")
82                         trustCertCollection("sample-trust-cert-collection")
83                     }
84                 }
85                 relationshipTemplateGrpcClient("sample-basic-auth", "Grpc Server") {
86                     basicAuth {
87                         host("localhost")
88                         port(40002)
89                         username("sample-user")
90                         password("credential")
91                     }
92                 }
93                 relationshipTemplateGrpcClient("sample-token-auth", "Grpc Server") {
94                     tokenAuth {
95                         host("localhost")
96                         port(40002)
97                         token("sample-token")
98                     }
99                 }
100             }
101             relationshipTypeConnectsToGrpcClient()
102             relationshipTypeConnectsTo()
103         }
104
105         // println(serviceTemplate.asJsonString(true))
106         assertNotNull(serviceTemplate, "failed to create service template")
107         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
108         assertNotNull(relationshipTemplates, "failed to get relationship templates")
109         assertEquals(3, relationshipTemplates.size, "relationshipTemplates doesn't match")
110         assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth")
111         assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth")
112         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
113
114         val relationshipTypes = serviceTemplate.relationshipTypes
115         assertNotNull(relationshipTypes, "failed to get relationship types")
116         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
117         assertNotNull(
118             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
119             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
120         )
121         assertNotNull(
122             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT],
123             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_GRPC_CLIENT}"
124         )
125     }
126 }