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.handler.ModelTypeHandler;
29 import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestTest;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
32 import org.springframework.test.annotation.Commit;
33 import org.springframework.test.context.ContextConfiguration;
34 import org.springframework.test.context.junit4.SpringRunner;
35 import org.springframework.transaction.annotation.Propagation;
36 import org.springframework.transaction.annotation.Transactional;
38 import java.util.List;
40 @RunWith(SpringRunner.class)
42 @Transactional(propagation = Propagation.NOT_SUPPORTED)
43 @ContextConfiguration(classes = {TestApplication.class})
44 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
45 public class ModelTypeServiceTest {
46 private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class);
48 private ModelTypeHandler modelTypeHandler;
50 String modelName = "test-datatype";
54 public void test01SaveModelType() throws Exception {
55 log.info("**************** test01SaveModelType ********************");
57 String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json");
58 ModelType modelType = new ModelType();
59 modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
60 modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);
61 modelType.setDescription("Definition for Sample Datatype ");
62 modelType.setDefinition(JacksonUtils.jsonNode(content));
63 modelType.setModelName(modelName);
64 modelType.setVersion("1.0.0");
65 modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","
66 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
67 modelType.setUpdatedBy("xxxxxx@xxx.com");
68 modelType = modelTypeHandler.saveModel(modelType);
69 log.info("Saved Mode {}", modelType.toString());
70 Assert.assertNotNull("Failed to get Saved ModelType", modelType);
71 Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName());
73 ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelType.getModelName());
74 Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")",
78 modelType.setUpdatedBy("bs2796@xxx.com");
79 modelType = modelTypeHandler.saveModel(modelType);
80 Assert.assertNotNull("Failed to get Saved ModelType", modelType);
81 Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy());
86 public void test02SearchModelTypes() throws Exception {
87 log.info("*********************** test02SearchModelTypes ***************************");
89 String tags = "test-datatype";
91 List<ModelType> dbModelTypes = modelTypeHandler.searchModelTypes(tags);
92 Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes);
93 Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0);
98 public void test03GetModelType() throws Exception {
99 log.info("************************* test03GetModelType *********************************");
100 ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelName);
101 Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType);
102 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName());
104 List<ModelType> dbDatatypeModelTypes =
105 modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
106 Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes);
107 Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0);
109 List<ModelType> dbModelTypeByDerivedFroms =
110 modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);
111 Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms);
112 Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0);
117 public void test04DeleteModelType() throws Exception {
119 "************************ test03DeleteModelType ***********************");
120 ModelType dbResourceMapping = modelTypeHandler.getModelTypeByName(modelName);
121 Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping);
122 Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName());
124 modelTypeHandler.deleteByModelName(dbResourceMapping.getModelName());