Merge "Adding changes for catalog edit and create"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / repository / ResourceDictionaryReactRepositoryTest.kt
1 /*
2  *  Copyright © 2019 IBM.
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
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository
18
19 import org.junit.Assert
20 import org.junit.FixMethodOrder
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.junit.runners.MethodSorters
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiTestConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.annotation.Commit
33 import org.springframework.test.context.ContextConfiguration
34 import org.springframework.test.context.TestPropertySource
35 import org.springframework.test.context.junit4.SpringRunner
36 import org.springframework.transaction.annotation.Transactional
37
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(
40     classes = [DesignerApiTestConfiguration::class,
41         BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]
42 )
43 @TestPropertySource(locations = ["classpath:application-test.properties"])
44 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
45 class ResourceDictionaryReactRepositoryTest {
46
47     private val sourceName = "test-source"
48
49     @Autowired
50     lateinit var resourceDictionaryRepository: ResourceDictionaryRepository
51
52     @Test
53     @Commit
54     fun test01Save() {
55         val resourceDefinition = JacksonUtils
56             .readValueFromFile(
57                 "./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json",
58                 ResourceDefinition::class.java
59             )
60         Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition)
61         resourceDefinition!!.name = sourceName
62
63         val resourceDictionary = transformResourceDictionary(resourceDefinition)
64         val dbResourceDictionary = resourceDictionaryRepository.save(resourceDictionary)
65         Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary)
66     }
67
68     @Test
69     fun test02FindByNameReact() {
70         val dbResourceDictionary = resourceDictionaryRepository.findByName(sourceName)
71         Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary)
72     }
73
74     @Test
75     fun test03FindByNameInReact() {
76         val dbResourceDictionaries = resourceDictionaryRepository.findByNameIn(arrayListOf(sourceName))
77         Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries)
78     }
79
80     @Test
81     fun test04FindByTagsContainingIgnoreCaseReact() {
82         val dbTagsResourceDictionaries = resourceDictionaryRepository.findByTagsContainingIgnoreCase(sourceName)
83         Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries)
84     }
85
86     @Test
87     @Transactional
88     @Commit
89     fun test05Delete() {
90         resourceDictionaryRepository.deleteByName(sourceName)
91     }
92
93     private fun transformResourceDictionary(resourceDefinition: ResourceDefinition): ResourceDictionary {
94         val resourceDictionary = ResourceDictionary()
95         resourceDictionary.name = resourceDefinition.name
96         resourceDictionary.dataType = resourceDefinition.property.type
97         resourceDictionary.description = resourceDefinition.property.description!!
98         resourceDictionary.tags = resourceDefinition.tags!!
99         resourceDictionary.updatedBy = resourceDefinition.updatedBy
100         resourceDictionary.definition = resourceDefinition
101         return resourceDictionary
102     }
103 }