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.resource.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.deleteDir
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
25 import org.slf4j.LoggerFactory
26 import org.springframework.beans.factory.annotation.Autowired
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
35 import kotlin.test.AfterTest
37 @RunWith(SpringRunner::class)
39 @ContextConfiguration(
40 classes = [TestDatabaseConfiguration::class, BluePrintCoreConfiguration::class,
41 BluePrintCatalogService::class, ErrorCatalogTestConfiguration::class]
43 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
44 @TestPropertySource(locations = ["classpath:application-test.properties"])
45 class TemplateControllerTest {
47 private val log = LoggerFactory.getLogger(TemplateControllerTest::class.toString())
50 lateinit var webTestClient: WebTestClient
52 var resolutionKey = "7cafa9f3-bbc8-49ec-8f25-fcaa6ac3ff08"
53 val blueprintName = "baseconfiguration"
54 val blueprintVersion = "1.0.0"
55 val templatePrefix = "activate"
56 val payloadDummyTemplateData = "PAYLOAD DATA"
58 var requestArguments = "bpName=$blueprintName&bpVersion=$blueprintVersion" +
59 "&artifactName=$templatePrefix&resolutionKey=$resolutionKey"
63 deleteDir("target", "blueprints")
67 fun `ping return Success`() {
69 webTestClient.get().uri("/api/v1/template/health-check")
78 fun `store same value and tries to retrieve - duplicate entry execption`() {
88 .uri("/api/v1/template?$requestArguments")
90 .expectStatus().is4xxClientError
91 .expectBody().equals(payloadDummyTemplateData)
96 fun `get returns requested JSON content-type`() {
100 get("json", resolutionKey)
105 fun `get returns requested XML content-type`() {
109 get("xml", resolutionKey)
114 fun `get returns 400 error if missing arg`() {
116 val arguments = "bpBADName=$blueprintName" +
117 "&bpBADVersion=$blueprintVersion" +
118 "&artifactName=$templatePrefix" +
119 "&resolutionKey=$resolutionKey"
121 webTestClient.get().uri("/api/v1/template?$arguments")
123 .expectStatus().isNotFound
128 fun `get returns 404 if entry not found`() {
134 "/api/v1/template?bpName=$blueprintName&bpVersion=$blueprintVersion" +
135 "&artifactName=$templatePrefix&resolutionKey=notFound"
138 .expectStatus().isNotFound
142 private fun post(resKey: String) {
145 .uri("/api/v1/template/$blueprintName/$blueprintVersion/$templatePrefix/$resKey")
146 .body(BodyInserters.fromObject(payloadDummyTemplateData))
148 .expectStatus().is2xxSuccessful
151 log.info("Stored result under UUID ${it.responseBody}")
155 private fun get(expectedType: String, resKey: String) {
156 var requestArguments = "bpName=$blueprintName&bpVersion=$blueprintVersion" +
157 "&artifactName=$templatePrefix&resolutionKey=$resKey"
159 if (expectedType.isNotEmpty()) {
160 requestArguments = "$requestArguments&format=$expectedType"
163 .uri("/api/v1/template?$requestArguments")
165 .expectStatus().is2xxSuccessful
166 .expectHeader().contentType(MediaType.valueOf("application/$expectedType"))
167 .expectBody().equals(payloadDummyTemplateData)
171 .uri("/api/v1/template?$requestArguments")
173 .expectStatus().is2xxSuccessful
174 .expectHeader().contentType(MediaType.TEXT_PLAIN)
175 .expectBody().equals(payloadDummyTemplateData)