Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / rest-lib / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / rest / service / RestClientPropertiesDSLTest.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.rest.service
18
19 import org.junit.Test
20 import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTemplateRestClient
21 import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTypeConnectsToRestClient
22 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
24 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
25 import kotlin.test.assertEquals
26 import kotlin.test.assertNotNull
27
28 class RestClientPropertiesDSLTest {
29
30     @Test
31     fun testRestClientProperties() {
32
33         val serviceTemplate = serviceTemplate("rest-properties-test", "1.0.0", "xxx.@xx.com", "rest") {
34             topologyTemplate {
35                 relationshipTemplateRestClient("sample-basic-auth", "") {
36                     basicAuth {
37                         url("http://localhost:8080")
38                         username("xxxxx")
39                         password("******")
40                     }
41                 }
42                 relationshipTemplateRestClient("sample-token-auth", "") {
43                     tokenAuth {
44                         url("http://localhost:8080")
45                         token("sdfgfsadgsgf")
46                     }
47                 }
48                 relationshipTemplateRestClient("sample-ssl-auth", "") {
49                     sslAuth {
50                         url("http://localhost:8080")
51                         keyStoreInstance("instance")
52                         sslTrust("sample-trust")
53                         sslTrustPassword("sample-trust-password")
54                         sslKey("sample-sslkey")
55                         sslKeyPassword("sample-key-password")
56                     }
57                 }
58             }
59             relationshipTypeConnectsToRestClient()
60             relationshipTypeConnectsTo()
61         }
62
63         // println(serviceTemplate.asJsonString(true))
64         assertNotNull(serviceTemplate, "failed to create service template")
65         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
66         assertNotNull(relationshipTemplates, "failed to get relationship templates")
67         assertEquals(3, relationshipTemplates.size, "relationshipTemplates doesn't match")
68         assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth")
69         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
70         assertNotNull(relationshipTemplates["sample-ssl-auth"], "failed to get sample-ssl-auth")
71
72         val relationshipTypes = serviceTemplate.relationshipTypes
73         assertNotNull(relationshipTypes, "failed to get relationship types")
74         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
75         assertNotNull(
76             relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
77             "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
78         )
79         assertNotNull(
80             relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT],
81             "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT}"
82         )
83     }
84 }