Add netconf script component function
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / rest-lib / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / rest / service / RestClientServiceTest.kt
1 /*
2  * Copyright © 2017-2018 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.apps.blueprintsprocessor.rest.service
18
19 import org.junit.runner.RunWith
20 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
22 import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration
23 import org.springframework.beans.factory.annotation.Autowired
24 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
25 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
26 import org.springframework.boot.test.context.SpringBootTest
27 import org.springframework.test.context.ContextConfiguration
28 import org.springframework.test.context.TestPropertySource
29 import org.springframework.test.context.junit4.SpringRunner
30 import org.springframework.web.bind.annotation.GetMapping
31 import org.springframework.web.bind.annotation.RequestMapping
32 import org.springframework.web.bind.annotation.RestController
33 import kotlin.test.Test
34 import kotlin.test.assertNotNull
35
36 @RunWith(SpringRunner::class)
37 @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
38 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
39 @ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class,
40     SampleController::class, BluePrintProperties::class])
41 @TestPropertySource(properties =
42 ["server.port=9111",
43     "blueprintsprocessor.restclient.sample.type=basic-auth",
44     "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:9111",
45     "blueprintsprocessor.restclient.sample.userId=sampleuser",
46     "blueprintsprocessor.restclient.sample.token=sampletoken"])
47 class RestClientServiceTest {
48
49     @Autowired
50     lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
51
52     @Test
53     fun testBaseAuth() {
54
55         val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample")
56         val headers = mutableMapOf<String, String>()
57         headers["X-Transaction-Id"] = "1234"
58         val response = restClientService.getResource("/sample/name", headers, String::class.java)
59         assertNotNull(response, "failed to get response")
60     }
61
62 }
63
64 @RestController
65 @RequestMapping("/sample")
66 open class SampleController {
67     @GetMapping("/name")
68     fun getName(): String = "Sample Controller"
69 }
70