Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / selfservice / api / ExecutionServiceHandlerTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 Bell Canada.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
19
20 import org.junit.Test
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
40
41 @RunWith(SpringRunner::class)
42 @WebFluxTest
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 {
47
48     @Autowired
49     lateinit var blueprintCatalog: BluePrintCatalogService
50     @Autowired
51     lateinit var webTestClient: WebTestClient
52
53
54     @Test
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}")
58
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 {
62                     return "test-cba.zip"
63                 }
64             })
65         }.build()
66
67         webTestClient
68                 .post()
69                 .uri("/api/v1/execution-service/upload")
70                 .body(BodyInserters.fromMultipartData(body))
71                 .exchange()
72                 .expectStatus().isOk
73     }
74
75     @Test
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)
80
81         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
82         webTestClient
83                 .post()
84                 .uri("/api/v1/execution-service/process")
85                 .body(BodyInserters.fromObject(executionServiceInput))
86                 .exchange()
87                 .expectStatus().isOk
88     }
89 }