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.deleteDir
29 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
31 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
34 import org.springframework.context.annotation.ComponentScan
35 import org.springframework.test.context.ContextConfiguration
36 import org.springframework.test.context.TestPropertySource
37 import org.springframework.test.context.junit4.SpringRunner
39 import kotlin.test.AfterTest
40 import kotlin.test.BeforeTest
41 import kotlin.test.assertTrue
43 @RunWith(SpringRunner::class)
44 @EnableAutoConfiguration
45 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"])
46 @ContextConfiguration(classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class,
47 MockBlueprintProcessorCatalogServiceImpl::class])
48 @TestPropertySource(locations = ["classpath:application-test.properties"])
49 class BlueprintProcessorCatalogServiceImplTest {
52 lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl
55 lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration
57 private lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
59 private val blueprintId = "1234"
63 deleteDir("target", "blueprints")
64 bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId,
65 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
70 deleteDir("target", "blueprints")
74 fun `test catalog service`() {
75 //TODO: I thing this test function should be remve and replace by the other one.
77 //FIXME("Create ZIP from test blueprints")
79 val file = normalizedFile("./src/test/resources/test-cba.zip")
80 assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
82 blueprintsProcessorCatalogService.saveToDatabase("1234", file)
83 blueprintsProcessorCatalogService.getFromDatabase("baseconfiguration", "1.0.0")
85 blueprintsProcessorCatalogService.deleteFromDatabase("baseconfiguration", "1.0.0")
90 fun `test save function`() {
92 val file = normalizedFile("./src/test/resources/test-cba.zip")
93 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
94 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
95 metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
97 blueprintsProcessorCatalogService.save(metadata, file)
102 fun `test get function`() {
104 val file = normalizedFile("./src/test/resources/test-cba.zip")
105 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
106 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
107 metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
109 blueprintsProcessorCatalogService.save(metadata, file)
110 blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true)
113 assertTrue(File(blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath +
114 "/baseconfiguration").deleteRecursively(),"Couldn't get blueprint archive " +
115 "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " +
120 fun `test delete function`() {
122 blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0")