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