6b409dbeff6e0302b1c5c30ad97aedeeb108f73e
[ccsdk/cds.git] /
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.designer.api.domain.ModelType
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
27 import org.slf4j.LoggerFactory
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.test.annotation.Commit
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.TestPropertySource
32 import org.springframework.test.context.junit4.SpringRunner
33
34 @RunWith(SpringRunner::class)
35 @ContextConfiguration(
36     classes = [DesignerApiTestConfiguration::class]
37 )
38 @TestPropertySource(locations = ["classpath:application-test.properties"])
39 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
40 class ModelTypeControllerTest {
41
42     private val log = LoggerFactory.getLogger(ModelTypeControllerTest::class.java)!!
43
44     @Autowired
45     internal var modelTypeController: ModelTypeController? = null
46
47     private var modelName = "test-datatype"
48
49     @Test
50     @Commit
51     @Throws(Exception::class)
52     fun test01SaveModelType() {
53         log.info("**************** test01SaveModelType  ********************")
54
55         val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
56         var modelType = ModelType()
57         modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
58         modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
59         modelType.description = "Definition for Sample Datatype "
60         modelType.definition = JacksonUtils.jsonNode(content)
61         modelType.modelName = modelName
62         modelType.version = "1.0.0"
63         modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," +
64                 BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
65         modelType.updatedBy = "xxxxxx@xxx.com"
66         modelType = modelTypeController!!.saveModelType(modelType)
67         log.info("Saved Mode {}", modelType.toString())
68         Assert.assertNotNull("Failed to get Saved ModelType", modelType)
69         Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
70
71         val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName)
72         Assert.assertNotNull(
73             "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
74             dbModelType
75         )
76
77         // Model Update
78         modelType.updatedBy = "bs2796@xxx.com"
79         modelType = modelTypeController!!.saveModelType(modelType)
80         Assert.assertNotNull("Failed to get Saved ModelType", modelType)
81         Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy)
82     }
83
84     @Test
85     @Throws(Exception::class)
86     fun test02SearchModelTypes() {
87         log.info("*********************** test02SearchModelTypes  ***************************")
88
89         val tags = "test-datatype"
90
91         val dbModelTypes = modelTypeController!!.searchModelTypes(tags)
92         Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
93         Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
94     }
95
96     @Test
97     @Throws(Exception::class)
98     fun test03GetModelType() {
99         log.info("************************* test03GetModelType  *********************************")
100         val dbModelType = modelTypeController!!.getModelTypeByName(modelName)
101         Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
102         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType!!.modelName)
103
104         val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
105         Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
106         Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
107     }
108
109     @Test
110     @Commit
111     @Throws(Exception::class)
112     fun test04DeleteModelType() {
113         log.info(
114             "************************ test03DeleteModelType  ***********************"
115         )
116         val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName)
117         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
118         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbResourceMapping!!.modelName)
119
120         modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName)
121     }
122 }