blob: 4a8da536f20ca0cbbd0e6554b436a667173ca752 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.ccsdk.cds.blueprintsprocessor.uat
import kotlinx.coroutines.runBlocking
import org.junit.ClassRule
import org.junit.Rule
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.ExtendedTemporaryFolder
import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.UatExecutor
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.UAT_SPECIFICATION_FILE
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils.Companion.compressToBytes
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.junit4.rules.SpringClassRule
import org.springframework.test.context.junit4.rules.SpringMethodRule
import java.io.File
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import kotlin.test.BeforeTest
import kotlin.test.Test
// Only one runner can be configured with jUnit 4. We had to replace the SpringRunner by equivalent jUnit rules.
// See more on https://docs.spring.io/autorepo/docs/spring-framework/current/spring-framework-reference/testing.html#testcontext-junit4-rules
@RunWith(Parameterized::class)
class BlueprintsAcceptanceTest(
@Suppress("unused") private val blueprintName: String, // readable test description
private val rootFs: FileSystem
) : BaseUatTest() {
companion object {
@ClassRule
@JvmField
val springClassRule = SpringClassRule()
/**
* Generates the parameters to create a test instance for every blueprint found under UAT_BLUEPRINTS_BASE_DIR
* that contains the proper UAT definition file.
*/
@Parameterized.Parameters(name = "{index} {0}")
@JvmStatic
fun scanUatEmpoweredBlueprints(): List<Array<Any>> {
return (
File(UAT_BLUEPRINTS_BASE_DIR)
.listFiles { file -> file.isDirectory && File(file, UAT_SPECIFICATION_FILE).isFile }
?: throw RuntimeException("Failed to scan $UAT_BLUEPRINTS_BASE_DIR")
)
.map { file ->
arrayOf(
file.nameWithoutExtension,
FileSystems.newFileSystem(file.canonicalFile.toPath(), null)
)
}
}
}
@Rule
@JvmField
val springMethodRule = SpringMethodRule()
@Autowired
// Bean is created programmatically by {@link WorkingFoldersInitializer#initialize(String)}
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
lateinit var tempFolder: ExtendedTemporaryFolder
@Autowired
lateinit var uatExecutor: UatExecutor
@BeforeTest
fun cleanupTemporaryFolder() {
tempFolder.deleteAllFiles()
}
@Test
fun runUat() {
runBlocking {
val uatSpec = rootFs.getPath(UAT_SPECIFICATION_FILE).toFile().readText()
val cbaBytes = compressToBytes(rootFs.getPath("/"))
uatExecutor.execute(uatSpec, cbaBytes)
}
}
}
|