2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
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.
18 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
20 import kotlinx.coroutines.reactive.awaitSingle
21 import kotlinx.coroutines.runBlocking
23 import org.junit.runner.RunWith
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.boot.autoconfigure.security.SecurityProperties
31 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
32 import org.springframework.context.annotation.ComponentScan
33 import org.springframework.core.io.ByteArrayResource
34 import org.springframework.http.client.MultipartBodyBuilder
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
41 import java.nio.file.Files
42 import java.nio.file.Paths
44 import kotlin.test.AfterTest
45 import kotlin.test.BeforeTest
46 import kotlin.test.assertTrue
48 @RunWith(SpringRunner::class)
50 @ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class])
51 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
52 @TestPropertySource(locations = ["classpath:application-test.properties"])
53 class ExecutionServiceHandlerTest {
56 lateinit var blueprintCatalog: BluePrintCatalogService
58 lateinit var webTestClient: WebTestClient
62 deleteDir("target", "blueprints")
67 deleteDir("target", "blueprints")
72 fun `test rest upload blueprint`() {
74 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
75 assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
77 val body = MultipartBodyBuilder().apply {
78 part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) {
79 override fun getFilename(): String {
87 .uri("/api/v1/execution-service/upload")
88 .body(BodyInserters.fromMultipartData(body))
91 .returnResult<String>()
99 fun `test rest process`() {
101 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
102 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
103 blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), file)
105 val executionServiceInput = JacksonUtils
106 .readValueFromClassPathFile("execution-input/default-input.json",
107 ExecutionServiceInput::class.java)!!
111 .uri("/api/v1/execution-service/process")
112 .body(BodyInserters.fromObject(executionServiceInput))