Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / db-lib / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / db / DatabasePropertiesDSLTest.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.db
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 DatabasePropertiesDSLTest {
27
28     @Test
29     fun testDatabasePropertiesDSL() {
30         val serviceTemplate = serviceTemplate("database-properties-test", "1.0.0", "xxx.@xx.com", "database") {
31             topologyTemplate {
32                 relationshipTemplateDb("sample-maria-db", "Database Server") {
33                     mariaDb {
34                         url("jdbc://mariadb:3600")
35                         username("user")
36                         password("credential")
37                         hibernateDDLAuto("hibernateDDLAuto")
38                         hibernateHbm2ddlAuto("hibernateHbm2ddlAuto")
39                         hibernateDDLAuto("hibernateDDLAuto")
40                         hibernateNamingStrategy("hibernateNamingStrategy")
41                     }
42                 }
43                 relationshipTemplateDb("sample-mysql-db", "Database Server") {
44                     mySqlDb {
45                         url("jdbc://mysql:3600")
46                         username("user")
47                         password("credential")
48                         hibernateDDLAuto("hibernateDDLAuto")
49                         hibernateHbm2ddlAuto("hibernateHbm2ddlAuto")
50                         hibernateDDLAuto("hibernateDDLAuto")
51                         hibernateNamingStrategy("hibernateNamingStrategy")
52                     }
53                 }
54             }
55             relationshipTypeConnectsToDb()
56             relationshipTypeConnectsTo()
57         }
58
59         // println(serviceTemplate.asJsonString(true))
60         assertNotNull(serviceTemplate, "failed to create service template")
61         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
62         assertNotNull(relationshipTemplates, "failed to get relationship templates")
63         assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match")
64         assertNotNull(relationshipTemplates["sample-maria-db"], "failed to get sample-maria-db")
65         assertNotNull(relationshipTemplates["sample-mysql-db"], "failed to get sample-mysql-db")
66
67         val relationshipTypes = serviceTemplate.relationshipTypes
68         assertNotNull(relationshipTypes, "failed to get relationship types")
69         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
70         assertNotNull(
71             relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
72             "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
73         )
74         assertNotNull(
75             relationshipTypes[BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB],
76             "failed to get ${BlueprintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB}"
77         )
78     }
79 }