2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
4 * Modifications Copyright © 2019 Huawei.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.rest.service
21 import com.fasterxml.jackson.databind.JsonNode
22 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties
29 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLRestClientProperties
30 import org.onap.ccsdk.cds.blueprintsprocessor.rest.SSLTokenAuthRestClientProperties
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
35 import kotlin.test.assertEquals
36 import kotlin.test.assertNotNull
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class])
40 @TestPropertySource(properties =
41 ["blueprintsprocessor.restclient.sample.type=basic-auth",
42 "blueprintsprocessor.restclient.sample.url=http://localhost:8080",
43 "blueprintsprocessor.restclient.sample.userId=sampleuser",
44 "blueprintsprocessor.restclient.sslbasic.type=ssl-basic-auth",
45 "blueprintsprocessor.restclient.sslbasic.url=https://localhost:8443",
46 "blueprintsprocessor.restclient.sslbasic.username=admin",
47 "blueprintsprocessor.restclient.sslbasic.password=cds",
48 "blueprintsprocessor.restclient.sslbasic.keyStoreInstance=PKCS12",
49 "blueprintsprocessor.restclient.sslbasic.sslTrust=src/test/resources/keystore.p12",
50 "blueprintsprocessor.restclient.sslbasic.sslTrustPassword=changeit",
51 "blueprintsprocessor.restclient.ssltoken.type=ssl-token-auth",
52 "blueprintsprocessor.restclient.ssltoken.url=https://localhost:8443",
53 "blueprintsprocessor.restclient.ssltoken.token=72178473kjshdkjgvbsdkjv903274908",
54 "blueprintsprocessor.restclient.ssltoken.keyStoreInstance=PKCS12",
55 "blueprintsprocessor.restclient.ssltoken.sslTrust=src/test/resources/keystore.p12",
56 "blueprintsprocessor.restclient.ssltoken.sslTrustPassword=changeit",
57 "blueprintsprocessor.restclient.ssl.type=ssl-no-auth",
58 "blueprintsprocessor.restclient.ssl.url=https://localhost:8443",
59 "blueprintsprocessor.restclient.ssl.keyStoreInstance=PKCS12",
60 "blueprintsprocessor.restclient.ssl.sslTrust=src/test/resources/keystore.p12",
61 "blueprintsprocessor.restclient.ssl.sslTrustPassword=changeit",
62 "blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12",
63 "blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit"
66 class BluePrintRestLibPropertyServiceTest {
69 lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
72 fun testRestClientProperties() {
73 val properties = bluePrintRestLibPropertyService.restClientProperties(
74 "blueprintsprocessor.restclient.sample")
75 assertNotNull(properties, "failed to create property bean")
76 assertNotNull(properties.url, "failed to get url property in" +
81 fun testSSLBasicProperties() {
82 val properties = bluePrintRestLibPropertyService.restClientProperties(
83 "blueprintsprocessor.restclient.sslbasic")
84 assertNotNull(properties, "failed to create property bean")
85 val p: SSLBasicAuthRestClientProperties =
86 properties as SSLBasicAuthRestClientProperties
88 assertEquals(p.basicAuth!!.username, "admin")
89 assertEquals(p.basicAuth!!.password, "cds")
90 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
91 assertEquals(p.sslTrustPassword, "changeit")
92 assertEquals(p.keyStoreInstance, "PKCS12")
96 fun testSSLTokenProperties() {
97 val properties = bluePrintRestLibPropertyService.restClientProperties(
98 "blueprintsprocessor.restclient.ssltoken")
99 assertNotNull(properties, "failed to create property bean")
101 val p: SSLTokenAuthRestClientProperties =
102 properties as SSLTokenAuthRestClientProperties
104 assertEquals(p.tokenAuth!!.token!!, "72178473kjshdkjgvbsdkjv903274908")
105 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
106 assertEquals(p.sslTrustPassword, "changeit")
107 assertEquals(p.keyStoreInstance, "PKCS12")
111 fun testSSLNoAuthProperties() {
112 val properties = bluePrintRestLibPropertyService.restClientProperties(
113 "blueprintsprocessor.restclient.ssl")
114 assertNotNull(properties, "failed to create property bean")
116 val p: SSLRestClientProperties =
117 properties as SSLRestClientProperties
119 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
120 assertEquals(p.sslTrustPassword, "changeit")
121 assertEquals(p.keyStoreInstance, "PKCS12")
122 assertEquals(p.sslKey, "src/test/resources/keystore.p12")
123 assertEquals(p.sslKeyPassword, "changeit")
128 fun testSSLBasicPropertiesAsJson() {
129 val json: String = "{\n" +
130 " \"type\" : \"ssl-basic-auth\",\n" +
131 " \"url\" : \"https://localhost:8443\",\n" +
132 " \"keyStoreInstance\" : \"PKCS12\",\n" +
133 " \"sslTrust\" : \"src/test/resources/keystore.p12\",\n" +
134 " \"sslTrustPassword\" : \"changeit\",\n" +
135 " \"basicAuth\" : {\n" +
136 " \"username\" : \"admin\",\n" +
137 " \"password\" : \"cds\"\n" +
140 val mapper = ObjectMapper()
141 val actualObj: JsonNode = mapper.readTree(json)
142 val properties = bluePrintRestLibPropertyService.restClientProperties(
144 assertNotNull(properties, "failed to create property bean")
145 val p: SSLBasicAuthRestClientProperties =
146 properties as SSLBasicAuthRestClientProperties
148 assertEquals(p.basicAuth!!.username, "admin")
149 assertEquals(p.basicAuth!!.password, "cds")
150 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
151 assertEquals(p.sslTrustPassword, "changeit")
152 assertEquals(p.keyStoreInstance, "PKCS12")
156 fun testSSLTokenPropertiesAsJson() {
157 val json: String = "{\n" +
158 " \"type\" : \"ssl-token-auth\",\n" +
159 " \"url\" : \"https://localhost:8443\",\n" +
160 " \"keyStoreInstance\" : \"PKCS12\",\n" +
161 " \"sslTrust\" : \"src/test/resources/keystore.p12\",\n" +
162 " \"sslTrustPassword\" : \"changeit\",\n" +
163 " \"tokenAuth\" : {\n" +
164 " \"token\" : \"72178473kjshdkjgvbsdkjv903274908\"\n" +
167 val mapper = ObjectMapper()
168 val actualObj: JsonNode = mapper.readTree(json)
169 val properties = bluePrintRestLibPropertyService.restClientProperties(
171 assertNotNull(properties, "failed to create property bean")
173 val p: SSLTokenAuthRestClientProperties =
174 properties as SSLTokenAuthRestClientProperties
176 assertEquals(p.tokenAuth!!.token!!, "72178473kjshdkjgvbsdkjv903274908")
177 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
178 assertEquals(p.sslTrustPassword, "changeit")
179 assertEquals(p.keyStoreInstance, "PKCS12")
183 fun testSSLNoAuthPropertiesAsJson() {
184 val json: String = "{\n" +
185 " \"type\" : \"ssl-basic-auth\",\n" +
186 " \"url\" : \"https://localhost:8443\",\n" +
187 " \"keyStoreInstance\" : \"PKCS12\",\n" +
188 " \"sslTrust\" : \"src/test/resources/keystore.p12\",\n" +
189 " \"sslTrustPassword\" : \"changeit\",\n" +
190 " \"sslKey\" : \"src/test/resources/keystore.p12\",\n" +
191 " \"sslKeyPassword\" : \"changeit\"\n" +
193 val mapper = ObjectMapper()
194 val actualObj: JsonNode = mapper.readTree(json)
195 val properties = bluePrintRestLibPropertyService.restClientProperties(
197 assertNotNull(properties, "failed to create property bean")
199 val p: SSLRestClientProperties =
200 properties as SSLRestClientProperties
202 assertEquals(p.sslTrust, "src/test/resources/keystore.p12")
203 assertEquals(p.sslTrustPassword, "changeit")
204 assertEquals(p.keyStoreInstance, "PKCS12")
205 assertEquals(p.sslKey, "src/test/resources/keystore.p12")
206 assertEquals(p.sslKeyPassword, "changeit")
210 fun testBlueprintWebClientService() {
211 val blueprintWebClientService = bluePrintRestLibPropertyService
212 .blueprintWebClientService("sample")
213 assertNotNull(blueprintWebClientService, "failed to create blu" +
214 "eprintWebClientService")