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.autoconfigure.security.SecurityProperties
28 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
29 import org.springframework.context.annotation.ComponentScan
30 import org.springframework.core.io.ByteArrayResource
31 import org.springframework.http.client.MultipartBodyBuilder
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
35 import org.springframework.test.web.reactive.server.WebTestClient
36 import org.springframework.web.reactive.function.BodyInserters
37 import java.nio.file.Files
38 import java.nio.file.Paths
39 import kotlin.test.assertTrue
41 @RunWith(SpringRunner::class)
43 @ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class])
44 @ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
45 @TestPropertySource(locations = ["classpath:application-test.properties"])
46 class ExecutionServiceHandlerTest {
49 lateinit var blueprintCatalog: BluePrintCatalogService
51 lateinit var webTestClient: WebTestClient
55 fun `test rest upload blueprint`() {
56 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
57 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
59 val body = MultipartBodyBuilder().apply {
60 part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) {
61 override fun getFilename(): String {
69 .uri("/api/v1/execution-service/upload")
70 .body(BodyInserters.fromMultipartData(body))
76 fun `test rest process`() {
77 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
78 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
79 blueprintCatalog.saveToDatabase(file)
81 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
84 .uri("/api/v1/execution-service/process")
85 .body(BodyInserters.fromObject(executionServiceInput))