9b3cf80bc086d84b8c65aaff523081a31ac90d22
[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.BluePrintTypes
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             relationshipTypes(
48                 arrayListOf(
49                     BluePrintTypes.relationshipTypeConnectsToGrpcServer(),
50                     BluePrintTypes.relationshipTypeConnectsTo()
51                 )
52             )
53         }
54         assertNotNull(serviceTemplate, "failed to create service template")
55         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
56         assertNotNull(relationshipTemplates, "failed to get relationship templates")
57         assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match")
58         assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth")
59         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
60         // println(serviceTemplate.asJsonString(true))
61     }
62
63     @Test
64     fun testGrpcClientPropertiesDSL() {
65         val serviceTemplate = serviceTemplate("grpc-properties-test", "1.0.0", "xxx.@xx.com", "grpc") {
66             topologyTemplate {
67                 relationshipTemplateGrpcClient("sample-tls-auth", "Grpc Server") {
68                     tlsAuth {
69                         host("localhost")
70                         port(40002)
71                         clientCertChain("sample-certchains")
72                         clientPrivateKey("sample-private-key")
73                         trustCertCollection("sample-trust-cert-collection")
74                     }
75                 }
76                 relationshipTemplateGrpcClient("sample-basic-auth", "Grpc Server") {
77                     basicAuth {
78                         host("localhost")
79                         port(40002)
80                         username("sample-user")
81                         password("credential")
82                     }
83                 }
84                 relationshipTemplateGrpcClient("sample-token-auth", "Grpc Server") {
85                     tokenAuth {
86                         host("localhost")
87                         port(40002)
88                         token("sample-token")
89                     }
90                 }
91             }
92             relationshipTypes(
93                 arrayListOf(
94                     BluePrintTypes.relationshipTypeConnectsToGrpcClient(),
95                     BluePrintTypes.relationshipTypeConnectsTo()
96                 )
97             )
98         }
99         assertNotNull(serviceTemplate, "failed to create service template")
100         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
101         assertNotNull(relationshipTemplates, "failed to get relationship templates")
102         assertEquals(3, relationshipTemplates.size, "relationshipTemplates doesn't match")
103         assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth")
104         assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth")
105         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
106         // println(serviceTemplate.asJsonString(true))
107     }
108 }