c7147490d78edb540e683cd886c5750f23c6cbe0
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
19 \r
20 import org.apache.commons.io.FileUtils;\r
21 import org.junit.*;\r
22 import org.junit.runner.RunWith;\r
23 import org.junit.runners.MethodSorters;\r
24 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
27 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
28 import com.att.eelf.configuration.EELFLogger;\r
29 import com.att.eelf.configuration.EELFManager;\r
30 import org.springframework.beans.factory.annotation.Autowired;\r
31 import org.springframework.boot.test.context.SpringBootTest;\r
32 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;\r
33 import org.springframework.test.context.ContextConfiguration;\r
34 import org.springframework.test.context.junit4.SpringRunner;\r
35 \r
36 import java.io.File;\r
37 import java.nio.charset.Charset;\r
38 import java.util.List;\r
39 \r
40 @RunWith(SpringRunner.class)\r
41 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)\r
42 @ContextConfiguration(classes = {TestApplication.class})\r
43 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
44 public class ModelTypeRestTest {\r
45     private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class);\r
46     @Autowired\r
47     ModelTypeRest modelTypeRest;\r
48 \r
49     String modelName = "test-datatype";\r
50 \r
51     @Before\r
52     public void setUp() {\r
53 \r
54     }\r
55 \r
56 \r
57     @After\r
58     public void tearDown() {\r
59     }\r
60 \r
61     @Test\r
62     public void test01SaveModelType() throws Exception {\r
63         log.info("**************** test01SaveModelType  ********************");\r
64 \r
65         String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json");\r
66         ModelType modelType = new ModelType();\r
67         modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
68         modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);\r
69         modelType.setDescription("Definition for Sample Datatype ");\r
70         modelType.setDefinition(JacksonUtils.jsonNode(content));\r
71         modelType.setModelName(modelName);\r
72         modelType.setVersion("1.0.0");\r
73         modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","\r
74                 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
75         modelType.setUpdatedBy("xxxxxx@xxx.com");\r
76         modelType = modelTypeRest.saveModelType(modelType);\r
77         log.info("Saved Mode {}", modelType.toString());\r
78         Assert.assertNotNull("Failed to get Saved ModelType", modelType);\r
79         Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName());\r
80 \r
81         ModelType dbModelType = modelTypeRest.getModelTypeByName(modelType.getModelName());\r
82         Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")",\r
83                 dbModelType);\r
84 \r
85         // Model Update\r
86         modelType.setUpdatedBy("bs2796@xxx.com");\r
87         modelType = modelTypeRest.saveModelType(modelType);\r
88         Assert.assertNotNull("Failed to get Saved ModelType", modelType);\r
89         Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy());\r
90 \r
91     }\r
92 \r
93     @Test\r
94     public void test02SearchModelTypes() throws Exception {\r
95         log.info("*********************** test02SearchModelTypes  ***************************");\r
96 \r
97         String tags = "test-datatype";\r
98 \r
99         List<ModelType> dbModelTypes = modelTypeRest.searchModelTypes(tags);\r
100         Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes);\r
101         Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0);\r
102 \r
103     }\r
104 \r
105     @Test\r
106     public void test03GetModelType() throws Exception {\r
107         log.info("************************* test03GetModelType  *********************************");\r
108         ModelType dbModelType = modelTypeRest.getModelTypeByName(modelName);\r
109         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType);\r
110         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType.getModelName());\r
111 \r
112         List<ModelType> dbDatatypeModelTypes =\r
113                 modelTypeRest.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
114         Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes);\r
115         Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0);\r
116     }\r
117 \r
118     @Test\r
119     public void test04DeleteModelType() throws Exception {\r
120         log.info(\r
121                 "************************ test03DeleteModelType  ***********************");\r
122         ModelType dbResourceMapping = modelTypeRest.getModelTypeByName(modelName);\r
123         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping);\r
124         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbResourceMapping.getModelName());\r
125 \r
126         modelTypeRest.deleteModelTypeByName(dbResourceMapping.getModelName());\r
127     }\r
128 \r
129 \r
130 }\r