4cf474b93b022a21334f9981b24c89948b1a9486
[ccsdk/cds.git] /
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.nats
18
19 import org.junit.Test
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
21 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getInput
22 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
23 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
24 import kotlin.test.assertEquals
25 import kotlin.test.assertNotNull
26
27 class NatsPropertiesDSLTest {
28
29     @Test
30     fun testNatsPropertiesDSL() {
31         val serviceTemplate = serviceTemplate("nats-dsl", "1.0.0", "xx@xx.com", "nats") {
32             topologyTemplate {
33                 relationshipTemplateNats("sample-token-auth", "Nats TokenAuth endpoint") {
34                     tokenAuth {
35                         host("nats://localhost:4222")
36                         token("tokenAuth")
37                         monitoringSelector(getInput("monitoringUrl"))
38                     }
39                 }
40                 relationshipTemplateNats("sample-tls-auth", "Nats TLS endpoint.") {
41                     tlsAuth {
42                         host("nats://localhost:4222")
43                     }
44                 }
45             }
46
47             relationshipTypes(
48                 arrayListOf(
49                     BluePrintTypes.relationshipTypeConnectsToNats(),
50                     BluePrintTypes.relationshipTypeConnectsTo()
51                 )
52             )
53         }
54
55         assertNotNull(serviceTemplate, "failed to create service template")
56         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
57         assertNotNull(relationshipTemplates, "failed to get relationship templates")
58         assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match")
59         assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
60         assertNotNull(relationshipTemplates["sample-tls-auth"], "failed to get sample-tls-auth")
61         // println(serviceTemplate.asJsonString(true))
62     }
63 }