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(
49 BlueprintProcessorCatalogServiceImpl::class, BlueprintCoreConfiguration::class,
50 MockBlueprintProcessorCatalogServiceImpl::class
53 @TestPropertySource(locations = ["classpath:application-test.properties"])
54 class BlueprintProcessorCatalogServiceImplTest {
57 lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl
60 lateinit var blueprintCoreConfiguration: BlueprintCoreConfiguration
62 private lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*>
64 private val blueprintId = "1234"
69 deleteDir("target", "blueprints")
71 // Create sample CBA zip
72 normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
73 .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
75 bluePrintRuntimeService = BlueprintMetadataUtils.bluePrintRuntime(
77 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
83 deleteDir("target", "blueprints")
87 fun `test catalog service`() {
90 val file = normalizedFile("./target/blueprints/generated-cba.zip")
91 assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
93 blueprintsProcessorCatalogService.saveToDatabase("1234", file)
94 blueprintsProcessorCatalogService.getFromDatabase("baseconfiguration", "1.0.0")
96 blueprintsProcessorCatalogService.deleteFromDatabase("baseconfiguration", "1.0.0")
101 fun `test save function`() {
103 val file = normalizedFile("./target/blueprints/generated-cba.zip")
104 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
105 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
106 metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
108 blueprintsProcessorCatalogService.save(metadata, file)
113 fun `test get function`() {
115 val file = normalizedFile("./target/blueprints/generated-cba.zip")
116 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
117 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
118 metadata[BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
120 blueprintsProcessorCatalogService.save(metadata, file)
121 blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true)
126 blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath +
128 ).deleteRecursively(),
129 "Couldn't get blueprint archive " +
130 "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " +
136 fun `test delete function`() {
138 blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0")