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.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
27 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
33 import org.springframework.context.annotation.ComponentScan
34 import org.springframework.test.context.ContextConfiguration
35 import org.springframework.test.context.TestPropertySource
36 import org.springframework.test.context.junit4.SpringRunner
38 import kotlin.test.AfterTest
39 import kotlin.test.BeforeTest
40 import kotlin.test.assertTrue
42 @RunWith(SpringRunner::class)
43 @EnableAutoConfiguration
44 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"])
45 @ContextConfiguration(classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class,
46 MockBlueprintProcessorCatalogServiceImpl::class])
47 @TestPropertySource(locations = ["classpath:application-test.properties"])
48 class BlueprintProcessorCatalogServiceImplTest {
51 lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl
54 lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration
56 private lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
58 private val blueprintId = "1234"
62 deleteDir("target", "blueprints")
63 bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId,
64 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
69 deleteDir("target", "blueprints")
73 fun `test catalog service`() {
74 //TODO: I thing this test function should be remve and replace by the other one.
76 //FIXME("Create ZIP from test blueprints")
78 val file = normalizedFile("./src/test/resources/test-cba.zip")
79 assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
81 blueprintsProcessorCatalogService.saveToDatabase("1234", file)
82 blueprintsProcessorCatalogService.getFromDatabase("baseconfiguration", "1.0.0")
84 blueprintsProcessorCatalogService.deleteFromDatabase("baseconfiguration", "1.0.0")
89 fun `test save function`() {
91 val file = normalizedFile("./src/test/resources/test-cba.zip")
92 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
93 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
94 metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
96 blueprintsProcessorCatalogService.save(metadata, file)
101 fun `test get function`() {
103 val file = normalizedFile("./src/test/resources/test-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)
109 blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true)
112 assertTrue(File(blueprintCoreConfiguration.bluePrintPathConfiguration().blueprintArchivePath +
113 "/baseconfiguration").deleteRecursively(),"Couldn't get blueprint archive " +
114 "${blueprintCoreConfiguration.bluePrintPathConfiguration().blueprintArchivePath}/baseconfiguration " +
119 fun `test delete function`() {
121 blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0")