Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / 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.cds.blueprintsprocessor.designer.api.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.cds.blueprintsprocessor.designer.api.mock.MockFilePart
24 import org.onap.ccsdk.cds.controllerblueprints.core.compress
25 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
26 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
27 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
28 import org.onap.ccsdk.cds.controllerblueprints.core.reCreateDirs
29 import java.util.UUID
30 import kotlin.test.assertTrue
31
32 class BluePrintEnhancerUtilsTest {
33
34     private val blueprintDir = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
35     private val blueprintArchivePath: String = "./target/blueprints/archive"
36     private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment"
37     private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip")
38
39     @Before
40     fun setUp() {
41         val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
42         assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
43         val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs()
44         assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}")
45         val blueprintFile = normalizedFile(blueprintDir)
46         val testZipFile = blueprintFile.compress(zipBlueprintFileName)
47         assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}")
48     }
49
50     @After
51     fun tearDown() {
52         deleteDir(blueprintArchivePath)
53         deleteDir(blueprintEnrichmentPath)
54     }
55
56     @Test
57     fun testFilePartCompressionNDeCompression() {
58         val filePart = MockFilePart(zipBlueprintFileName)
59
60         runBlocking {
61             val enhanceId = UUID.randomUUID().toString()
62             val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId)
63             val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId)
64             BluePrintEnhancerUtils.copyFilePartToEnhanceDir(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
65             BluePrintEnhancerUtils.compressEnhanceDirAndReturnFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
66         }
67     }
68 }