2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
4 * Modifications Copyright © 2019 IBM.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
20 import kotlinx.coroutines.runBlocking
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
25 import org.onap.ccsdk.cds.controllerblueprints.core.compress
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.normalizedFile
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
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
39 import kotlin.test.AfterTest
40 import kotlin.test.BeforeTest
41 import kotlin.test.assertTrue
43 @RunWith(SpringRunner::class)
45 @ContextConfiguration(
47 ExecutionServiceHandler::class, BluePrintCoreConfiguration::class,
48 BluePrintCatalogService::class, SelfServiceApiTestConfiguration::class, ErrorCatalogTestConfiguration::class
51 @TestPropertySource(locations = ["classpath:application-test.properties"])
52 class ExecutionServiceControllerTest {
55 lateinit var blueprintsProcessorCatalogService: BluePrintCatalogService
58 lateinit var webTestClient: WebTestClient
62 deleteDir("target", "blueprints")
64 // Create sample CBA zip
65 normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
66 .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
71 deleteDir("target", "blueprints")
75 fun `test rest process`() {
77 blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
79 val executionServiceInput = JacksonUtils
80 .readValueFromClassPathFile(
81 "execution-input/default-input.json",
82 ExecutionServiceInput::class.java
87 .uri("/api/v1/execution-service/process")
88 .body(BodyInserters.fromObject(executionServiceInput))
95 fun `rest resource process should return status code 500 in case of server-side exception`() {
97 blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
99 val executionServiceInput = JacksonUtils
100 .readValueFromClassPathFile(
101 "execution-input/faulty-input.json",
102 ExecutionServiceInput::class.java
107 .uri("/api/v1/execution-service/process")
108 .body(BodyInserters.fromObject(executionServiceInput))
110 .expectStatus().is5xxServerError
114 private fun loadTestCbaFile(): File {
115 val testCbaFile = normalizedFile("./target/blueprints/generated-cba.zip")
116 assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}")