fd51df4825a3b5243418f0477926d81a76049225
[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 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.domain.ModelType
28 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import org.slf4j.LoggerFactory
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
37 @RunWith(SpringRunner::class)
38 @ContextConfiguration(
39     classes = [DesignerApiTestConfiguration::class,
40         BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]
41 )
42 @TestPropertySource(locations = ["classpath:application-test.properties"])
43 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
44 class ModelTypeControllerTest {
45
46     private val log = LoggerFactory.getLogger(ModelTypeControllerTest::class.java)!!
47
48     @Autowired
49     internal var modelTypeController: ModelTypeController? = null
50
51     private var modelName = "test-datatype"
52
53     @Test
54     @Commit
55     @Throws(Exception::class)
56     fun test01SaveModelType() {
57         log.info("**************** test01SaveModelType  ********************")
58
59         val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
60         var modelType = ModelType()
61         modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
62         modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
63         modelType.description = "Definition for Sample Datatype "
64         modelType.definition = JacksonUtils.jsonNode(content)
65         modelType.modelName = modelName
66         modelType.version = "1.0.0"
67         modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
68                 BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
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     @Test
89     @Throws(Exception::class)
90     fun test02SearchModelTypes() {
91         log.info("*********************** test02SearchModelTypes  ***************************")
92
93         val tags = "test-datatype"
94
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     @Test
101     @Throws(Exception::class)
102     fun test03GetModelType() {
103         log.info("************************* test03GetModelType  *********************************")
104         val dbModelType = modelTypeController!!.getModelTypeByName(modelName)
105         Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
106         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType!!.modelName)
107
108         val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
109         Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
110         Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
111     }
112
113     @Test
114     @Commit
115     @Throws(Exception::class)
116     fun test04DeleteModelType() {
117         log.info(
118             "************************ test03DeleteModelType  ***********************"
119         )
120         val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName)
121         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
122         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbResourceMapping!!.modelName)
123
124         modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName)
125     }
126 }