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