summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src/test/kotlin
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-20 12:43:58 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-22 11:11:04 -0400
commit1636ef122d95cde48b7802042311351b7e47c499 (patch)
tree72dd56b3b4beed39f10c27947db2da21f0f4eeb5 /ms/controllerblueprints/modules/service/src/test/kotlin
parent594346cf32493eb556a0c71126006f960d854f1d (diff)
Add blueprint enrichment api
Change-Id: Idf0f05a9462418a72c716d6b96c121cf223b56eb Issue-ID: CCSDK-1173 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/test/kotlin')
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt53
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt71
2 files changed, 124 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt
new file mode 100644
index 000000000..60420aa64
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.controller.mock
+
+import org.apache.commons.io.FilenameUtils
+import org.slf4j.LoggerFactory
+import org.springframework.core.io.buffer.DataBuffer
+import org.springframework.http.HttpHeaders
+import org.springframework.http.codec.multipart.FilePart
+import org.springframework.util.FileCopyUtils
+import reactor.core.publisher.Flux
+import reactor.core.publisher.Mono
+import java.io.File
+import java.nio.file.Path
+
+class MockFilePart(private val fileName: String) : FilePart {
+ val log = LoggerFactory.getLogger(MockFilePart::class.java)!!
+ override fun content(): Flux<DataBuffer> {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun headers(): HttpHeaders {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun filename(): String {
+ return FilenameUtils.getName(fileName)
+ }
+
+ override fun name(): String {
+ return FilenameUtils.getBaseName(fileName)
+ }
+
+ override fun transferTo(path: Path): Mono<Void> {
+ log.info("Copying file($fileName to ${path}")
+ FileCopyUtils.copy(File(fileName), path.toFile())
+ return Mono.empty()
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
new file mode 100644
index 000000000..2e7ca2cdc
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.utils
+
+import kotlinx.coroutines.runBlocking
+import org.junit.After
+import org.junit.Before
+import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.compress
+import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir
+import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
+import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart
+import java.nio.file.Paths
+import java.util.*
+import kotlin.test.assertTrue
+
+class BluePrintEnhancerUtilsTest {
+
+ private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ private val blueprintArchivePath: String = "./target/blueprints/archive"
+ private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment"
+ private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath
+
+ @Before
+ @Throws(Exception::class)
+ fun setUp() {
+ val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
+ assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
+ val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs()
+ assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}")
+ val blueprintFile = Paths.get(blueprintDir).toFile().normalize()
+ val testZipFile = blueprintFile.compress(zipBlueprintFileName)
+ assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}")
+ }
+
+ @After
+ @Throws(Exception::class)
+ fun tearDown() {
+ deleteDir(blueprintArchivePath)
+ deleteDir(blueprintEnrichmentPath)
+ }
+
+ @Test
+ fun testDecompressFilePart() {
+ val filePart = MockFilePart(zipBlueprintFileName)
+
+ runBlocking {
+ val enhanceId = UUID.randomUUID().toString()
+ val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId"
+ val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId"
+ BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
+ BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
+ }
+ }
+}
+