2 * Copyright © 2018 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;
19 import com.att.eelf.configuration.EELFLogger;
20 import com.att.eelf.configuration.EELFManager;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.MethodSorters;
24 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;
25 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
27 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
28 import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestTest;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringRunner;
33 import org.springframework.transaction.annotation.Propagation;
34 import org.springframework.transaction.annotation.Transactional;
36 import java.util.List;
38 @RunWith(SpringRunner.class)
40 @Transactional(propagation = Propagation.NOT_SUPPORTED)
41 @ContextConfiguration(classes = {TestApplication.class})
42 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
43 public class ModelTypeServiceTest {
44 private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class);
46 ModelTypeService modelTypeService;
48 String modelName = "test-datatype";
51 public void test01SaveModelType() throws Exception {
52 log.info("**************** test01SaveModelType ********************");
54 String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json");
55 ModelType modelType = new ModelType();
56 modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
57 modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);
58 modelType.setDescription("Definition for Sample Datatype ");
59 modelType.setDefinition(JacksonUtils.jsonNode(content));
60 modelType.setModelName(modelName);
61 modelType.setVersion("1.0.0");
62 modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","
63 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
64 modelType.setUpdatedBy("xxxxxx@xxx.com");
65 modelType = modelTypeService.saveModel(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.getModelName());
70 ModelType dbModelType = modelTypeService.getModelTypeByName(modelType.getModelName());
71 Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")",
75 modelType.setUpdatedBy("bs2796@xxx.com");
76 modelType = modelTypeService.saveModel(modelType);
77 Assert.assertNotNull("Failed to get Saved ModelType", modelType);
78 Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy());
83 public void test02SearchModelTypes() throws Exception {
84 log.info("*********************** test02SearchModelTypes ***************************");
86 String tags = "test-datatype";
88 List<ModelType> dbModelTypes = modelTypeService.searchModelTypes(tags);
89 Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes);
90 Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0);
95 public void test03GetModelType() throws Exception {
96 log.info("************************* test03GetModelType *********************************");
97 ModelType dbModelType = modelTypeService.getModelTypeByName(modelName);
98 Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType);
99 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName());
101 List<ModelType> dbDatatypeModelTypes =
102 modelTypeService.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
103 Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes);
104 Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0);
106 List<ModelType> dbModelTypeByDerivedFroms =
107 modelTypeService.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);
108 Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms);
109 Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0);
114 public void test04DeleteModelType() throws Exception {
116 "************************ test03DeleteModelType ***********************");
117 ModelType dbResourceMapping = modelTypeService.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.getModelName());
121 modelTypeService.deleteByModelName(dbResourceMapping.getModelName());