2 * Copyright © 2019 Bell Canada
3 * Modifications Copyright © 2019 IBM.
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 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
19 import kotlinx.coroutines.reactive.awaitSingle
20 import kotlinx.coroutines.runBlocking
21 import org.junit.After
22 import org.junit.Before
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
25 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
26 import org.slf4j.LoggerFactory
27 import org.springframework.beans.factory.annotation.Autowired
28 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
29 import org.springframework.boot.autoconfigure.security.SecurityProperties
30 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
31 import org.springframework.context.annotation.ComponentScan
32 import org.springframework.core.io.ByteArrayResource
33 import org.springframework.http.client.MultipartBodyBuilder
34 import org.springframework.test.annotation.DirtiesContext
35 import org.springframework.test.context.ContextConfiguration
36 import org.springframework.test.context.TestPropertySource
37 import org.springframework.test.context.junit4.SpringRunner
38 import org.springframework.test.web.reactive.server.WebTestClient
39 import org.springframework.test.web.reactive.server.returnResult
40 import org.springframework.web.reactive.function.BodyInserters
42 import java.nio.file.Files
43 import java.nio.file.Paths
44 import kotlin.test.Test
46 @RunWith(SpringRunner::class)
47 @EnableAutoConfiguration
48 @ContextConfiguration(classes = [ExecutionServiceControllerTest::class, SecurityProperties::class])
49 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
50 @TestPropertySource(locations = ["classpath:application-test.properties"])
53 class ExecutionServiceControllerTest {
55 private val log = LoggerFactory.getLogger(ExecutionServiceControllerTest::class.java)!!
58 lateinit var webTestClient: WebTestClient
60 var event: ExecutionServiceInput? = null
64 deleteDir("target", "blueprints")
69 deleteDir("target", "blueprints")
73 fun uploadBluePrint() {
75 val body = MultipartBodyBuilder().apply {
76 part("file", object : ByteArrayResource(Files.readAllBytes(loadCbaArchive().toPath())) {
77 override fun getFilename(): String {
85 .uri("/api/v1/execution-service/upload")
86 .body(BodyInserters.fromMultipartData(body))
89 .returnResult<String>()
95 private fun loadCbaArchive(): File {
96 return Paths.get("./src/test/resources/cba-for-kafka-integration_enriched.zip").toFile()