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