612a57d23891fe62d6232ad5d41e49ef69d62f4a
[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.message
18
19 import org.apache.kafka.streams.StreamsConfig
20 import org.junit.Test
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
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 MessagePropertiesDSLTest {
28
29     @Test
30     fun testScramSslMessageProducerDSL() {
31         val serviceTemplate = serviceTemplate("message-properties-test", "1.0.0", "xxx.@xx.com", "message") {
32             topologyTemplate {
33                 relationshipTemplateMessageProducer("sample-scram-ssl-auth", "Message Producer") {
34                     kafkaScramSslAuth {
35                         bootstrapServers("sample-bootstrapServers")
36                         clientId("sample-client-id")
37                         acks("all")
38                         retries(3)
39                         enableIdempotence(true)
40                         topic("sample-topic")
41                         truststore("/path/to/truststore.jks")
42                         truststorePassword("secretpassword")
43                         truststoreType("JKS")
44                         keystore("/path/to/keystore.jks")
45                         keystorePassword("secretpassword")
46                         keystoreType("JKS")
47                         sslEndpointIdentificationAlgorithm("")
48                         saslMechanism("SCRAM-SHA-512")
49                         scramUsername("sample-user")
50                         scramPassword("secretpassword")
51                     }
52                 }
53             }
54             relationshipTypeConnectsToMessageProducer()
55             relationshipTypeConnectsTo()
56         }
57
58         // println(serviceTemplate.asJsonString(true))
59         assertNotNull(serviceTemplate, "failed to create service template")
60         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
61         assertNotNull(relationshipTemplates, "failed to get relationship templates")
62         assertEquals(1, relationshipTemplates.size, "relationshipTemplates doesn't match")
63         assertNotNull(relationshipTemplates["sample-scram-ssl-auth"], "failed to get sample-scram-ssl-auth")
64
65         val relationshipTypes = serviceTemplate.relationshipTypes
66         assertNotNull(relationshipTypes, "failed to get relationship types")
67         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
68         assertNotNull(
69                 relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
70                 "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
71         )
72         assertNotNull(
73                 relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER],
74                 "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER}"
75         )
76     }
77
78     @Test
79     fun testScramSslAuthMessageConsumerDSL() {
80         val serviceTemplate = serviceTemplate("message-properties-test", "1.0.0", "xxx.@xx.com", "message") {
81             topologyTemplate {
82                 relationshipTemplateMessageConsumer("sample-scram-ssl-auth", "Message Consumer") {
83                     kafkaScramSslAuth {
84                         bootstrapServers("sample-bootstrapServers")
85                         clientId("sample-client-id")
86                         groupId("sample-group-id")
87                         topic("sample-topic")
88                         autoCommit(false)
89                         autoOffsetReset("latest")
90                         pollMillSec(5000)
91                         pollRecords(20)
92                         truststore("/path/to/truststore.jks")
93                         truststorePassword("secretpassword")
94                         truststoreType("JKS")
95                         keystore("/path/to/keystore.jks")
96                         keystorePassword("secretpassword")
97                         keystoreType("JKS")
98                         sslEndpointIdentificationAlgorithm("")
99                         saslMechanism("SCRAM-SHA-512")
100                         scramUsername("sample-user")
101                         scramPassword("secretpassword")
102                     }
103                 }
104                 relationshipTemplateMessageConsumer("sample-stream-scram-ssl-auth", "Message Consumer") {
105                     kafkaStreamsScramSslAuth {
106                         bootstrapServers("sample-bootstrapServers")
107                         applicationId("sample-application-id")
108                         autoOffsetReset("latest")
109                         processingGuarantee(StreamsConfig.EXACTLY_ONCE)
110                         topic("sample-streaming-topic")
111                         truststore("/path/to/truststore.jks")
112                         truststorePassword("secretpassword")
113                         truststoreType("JKS")
114                         keystore("/path/to/keystore.jks")
115                         keystorePassword("secretpassword")
116                         keystoreType("JKS")
117                         sslEndpointIdentificationAlgorithm("")
118                         saslMechanism("SCRAM-SHA-512")
119                         scramUsername("sample-user")
120                         scramPassword("secretpassword")
121                     }
122                 }
123             }
124             relationshipTypeConnectsToMessageConsumer()
125             relationshipTypeConnectsTo()
126         }
127
128         // println(serviceTemplate.asJsonString(true))
129         assertNotNull(serviceTemplate, "failed to create service template")
130         val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
131         assertNotNull(relationshipTemplates, "failed to get relationship templates")
132         assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match")
133         assertNotNull(relationshipTemplates["sample-scram-ssl-auth"], "failed to get sample-scram-ssl-auth")
134         assertNotNull(relationshipTemplates["sample-stream-scram-ssl-auth"], "failed to get sample-stream-scram-ssl-auth")
135
136         val relationshipTypes = serviceTemplate.relationshipTypes
137         assertNotNull(relationshipTypes, "failed to get relationship types")
138         assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match")
139         assertNotNull(
140             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO],
141             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}"
142         )
143         assertNotNull(
144             relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER],
145             "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER}"
146         )
147     }
148 }