6d3b3da4ab89c93c59d67eab78a50e5855542f4c
[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.core.BluePrintProperties
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
26 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
27 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType
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(classes = [DesignerApiTestConfiguration::class,
39     BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintDBLibConfiguration::class])
40 @TestPropertySource(locations = ["classpath:application-test.properties"])
41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
42 class ModelTypeControllerTest {
43
44     private val log = LoggerFactory.getLogger(ModelTypeControllerTest::class.java)!!
45
46     @Autowired
47     internal var modelTypeController: ModelTypeController? = null
48
49     private var modelName = "test-datatype"
50
51     @Test
52     @Commit
53     @Throws(Exception::class)
54     fun test01SaveModelType() {
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 = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","
66                 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
67         modelType.updatedBy = "xxxxxx@xxx.com"
68         modelType = modelTypeController!!.saveModelType(modelType)
69         log.info("Saved Mode {}", modelType.toString())
70         Assert.assertNotNull("Failed to get Saved ModelType", modelType)
71         Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
72
73         val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName)
74         Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
75                 dbModelType)
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
85     @Test
86     @Throws(Exception::class)
87     fun test02SearchModelTypes() {
88         log.info("*********************** test02SearchModelTypes  ***************************")
89
90         val tags = "test-datatype"
91
92         val dbModelTypes = modelTypeController!!.searchModelTypes(tags)
93         Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
94         Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
95
96     }
97
98     @Test
99     @Throws(Exception::class)
100     fun test03GetModelType() {
101         log.info("************************* test03GetModelType  *********************************")
102         val dbModelType = modelTypeController!!.getModelTypeByName(modelName)
103         Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
104         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType!!.modelName)
105
106         val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
107         Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
108         Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
109     }
110
111     @Test
112     @Commit
113     @Throws(Exception::class)
114     fun test04DeleteModelType() {
115         log.info(
116                 "************************ test03DeleteModelType  ***********************")
117         val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName)
118         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
119         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbResourceMapping!!.modelName)
120
121         modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName)
122     }
123 }