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