2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Copyright (C) 2019 Nordix Foundation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
20 package org.onap.ccsdk.apps.blueprintsprocessor.rest.service
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
24 import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
25 import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration
26 import org.springframework.beans.factory.annotation.Autowired
27 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
28 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
29 import org.springframework.boot.test.context.SpringBootTest
30 import org.springframework.http.HttpMethod
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.test.context.TestPropertySource
33 import org.springframework.test.context.junit4.SpringRunner
34 import org.springframework.web.bind.annotation.GetMapping
35 import org.springframework.web.bind.annotation.PatchMapping
36 import org.springframework.web.bind.annotation.RequestMapping
37 import org.springframework.web.bind.annotation.RestController
38 import kotlin.test.Test
39 import kotlin.test.assertEquals
40 import kotlin.test.assertNotNull
42 @RunWith(SpringRunner::class)
43 @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
44 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
45 @ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class,
46 SampleController::class, BluePrintProperties::class, BluePrintProperties::class])
47 @TestPropertySource(properties =
48 ["blueprintsprocessor.restclient.sample.type=basic-auth",
49 "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8080",
50 "blueprintsprocessor.restclient.sample.username=sampleuser",
51 "blueprintsprocessor.restclient.sample.password=sampletoken"])
52 class RestClientServiceTest {
55 lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
59 val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample")
60 val headers = mutableMapOf<String, String>()
61 headers["X-Transaction-Id"] = "1234"
62 val response = restClientService.exchangeResource(HttpMethod.GET.name, "/sample/name", "")
63 assertNotNull(response, "failed to get response")
68 val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample")
69 val response = restClientService.exchangeResource(HttpMethod.PATCH.name, "/sample/name", "")
70 assertEquals("Patch request successful", response, "failed to get patch response")
76 @RequestMapping("/sample")
77 open class SampleController {
79 fun getName(): String = "Sample Controller"
80 @PatchMapping("/name")
81 fun patchName(): String = "Patch request successful"