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.apps.blueprintsprocessor.selfservice.api
21 import org.junit.runner.RunWith
22 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
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.core.io.ByteArrayResource
30 import org.springframework.http.client.MultipartBodyBuilder
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.test.context.TestPropertySource
33 import org.springframework.test.context.junit4.SpringRunner
34 import org.springframework.test.web.reactive.server.WebTestClient
35 import org.springframework.web.reactive.function.BodyInserters
36 import java.nio.file.Files
37 import java.nio.file.Paths
38 import kotlin.test.assertTrue
40 @RunWith(SpringRunner::class)
42 @ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class])
43 @ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
44 @TestPropertySource(locations = ["classpath:application-test.properties"])
45 class ExecutionServiceHandlerTest {
48 lateinit var blueprintCatalog: BluePrintCatalogService
50 lateinit var webTestClient: WebTestClient
54 fun `test rest upload blueprint`() {
55 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
56 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
58 val body = MultipartBodyBuilder().apply {
59 part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) {
60 override fun getFilename(): String {
68 .uri("/api/v1/execution-service/upload")
69 .body(BodyInserters.fromMultipartData(body))
75 fun `test rest process`() {
76 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
77 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
78 blueprintCatalog.saveToDatabase(file)
80 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
83 .uri("/api/v1/execution-service/process")
84 .body(BodyInserters.fromObject(executionServiceInput))