2e7ca2cdcc55af1bb220f721e5dc5e1ebf43676e
[ccsdk/apps.git] /
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.compress
24 import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir
25 import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
26 import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
27 import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart
28 import java.nio.file.Paths
29 import java.util.*
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 = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath
38
39     @Before
40     @Throws(Exception::class)
41     fun setUp() {
42         val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
43         assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
44         val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs()
45         assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}")
46         val blueprintFile = Paths.get(blueprintDir).toFile().normalize()
47         val testZipFile = blueprintFile.compress(zipBlueprintFileName)
48         assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}")
49     }
50
51     @After
52     @Throws(Exception::class)
53     fun tearDown() {
54         deleteDir(blueprintArchivePath)
55         deleteDir(blueprintEnrichmentPath)
56     }
57
58     @Test
59     fun testDecompressFilePart() {
60         val filePart = MockFilePart(zipBlueprintFileName)
61
62         runBlocking {
63             val enhanceId = UUID.randomUUID().toString()
64             val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId"
65             val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId"
66             BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
67             BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
68         }
69     }
70 }
71