Implemented UAT runtime services
[ccsdk/cds.git] / ms / blueprintsprocessor / application / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / uat / BlueprintsAcceptanceTest.kt
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.ccsdk.cds.blueprintsprocessor.uat
21
22 import org.junit.ClassRule
23 import org.junit.Rule
24 import org.junit.runner.RunWith
25 import org.junit.runners.Parameterized
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.UAT_SPECIFICATION_FILE
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils.Companion.compressToBytes
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.test.context.junit4.rules.SpringClassRule
30 import org.springframework.test.context.junit4.rules.SpringMethodRule
31 import java.io.File
32 import java.nio.file.FileSystem
33 import java.nio.file.FileSystems
34 import kotlin.test.BeforeTest
35 import kotlin.test.Test
36
37 // Only one runner can be configured with jUnit 4. We had to replace the SpringRunner by equivalent jUnit rules.
38 // See more on https://docs.spring.io/autorepo/docs/spring-framework/current/spring-framework-reference/testing.html#testcontext-junit4-rules
39 @RunWith(Parameterized::class)
40 class BlueprintsAcceptanceTest(@Suppress("unused") private val blueprintName: String, // readable test description
41                                private val rootFs: FileSystem): BaseUatTest() {
42
43     companion object {
44
45         @ClassRule
46         @JvmField
47         val springClassRule = SpringClassRule()
48
49         /**
50          * Generates the parameters to create a test instance for every blueprint found under UAT_BLUEPRINTS_BASE_DIR
51          * that contains the proper UAT definition file.
52          */
53         @Parameterized.Parameters(name = "{index} {0}")
54         @JvmStatic
55         fun scanUatEmpoweredBlueprints(): List<Array<Any>> {
56             return (File(UAT_BLUEPRINTS_BASE_DIR)
57                     .listFiles { file -> file.isDirectory && File(file, UAT_SPECIFICATION_FILE).isFile }
58                     ?: throw RuntimeException("Failed to scan $UAT_BLUEPRINTS_BASE_DIR"))
59                     .map { file ->
60                         arrayOf(
61                                 file.nameWithoutExtension,
62                                 FileSystems.newFileSystem(file.canonicalFile.toPath(), null)
63                         )
64                     }
65         }
66     }
67
68     @Rule
69     @JvmField
70     val springMethodRule = SpringMethodRule()
71
72     @Autowired
73     // Bean is created programmatically by {@link WorkingFoldersInitializer#initialize(String)}
74     @Suppress("SpringJavaInjectionPointsAutowiringInspection")
75     lateinit var tempFolder: ExtendedTemporaryFolder
76
77     @Autowired
78     lateinit var uatExecutor: UatExecutor
79
80     @BeforeTest
81     fun cleanupTemporaryFolder() {
82         tempFolder.deleteAllFiles()
83     }
84
85     @Test
86     fun runUat() {
87         val uatSpec = rootFs.getPath(UAT_SPECIFICATION_FILE).toFile().readText()
88         val cbaBytes = compressToBytes(rootFs.getPath("/"))
89         uatExecutor.execute(uatSpec, cbaBytes)
90     }
91 }