2 * Copyright © 2017-2018 AT&T Intellectual Property.
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.apps.blueprintsprocessor.rest.service
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.http.HttpMethod
28 import org.springframework.test.context.ContextConfiguration
29 import org.springframework.test.context.TestPropertySource
30 import org.springframework.test.context.junit4.SpringRunner
31 import org.springframework.web.bind.annotation.GetMapping
32 import org.springframework.web.bind.annotation.RequestMapping
33 import org.springframework.web.bind.annotation.RestController
34 import kotlin.test.Test
35 import kotlin.test.assertNotNull
37 @RunWith(SpringRunner::class)
38 @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
39 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
40 @ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class,
41 SampleController::class, BluePrintProperties::class, BluePrintProperties::class])
42 @TestPropertySource(properties =
43 ["blueprintsprocessor.restclient.sample.type=basic-auth",
44 "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8080",
45 "blueprintsprocessor.restclient.sample.username=sampleuser",
46 "blueprintsprocessor.restclient.sample.password=sampletoken"])
47 class RestClientServiceTest {
50 lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
54 val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample")
55 val headers = mutableMapOf<String, String>()
56 headers["X-Transaction-Id"] = "1234"
57 val response = restClientService.exchangeResource(HttpMethod.GET.name, "/sample/name", "")
58 assertNotNull(response, "failed to get response")
64 @RequestMapping("/sample")
65 open class SampleController {
67 fun getName(): String = "Sample Controller"