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
42 import java.nio.file.Files
43 import java.nio.file.Paths
45 import kotlin.test.AfterTest
46 import kotlin.test.BeforeTest
47 import kotlin.test.assertTrue
49 @RunWith(SpringRunner::class)
51 @ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class])
52 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
53 @TestPropertySource(locations = ["classpath:application-test.properties"])
54 class ExecutionServiceHandlerTest {
57 lateinit var blueprintCatalog: BluePrintCatalogService
59 lateinit var webTestClient: WebTestClient
63 deleteDir("target", "blueprints")
68 deleteDir("target", "blueprints")
73 fun `test rest upload blueprint`() {
75 val body = MultipartBodyBuilder().apply {
76 part("file", object : ByteArrayResource(Files.readAllBytes(loadTestCbaFile().toPath())) {
77 override fun getFilename(): String {
85 .uri("/api/v1/execution-service/upload")
86 .body(BodyInserters.fromMultipartData(body))
89 .returnResult<String>()
97 fun `test rest process`() {
99 blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
101 val executionServiceInput = JacksonUtils
102 .readValueFromClassPathFile("execution-input/default-input.json",
103 ExecutionServiceInput::class.java)!!
107 .uri("/api/v1/execution-service/process")
108 .body(BodyInserters.fromObject(executionServiceInput))
115 fun `rest resource process should return status code 500 in case of server-side exception`() {
117 blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
119 val executionServiceInput = JacksonUtils
120 .readValueFromClassPathFile("execution-input/faulty-input.json",
121 ExecutionServiceInput::class.java)!!
125 .uri("/api/v1/execution-service/process")
126 .body(BodyInserters.fromObject(executionServiceInput))
128 .expectStatus().is5xxServerError
132 private fun loadTestCbaFile(): File {
133 val testCbaFile = Paths.get("./src/test/resources/test-cba.zip").toFile()
134 assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}")