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.context.annotation.FilterType
34 import org.springframework.core.io.ByteArrayResource
35 import org.springframework.http.client.MultipartBodyBuilder
36 import org.springframework.test.context.ContextConfiguration
37 import org.springframework.test.context.TestPropertySource
38 import org.springframework.test.context.junit4.SpringRunner
39 import org.springframework.test.web.reactive.server.WebTestClient
40 import org.springframework.test.web.reactive.server.returnResult
41 import org.springframework.web.reactive.function.BodyInserters
43 import java.nio.file.Files
44 import java.nio.file.Paths
46 import kotlin.test.AfterTest
47 import kotlin.test.BeforeTest
48 import kotlin.test.assertTrue
50 @RunWith(SpringRunner::class)
52 @ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class])
53 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"],
54 excludeFilters =arrayOf(ComponentScan.Filter(value = [(MessagingController::class)], type = FilterType.ASSIGNABLE_TYPE)))
55 @TestPropertySource(locations = ["classpath:application-test.properties"])
56 class ExecutionServiceHandlerTest {
59 lateinit var blueprintCatalog: BluePrintCatalogService
61 lateinit var webTestClient: WebTestClient
65 deleteDir("target", "blueprints")
70 deleteDir("target", "blueprints")
75 fun `test rest upload blueprint`() {
77 val body = MultipartBodyBuilder().apply {
78 part("file", object : ByteArrayResource(Files.readAllBytes(loadTestCbaFile().toPath())) {
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 blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
103 val executionServiceInput = JacksonUtils
104 .readValueFromClassPathFile("execution-input/default-input.json",
105 ExecutionServiceInput::class.java)!!
109 .uri("/api/v1/execution-service/process")
110 .body(BodyInserters.fromObject(executionServiceInput))
117 fun `rest resource process should return status code 500 in case of server-side exception`() {
119 blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
121 val executionServiceInput = JacksonUtils
122 .readValueFromClassPathFile("execution-input/faulty-input.json",
123 ExecutionServiceInput::class.java)!!
127 .uri("/api/v1/execution-service/process")
128 .body(BodyInserters.fromObject(executionServiceInput))
130 .expectStatus().is5xxServerError
134 private fun loadTestCbaFile(): File {
135 val testCbaFile = Paths.get("./src/test/resources/test-cba.zip").toFile()
136 assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}")