5208f7ffd2474850f2c6d85021c0eb7043804214
[clamp.git] / src / test / java / org / onap / clamp / clds / tosca / DictionaryRepositoriesTestItCase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.tosca;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 import java.util.List;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.onap.clamp.clds.Application;
32 import org.onap.clamp.tosca.Dictionary;
33 import org.onap.clamp.tosca.DictionaryElement;
34 import org.onap.clamp.tosca.DictionaryRepository;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38 import org.springframework.transaction.annotation.Transactional;
39
40 @RunWith(SpringJUnit4ClassRunner.class)
41 @SpringBootTest(classes = Application.class)
42 public class DictionaryRepositoriesTestItCase {
43     @Autowired
44     private DictionaryRepository dictionaryRepository;
45
46     @Test
47     @Transactional
48     public void crudTest() {
49         // Setup
50         Dictionary dictionaryTest1 = new Dictionary();
51         dictionaryTest1.setName("testDictionary1");
52         dictionaryTest1.setSecondLevelDictionary(1);
53         dictionaryTest1.setSubDictionaryType("testType");
54
55         DictionaryElement element1 = new DictionaryElement();
56         element1.setName("element1");
57         element1.setShortName("shortName1");
58         element1.setType("type1");
59         element1.setDescription("description1");
60
61         dictionaryTest1.addDictionaryElements(element1);
62
63         Dictionary dictionaryTest2 = new Dictionary();
64         dictionaryTest2.setName("testDictionary2");
65         dictionaryTest2.setSecondLevelDictionary(1);
66         dictionaryTest2.setSubDictionaryType("testType");
67
68         DictionaryElement element2 = new DictionaryElement();
69         element2.setName("element2");
70         element2.setShortName("shortName2");
71         element2.setSubDictionary("testDictionary1");
72         element2.setType("type2");
73         element2.setDescription("description2");
74
75         dictionaryTest2.addDictionaryElements(element2);
76
77         dictionaryRepository.save(dictionaryTest1);
78         List<String> res1 = dictionaryRepository.getAllDictionaryNames();
79         assertThat(res1.size()).isEqualTo(1);
80         assertThat(res1.get(0)).isEqualTo("testDictionary1");
81
82         dictionaryRepository.save(dictionaryTest2);
83         List<String> res2 = dictionaryRepository.getAllDictionaryNames();
84         assertThat(res2.size()).isEqualTo(2);
85         assertThat(res2.get(0)).isEqualTo("testDictionary1");
86         assertThat(res2.get(1)).isEqualTo("testDictionary2");
87     }
88 }