4b771c0a6419ed4d976a85468ae85c249c90f88e
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / repository / ModelTypeReactRepositoryTest.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.ModelType
29 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
30 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
31 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.test.annotation.Commit
34 import org.springframework.test.context.ContextConfiguration
35 import org.springframework.test.context.TestPropertySource
36 import org.springframework.test.context.junit4.SpringRunner
37 import java.nio.charset.Charset
38 import java.util.Arrays
39
40 /**
41  * ModelTypeReactRepositoryTest.
42  *
43  * @author Brinda Santh
44  */
45
46 @RunWith(SpringRunner::class)
47 @ContextConfiguration(
48     classes = [DesignerApiTestConfiguration::class,
49         BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]
50 )
51 @TestPropertySource(locations = ["classpath:application-test.properties"])
52 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 class ModelTypeReactRepositoryTest {
54
55     @Autowired
56     private val modelTypeReactRepository: ModelTypeReactRepository? = null
57
58     internal var modelName = "test-datatype"
59
60     @Test
61     @Commit
62     fun test01Save() {
63         val content = normalizedFile("./src/test/resources/model_type/data_type/datatype-property.json")
64             .readText(Charset.defaultCharset())
65         val modelType = ModelType()
66         modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
67         modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
68         modelType.description = "Definition for Sample Datatype "
69         modelType.definition = JacksonUtils.jsonNode(content)
70         modelType.modelName = modelName
71         modelType.version = "1.0.0"
72         modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
73                 BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
74         modelType.updatedBy = "xxxxxx@xxx.com"
75
76         val dbModelType = modelTypeReactRepository!!.save(modelType).block()
77         Assert.assertNotNull("Failed to get Saved ModelType", dbModelType)
78     }
79
80     @Test
81     fun test02Finds() {
82         val dbFindByModelName = modelTypeReactRepository!!.findByModelName(modelName).block()
83         Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName)
84
85         val dbFindByDefinitionType =
86             modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block()
87         Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType)
88         Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType!!.size > 0)
89
90         val dbFindByDerivedFrom = modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block()
91         Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom)
92         Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom!!.size > 0)
93
94         val dbFindByModelNameIn = modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block()
95         Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn)
96         Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn!!.size > 0)
97
98         val dbFindByDefinitionTypeIn =
99             modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block()
100         Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn)
101         Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn!!.size > 0)
102
103         val dbFindByDerivedFromIn =
104             modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block()
105         Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn)
106         Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn!!.size > 0)
107     }
108
109     @Test
110     @Commit
111     fun test03Delete() {
112         modelTypeReactRepository!!.deleteByModelName(modelName).block()
113     }
114 }