2fda159064a53112dc9d1414a426d2e007de8f8f
[ccsdk/cds.git] /
1 /*
2  * Copyright (C) 2019 Bell Canada.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.cds.blueprintsprocessor.db
17
18 import kotlinx.coroutines.runBlocking
19 import org.junit.Test
20 import org.junit.runner.RunWith
21 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
23 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
24 import org.springframework.beans.factory.annotation.Autowired
25 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
26 import org.springframework.context.annotation.ComponentScan
27 import org.springframework.test.context.TestPropertySource
28 import org.springframework.test.context.junit4.SpringRunner
29 import kotlin.test.AfterTest
30 import kotlin.test.BeforeTest
31 import kotlin.test.assertTrue
32
33 @RunWith(SpringRunner::class)
34 @EnableAutoConfiguration
35 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
36 @TestPropertySource(locations = ["classpath:application-test.properties"])
37 class BlueprintProcessorCatalogServiceImplTest {
38
39     @Autowired
40     lateinit var blueprintCatalog: BluePrintCatalogService
41
42     @BeforeTest
43     fun setup() {
44         deleteDir("target", "blueprints")
45     }
46
47     @AfterTest
48     fun cleanDir() {
49         deleteDir("target", "blueprints")
50     }
51
52     @Test
53     fun `test catalog service`() {
54         runBlocking {
55             //FIXME("Create ZIP from test blueprints")
56
57             val file = normalizedFile("./src/test/resources/test-cba.zip")
58             assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
59
60             blueprintCatalog.saveToDatabase("1234", file)
61
62             blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0")
63
64             blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0")
65
66         }
67     }
68 }