Revert "Renaming Files having BluePrint to have Blueprint"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / ModelTypeControllerTest.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
18
19 import kotlinx.coroutines.runBlocking
20 import org.junit.Assert
21 import org.junit.FixMethodOrder
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 import org.junit.runners.MethodSorters
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.logger
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
35 @RunWith(SpringRunner::class)
36 @ContextConfiguration(
37     classes = [DesignerApiTestConfiguration::class]
38 )
39 @TestPropertySource(locations = ["classpath:application-test.properties"])
40 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
41 class ModelTypeControllerTest {
42
43     private val log = logger(ModelTypeControllerTest::class.java)!!
44
45     @Autowired
46     lateinit var modelTypeController: ModelTypeController
47
48     private var modelName = "test-datatype"
49
50     @Test
51     @Commit
52     @Throws(Exception::class)
53     fun test01SaveModelType() {
54         runBlocking {
55             log.info("**************** test01SaveModelType  ********************")
56
57             val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
58             var modelType = ModelType()
59             modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
60             modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
61             modelType.description = "Definition for Sample Datatype "
62             modelType.definition = JacksonUtils.jsonNode(content)
63             modelType.modelName = modelName
64             modelType.version = "1.0.0"
65             modelType.tags = (
66                 "test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
67                     BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
68                 )
69             modelType.updatedBy = "xxxxxx@xxx.com"
70             modelType = modelTypeController.saveModelType(modelType)
71             log.info("Saved Mode {}", modelType.toString())
72             Assert.assertNotNull("Failed to get Saved ModelType", modelType)
73             Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
74
75             val dbModelType = modelTypeController.getModelTypeByName(modelType.modelName)
76             Assert.assertNotNull(
77                 "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
78                 dbModelType
79             )
80
81             // Model Update
82             modelType.updatedBy = "bs2796@xxx.com"
83             modelType = modelTypeController.saveModelType(modelType)
84             Assert.assertNotNull("Failed to get Saved ModelType", modelType)
85             Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy)
86         }
87     }
88
89     @Test
90     @Throws(Exception::class)
91     fun test02SearchModelTypes() {
92         runBlocking {
93             log.info("*********************** test02SearchModelTypes  ***************************")
94             val tags = "test-datatype"
95             val dbModelTypes = modelTypeController.searchModelTypes(tags)
96             Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
97             Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
98         }
99     }
100
101     @Test
102     @Throws(Exception::class)
103     fun test03GetModelType() {
104         runBlocking {
105             log.info("************************* test03GetModelType  *********************************")
106             val dbModelType = modelTypeController.getModelTypeByName(modelName)
107             Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
108             Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType!!.modelName)
109
110             val dbDatatypeModelTypes =
111                 modelTypeController.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
112             Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
113             Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
114         }
115     }
116
117     @Test
118     @Commit
119     @Throws(Exception::class)
120     fun test04DeleteModelType() {
121         runBlocking {
122             log.info("************************ test03DeleteModelType  ***********************")
123             val dbResourceMapping = modelTypeController.getModelTypeByName(modelName)
124             Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
125             Assert.assertNotNull(
126                 "Failed to get Id for api call  getModelByName ",
127                 dbResourceMapping!!.modelName
128             )
129             modelTypeController.deleteModelTypeByName(dbResourceMapping.modelName)
130         }
131     }
132 }