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