diff options
author | Dan Timoney <dtimoney@att.com> | 2019-03-22 16:07:30 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-22 16:07:30 +0000 |
commit | 7f2812c44928ca7f55247d57e4b97943856f58eb (patch) | |
tree | 11cfe0d3ffa4bdebf1900859ebf62b65824b1c91 /ms/controllerblueprints/modules/service/src/test | |
parent | 78ffdaae81ce88333d90d642fab8a95a9b0683b1 (diff) | |
parent | 2960fd72dc68665e4d518713528957ec9528907f (diff) |
Merge "Add blueprint enrichment api"
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/test')
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 00000000..60420aa6 --- /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 00000000..2e7ca2cd --- /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) + } + } +} + |