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.autoconfigure.security.SecurityProperties
27 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
28 import org.springframework.context.annotation.ComponentScan
29 import org.springframework.http.MediaType
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.TestPropertySource
32 import org.springframework.test.context.junit4.SpringRunner
33 import org.springframework.test.web.reactive.server.WebTestClient
34 import org.springframework.web.reactive.function.BodyInserters
36 @RunWith(SpringRunner::class)
38 @ContextConfiguration(
39 classes = [BluePrintCoreConfiguration::class,
40 BluePrintCatalogService::class, SecurityProperties::class]
42 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
43 @TestPropertySource(locations = ["classpath:application-test.properties"])
44 class ResourceConfigSnapshotControllerTest {
46 private val log = LoggerFactory.getLogger(ResourceConfigSnapshotControllerTest::class.toString())
49 lateinit var webTestClient: WebTestClient
51 val resourceId = "fcaa6ac3ff08"
52 val resourceType = "PNF"
53 val snapshotData = "PAYLOAD DATA"
55 var requestArguments = "resourceId=$resourceId&resourceType=$resourceType"
58 fun `ping return Success`() {
60 webTestClient.get().uri("/api/v1/configs/health-check")
69 fun `update configuration is allowed and updates timestamp`() {
74 .uri("/api/v1/configs/$resourceType/$resourceId/running")
75 .body(BodyInserters.fromObject(snapshotData))
77 .expectStatus().is2xxSuccessful
79 .jsonPath("$.createdDate")
80 .value<String> { println(it) }
84 .uri("/api/v1/configs/$resourceType/$resourceId/running")
85 .body(BodyInserters.fromObject(snapshotData))
87 .expectStatus().is2xxSuccessful
89 .jsonPath("$.createdDate")
90 .value<String> { println(it) }
95 fun `get returns requested JSON content-type`() {
97 post(resourceType, "22", "RUNNING")
98 get("json", resourceType, "22", "RUNNING")
103 fun `get returns requested XML content-type`() {
105 post(resourceType, "3", "CANDIDATE")
106 get("xml", resourceType, "3", "CANDIDATE")
111 fun `get returns 400 error if missing arg`() {
113 val arguments = "artifactName=WRONGARG1&resolutionKey=WRONGARG1"
115 webTestClient.get().uri("/api/v1/configs?$arguments")
117 .expectStatus().isBadRequest
122 fun `get returns 400 error if wrong Status arg`() {
124 val arguments = "resourceId=MISSING&resourceType=PNF&status=TOTALLY_WRONG"
126 webTestClient.get().uri("/api/v1/configs?$arguments")
128 .expectStatus().isBadRequest
133 fun `get returns 200 if entry not found`() {
138 .uri("/api/v1/configs?resourceId=MISSING&resourceType=PNF")
140 .expectStatus().is2xxSuccessful
145 private fun post(resourceType: String, resourceId: String, status: String) {
148 .uri("/api/v1/configs/$resourceType/$resourceId/$status")
149 .body(BodyInserters.fromObject(snapshotData))
151 .expectStatus().is2xxSuccessful
155 private fun get(expectedType: String, resourceType: String, resourceId: String, status: String) {
156 var requestArguments = "resourceId=$resourceId&resourceType=$resourceType&status=$status"
158 if (expectedType.isNotEmpty()) {
159 requestArguments = "$requestArguments&format=$expectedType"
162 .uri("/api/v1/configs?$requestArguments")
164 .expectStatus().is2xxSuccessful
165 .expectHeader().contentType(MediaType.valueOf("application/$expectedType"))
166 .expectBody().equals(snapshotData)
170 .uri("/api/v1/configs?$requestArguments")
172 .expectStatus().is2xxSuccessful
173 .expectHeader().contentType(MediaType.TEXT_PLAIN)
174 .expectBody().equals(snapshotData)