2 * Copyright (C) 2019 Bell Canada.
4 * Copyright (C) 2019 IBM, Bell Canada.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.db
20 import kotlinx.coroutines.runBlocking
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
24 import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl
25 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintCatalogServiceImpl
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintProcessorCatalogServiceImpl
27 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
28 import org.onap.ccsdk.cds.controllerblueprints.core.compress
29 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
30 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
31 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
32 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
33 import org.springframework.beans.factory.annotation.Autowired
34 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
35 import org.springframework.context.annotation.ComponentScan
36 import org.springframework.test.context.ContextConfiguration
37 import org.springframework.test.context.TestPropertySource
38 import org.springframework.test.context.junit4.SpringRunner
40 import kotlin.test.AfterTest
41 import kotlin.test.BeforeTest
42 import kotlin.test.assertTrue
44 @RunWith(SpringRunner::class)
45 @EnableAutoConfiguration
46 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"])
47 @ContextConfiguration(
48 classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class,
49 MockBlueprintProcessorCatalogServiceImpl::class]
51 @TestPropertySource(locations = ["classpath:application-test.properties"])
52 class BlueprintProcessorCatalogServiceImplTest {
55 lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl
58 lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration
60 private lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
62 private val blueprintId = "1234"
67 deleteDir("target", "blueprints")
69 // Create sample CBA zip
70 normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
71 .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
73 bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime(
75 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
81 deleteDir("target", "blueprints")
85 fun `test catalog service`() {
88 val file = normalizedFile("./target/blueprints/generated-cba.zip")
89 assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
91 blueprintsProcessorCatalogService.saveToDatabase("1234", file)
92 blueprintsProcessorCatalogService.getFromDatabase("baseconfiguration", "1.0.0")
94 blueprintsProcessorCatalogService.deleteFromDatabase("baseconfiguration", "1.0.0")
99 fun `test save function`() {
101 val file = normalizedFile("./target/blueprints/generated-cba.zip")
102 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
103 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
104 metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
106 blueprintsProcessorCatalogService.save(metadata, file)
111 fun `test get function`() {
113 val file = normalizedFile("./target/blueprints/generated-cba.zip")
114 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
115 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
116 metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
118 blueprintsProcessorCatalogService.save(metadata, file)
119 blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true)
124 blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath +
126 ).deleteRecursively(), "Couldn't get blueprint archive " +
127 "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " +
133 fun `test delete function`() {
135 blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0")