Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / test / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / utils / BluePrintEnhancerUtilsTest.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.utils
18
19 import kotlinx.coroutines.runBlocking
20 import org.junit.After
21 import org.junit.Before
22 import org.junit.Test
23 import org.onap.ccsdk.apps.controllerblueprints.core.*
24 import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart
25 import java.nio.file.Paths
26 import java.util.*
27 import kotlin.test.assertTrue
28
29 class BluePrintEnhancerUtilsTest {
30
31     private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
32     private val blueprintArchivePath: String = "./target/blueprints/archive"
33     private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment"
34     private var zipBlueprintFileName =  normalizedPathName(blueprintArchivePath, "test.zip")
35
36     @Before
37     fun setUp() {
38         val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
39         assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
40         val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs()
41         assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}")
42         val blueprintFile = Paths.get(blueprintDir).toFile().normalize()
43         val testZipFile = blueprintFile.compress(zipBlueprintFileName)
44         assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}")
45     }
46
47     @After
48     fun tearDown() {
49         deleteDir(blueprintArchivePath)
50         deleteDir(blueprintEnrichmentPath)
51     }
52
53     @Test
54     fun testFilePartCompressionNDeCompression() {
55         val filePart = MockFilePart(zipBlueprintFileName)
56
57         runBlocking {
58             val enhanceId = UUID.randomUUID().toString()
59             val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId)
60             val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId)
61             BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
62             BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
63         }
64     }
65 }
66