2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 package org.onap.ccsdk.apps.controllerblueprints.service.rs;
\r
20 import com.att.eelf.configuration.EELFLogger;
\r
21 import com.att.eelf.configuration.EELFManager;
\r
22 import org.junit.Assert;
\r
23 import org.junit.FixMethodOrder;
\r
24 import org.junit.Test;
\r
25 import org.junit.runner.RunWith;
\r
26 import org.junit.runners.MethodSorters;
\r
27 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;
\r
28 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
\r
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
\r
30 import org.onap.ccsdk.apps.controllerblueprints.service.controller.ModelTypeController;
\r
31 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
\r
32 import org.springframework.beans.factory.annotation.Autowired;
\r
33 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
\r
34 import org.springframework.test.annotation.Commit;
\r
35 import org.springframework.test.context.ContextConfiguration;
\r
36 import org.springframework.test.context.junit4.SpringRunner;
\r
38 import java.util.List;
\r
40 @RunWith(SpringRunner.class)
\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
47 ModelTypeController modelTypeController;
\r
49 String modelName = "test-datatype";
\r
53 public void test01SaveModelType() throws Exception {
\r
54 log.info("**************** test01SaveModelType ********************");
\r
56 String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json");
\r
57 ModelType modelType = new ModelType();
\r
58 modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
\r
59 modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);
\r
60 modelType.setDescription("Definition for Sample Datatype ");
\r
61 modelType.setDefinition(JacksonUtils.jsonNode(content));
\r
62 modelType.setModelName(modelName);
\r
63 modelType.setVersion("1.0.0");
\r
64 modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","
\r
65 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
\r
66 modelType.setUpdatedBy("xxxxxx@xxx.com");
\r
67 modelType = modelTypeController.saveModelType(modelType);
\r
68 log.info("Saved Mode {}", modelType.toString());
\r
69 Assert.assertNotNull("Failed to get Saved ModelType", modelType);
\r
70 Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName());
\r
72 ModelType dbModelType = modelTypeController.getModelTypeByName(modelType.getModelName());
\r
73 Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")",
\r
77 modelType.setUpdatedBy("bs2796@xxx.com");
\r
78 modelType = modelTypeController.saveModelType(modelType);
\r
79 Assert.assertNotNull("Failed to get Saved ModelType", modelType);
\r
80 Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy());
\r
85 public void test02SearchModelTypes() throws Exception {
\r
86 log.info("*********************** test02SearchModelTypes ***************************");
\r
88 String tags = "test-datatype";
\r
90 List<ModelType> dbModelTypes = modelTypeController.searchModelTypes(tags);
\r
91 Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes);
\r
92 Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0);
\r
97 public void test03GetModelType() throws Exception {
\r
98 log.info("************************* test03GetModelType *********************************");
\r
99 ModelType dbModelType = modelTypeController.getModelTypeByName(modelName);
\r
100 Assert.assertNotNull("Failed to get response for api call getModelByName " + modelName, dbModelType);
\r
101 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName());
\r
103 List<ModelType> dbDatatypeModelTypes =
\r
104 modelTypeController.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
\r
105 Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes);
\r
106 Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0);
\r
111 public void test04DeleteModelType() throws Exception {
\r
113 "************************ test03DeleteModelType ***********************");
\r
114 ModelType dbResourceMapping = modelTypeController.getModelTypeByName(modelName);
\r
115 Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping);
\r
116 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName());
\r
118 modelTypeController.deleteModelTypeByName(dbResourceMapping.getModelName());
\r