2 * Copyright © 2019 Bell Canada.
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.configs.api
19 import kotlinx.coroutines.runBlocking
21 import org.junit.runner.RunWith
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
24 import org.slf4j.LoggerFactory
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
27 import org.springframework.context.annotation.ComponentScan
28 import org.springframework.http.MediaType
29 import org.springframework.test.context.ContextConfiguration
30 import org.springframework.test.context.TestPropertySource
31 import org.springframework.test.context.junit4.SpringRunner
32 import org.springframework.test.web.reactive.server.WebTestClient
33 import org.springframework.web.reactive.function.BodyInserters
35 @RunWith(SpringRunner::class)
37 @ContextConfiguration(
38 classes = [BluePrintCoreConfiguration::class, BluePrintCatalogService::class]
40 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
41 @TestPropertySource(locations = ["classpath:application-test.properties"])
42 class ResourceConfigSnapshotControllerTest {
44 private val log = LoggerFactory.getLogger(ResourceConfigSnapshotControllerTest::class.toString())
47 lateinit var webTestClient: WebTestClient
49 val resourceId = "fcaa6ac3ff08"
50 val resourceType = "PNF"
51 val snapshotData = "PAYLOAD DATA"
53 var requestArguments = "resourceId=$resourceId&resourceType=$resourceType"
56 fun `ping return Success`() {
58 webTestClient.get().uri("/api/v1/configs/health-check")
67 fun `update configuration is allowed and updates timestamp`() {
72 .uri("/api/v1/configs/$resourceType/$resourceId/running")
73 .body(BodyInserters.fromObject(snapshotData))
75 .expectStatus().is2xxSuccessful
77 .jsonPath("$.createdDate")
78 .value<String> { println(it) }
82 .uri("/api/v1/configs/$resourceType/$resourceId/running")
83 .body(BodyInserters.fromObject(snapshotData))
85 .expectStatus().is2xxSuccessful
87 .jsonPath("$.createdDate")
88 .value<String> { println(it) }
93 fun `get returns requested JSON content-type`() {
95 post(resourceType, "22", "RUNNING")
96 get("json", resourceType, "22", "RUNNING")
101 fun `get returns requested XML content-type`() {
103 post(resourceType, "3", "CANDIDATE")
104 get("xml", resourceType, "3", "CANDIDATE")
109 fun `get returns 400 error if missing arg`() {
111 val arguments = "artifactName=WRONGARG1&resolutionKey=WRONGARG1"
113 webTestClient.get().uri("/api/v1/configs?$arguments")
115 .expectStatus().isBadRequest
120 fun `get returns 400 error if wrong Status arg`() {
122 val arguments = "resourceId=MISSING&resourceType=PNF&status=TOTALLY_WRONG"
124 webTestClient.get().uri("/api/v1/configs?$arguments")
126 .expectStatus().isBadRequest
131 fun `get returns 200 if entry not found`() {
136 .uri("/api/v1/configs?resourceId=MISSING&resourceType=PNF")
138 .expectStatus().is2xxSuccessful
143 private fun post(resourceType: String, resourceId: String, status: String) {
146 .uri("/api/v1/configs/$resourceType/$resourceId/$status")
147 .body(BodyInserters.fromObject(snapshotData))
149 .expectStatus().is2xxSuccessful
153 private fun get(expectedType: String, resourceType: String, resourceId: String, status: String) {
154 var requestArguments = "resourceId=$resourceId&resourceType=$resourceType&status=$status"
156 if (expectedType.isNotEmpty()) {
157 requestArguments = "$requestArguments&format=$expectedType"
160 .uri("/api/v1/configs?$requestArguments")
162 .expectStatus().is2xxSuccessful
163 .expectHeader().contentType(MediaType.valueOf("application/$expectedType"))
164 .expectBody().equals(snapshotData)
168 .uri("/api/v1/configs?$requestArguments")
170 .expectStatus().is2xxSuccessful
171 .expectHeader().contentType(MediaType.TEXT_PLAIN)
172 .expectBody().equals(snapshotData)