de12014886b787c9f75bbb0756db661cfc8219e7
[ccsdk/cds.git] /
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.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
39
40 @RunWith(SpringRunner::class)
41 @WebFluxTest
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 {
46
47     @Autowired
48     lateinit var blueprintCatalog: BluePrintCatalogService
49     @Autowired
50     lateinit var webTestClient: WebTestClient
51
52
53     @Test
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}")
57
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 {
61                     return "test-cba.zip"
62                 }
63             })
64         }.build()
65
66         webTestClient
67                 .post()
68                 .uri("/api/v1/execution-service/upload")
69                 .body(BodyInserters.fromMultipartData(body))
70                 .exchange()
71                 .expectStatus().isOk
72     }
73
74     @Test
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)
79
80         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!!
81         webTestClient
82                 .post()
83                 .uri("/api/v1/execution-service/process")
84                 .body(BodyInserters.fromObject(executionServiceInput))
85                 .exchange()
86                 .expectStatus().isOk
87     }
88 }