2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.ObjectMapper
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
25 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties
26 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BluePrintGrpcLibConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.test.context.ContextConfiguration
30 import org.springframework.test.context.TestPropertySource
31 import org.springframework.test.context.junit4.SpringRunner
32 import kotlin.test.assertEquals
33 import kotlin.test.assertNotNull
34 import kotlin.test.assertTrue
36 @RunWith(SpringRunner::class)
37 @ContextConfiguration(classes = [BluePrintGrpcLibConfiguration::class,
38 BlueprintPropertyConfiguration::class, BluePrintProperties::class])
39 @TestPropertySource(properties =
40 ["blueprintsprocessor.grpcclient.sample.type=basic-auth",
41 "blueprintsprocessor.grpcclient.sample.host=127.0.0.1",
42 "blueprintsprocessor.grpcclient.sample.port=50505",
43 "blueprintsprocessor.grpcclient.sample.username=sampleuser",
44 "blueprintsprocessor.grpcclient.sample.password=sampleuser",
45 "blueprintsprocessor.grpcclient.token.type=token-auth",
46 "blueprintsprocessor.grpcclient.token.host=127.0.0.1",
47 "blueprintsprocessor.grpcclient.token.port=50505",
48 "blueprintsprocessor.grpcclient.token.username=sampleuser",
49 "blueprintsprocessor.grpcclient.token.password=sampleuser"
51 class BluePrintGrpcLibPropertyServiceTest {
54 lateinit var bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService
57 * Tests the GRPC client properties with selector for basic auth.
60 fun testGrpcClientProperties() {
61 val properties = bluePrintGrpcLibPropertyService.grpcClientProperties(
62 "blueprintsprocessor.grpcclient.sample")
63 as BasicAuthGrpcClientProperties
64 assertNotNull(properties, "failed to create property bean")
65 assertNotNull(properties.host, "failed to get host property" +
67 assertNotNull(properties.port, "failed to get host property" +
69 assertNotNull(properties.username, "failed to get host pro" +
70 "perty in property bean")
71 assertNotNull(properties.password, "failed to get host pr" +
72 "operty in property bean")
76 * Tests the GRPC client properties with JSON node for token auth.
79 fun testGrpcClientPropertiesWithJson() {
80 val json: String = "{\n" +
81 " \"type\" : \"token-auth\",\n" +
82 " \"host\" : \"127.0.0.1\",\n" +
83 " \"port\" : \"50505\"\n" +
85 val mapper = ObjectMapper()
86 val actualObj: JsonNode = mapper.readTree(json)
87 val properties = bluePrintGrpcLibPropertyService.grpcClientProperties(
88 actualObj) as TokenAuthGrpcClientProperties
89 assertNotNull(properties, "failed to create property bean")
90 assertEquals(properties.host, "127.0.0.1")
91 assertNotNull(properties.port, "50505")
95 * Tests the GRPC client service with selector for basic auth.
98 fun testGrpcClientServiceBasic() {
99 val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(
101 assertTrue(svc is BasicAuthGrpcClientService)
105 * Tests the GRPC client service with selector for token auth.
108 fun testGrpcClientServiceToken() {
109 val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(
111 assertTrue(svc is TokenAuthGrpcClientService)
115 * Tests the GRPC client service with JSON node for basic auth.
118 fun testGrpcClientServiceWithJson() {
119 val json: String = "{\n" +
120 " \"type\" : \"basic-auth\",\n" +
121 " \"host\" : \"127.0.0.1\",\n" +
122 " \"port\" : \"50505\",\n" +
123 " \"username\" : \"sampleuser\",\n" +
124 " \"password\" : \"samplepwd\"\n" +
126 val mapper = ObjectMapper()
127 val actualObj: JsonNode = mapper.readTree(json)
128 val svc = bluePrintGrpcLibPropertyService
129 .blueprintGrpcClientService(actualObj)
130 assertTrue(svc is BasicAuthGrpcClientService)