2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.apps.controllerblueprints.service.controller
19 import com.att.eelf.configuration.EELFManager
20 import org.junit.Assert
21 import org.junit.FixMethodOrder
23 import org.junit.runner.RunWith
24 import org.junit.runners.MethodSorters
25 import org.onap.ccsdk.apps.controllerblueprints.TestApplication
26 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
28 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
31 import org.springframework.test.annotation.Commit
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.junit4.SpringRunner
35 @RunWith(SpringRunner::class)
37 @ContextConfiguration(classes = [TestApplication::class])
38 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
39 class ModelTypeControllerTest {
41 private val log = EELFManager.getInstance().getLogger(ModelTypeControllerTest::class.java)!!
44 internal var modelTypeController: ModelTypeController? = null
46 private var modelName = "test-datatype"
50 @Throws(Exception::class)
51 fun test01SaveModelType() {
52 log.info("**************** test01SaveModelType ********************")
54 val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json")
55 var modelType = ModelType()
56 modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE
57 modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT
58 modelType.description = "Definition for Sample Datatype "
59 modelType.definition = JacksonUtils.jsonNode(content)
60 modelType.modelName = modelName
61 modelType.version = "1.0.0"
62 modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","
63 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
64 modelType.updatedBy = "xxxxxx@xxx.com"
65 modelType = modelTypeController!!.saveModelType(modelType)
66 log.info("Saved Mode {}", modelType.toString())
67 Assert.assertNotNull("Failed to get Saved ModelType", modelType)
68 Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName)
70 val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName)
71 Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")",
75 modelType.updatedBy = "bs2796@xxx.com"
76 modelType = modelTypeController!!.saveModelType(modelType)
77 Assert.assertNotNull("Failed to get Saved ModelType", modelType)
78 Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy)
83 @Throws(Exception::class)
84 fun test02SearchModelTypes() {
85 log.info("*********************** test02SearchModelTypes ***************************")
87 val tags = "test-datatype"
89 val dbModelTypes = modelTypeController!!.searchModelTypes(tags)
90 Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes)
91 Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty())
96 @Throws(Exception::class)
97 fun test03GetModelType() {
98 log.info("************************* test03GetModelType *********************************")
99 val dbModelType = modelTypeController!!.getModelTypeByName(modelName)
100 Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType)
101 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName)
103 val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
104 Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes)
105 Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty())
110 @Throws(Exception::class)
111 fun test04DeleteModelType() {
113 "************************ test03DeleteModelType ***********************")
114 val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName)
115 Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping)
116 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName)
118 modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName)