Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / test / java / org / onap / ccsdk / cds / controllerblueprints / service / repository / ModelTypeReactRepositoryTest.java
1 /*
2  *  Copyright © 2018 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.service.repository;
18
19 import org.junit.Assert;
20 import org.junit.FixMethodOrder;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.MethodSorters;
24 import org.onap.ccsdk.cds.controllerblueprints.TestApplication;
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants;
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils;
27 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
30 import org.springframework.test.annotation.Commit;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringRunner;
33
34 import java.util.Arrays;
35 import java.util.List;
36
37 /**
38  * ModelTypeReactRepositoryTest.
39  *
40  * @author Brinda Santh
41  */
42
43 @RunWith(SpringRunner.class)
44 @DataJpaTest
45 @ContextConfiguration(classes = {TestApplication.class})
46 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
47 public class ModelTypeReactRepositoryTest {
48
49     @Autowired
50     private ModelTypeReactRepository modelTypeReactRepository;
51
52     String modelName = "test-datatype";
53
54     @Test
55     @Commit
56     public void test01Save() {
57         String content = JacksonUtils.Companion.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.Companion.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
69         ModelType dbModelType = modelTypeReactRepository.save(modelType).block();
70         Assert.assertNotNull("Failed to get Saved ModelType", dbModelType);
71     }
72
73     @Test
74     public void test02Finds() {
75         ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block();
76         Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName);
77
78         List<ModelType> dbFindByDefinitionType =
79                 modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block();
80         Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType);
81         Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0);
82
83         List<ModelType> dbFindByDerivedFrom =
84                 modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block();
85         Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom);
86         Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0);
87
88         List<ModelType> dbFindByModelNameIn =
89                 modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block();
90         Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn);
91         Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0);
92
93         List<ModelType> dbFindByDefinitionTypeIn =
94                 modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block();
95         Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn);
96         Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0);
97
98         List<ModelType> dbFindByDerivedFromIn =
99                 modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block();
100         Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn);
101         Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0);
102     }
103
104     @Test
105     @Commit
106     public void test03Delete() {
107         modelTypeReactRepository.deleteByModelName(modelName).block();
108     }
109
110 }