Modify the template model
[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.LinkedList;
29 import java.util.List;
30
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.onap.clamp.clds.Application;
34 import org.onap.clamp.tosca.Dictionary;
35 import org.onap.clamp.tosca.DictionaryElement;
36 import org.onap.clamp.tosca.DictionaryRepository;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40 import org.springframework.transaction.annotation.Transactional;
41
42 @RunWith(SpringJUnit4ClassRunner.class)
43 @SpringBootTest(classes = Application.class)
44 public class DictionaryRepositoriesTestItCase {
45     @Autowired
46     private DictionaryRepository dictionaryRepository;
47
48     @Test
49     @Transactional
50     public void crudTest() {
51         // Setup
52         Dictionary dictionaryTest1 = new Dictionary();
53         dictionaryTest1.setName("testDictionary1");
54         dictionaryTest1.setSecondLevelDictionary(1);
55         dictionaryTest1.setSubDictionaryType("testType");
56
57         DictionaryElement element1 = new DictionaryElement();
58         element1.setDictionary(dictionaryTest1);
59         element1.setName("element1");
60         element1.setShortName("shortName1");
61         element1.setSubDictionary("subDictionary1");
62         element1.setType("type1");
63         element1.setDescription("description1");
64
65         LinkedList<DictionaryElement> elementList1 = new LinkedList<DictionaryElement>();
66         elementList1.add(element1);
67         dictionaryTest1.setDictionaryElements(elementList1);
68
69         Dictionary dictionaryTest2 = new Dictionary();
70         dictionaryTest2.setName("testDictionary2");
71         dictionaryTest2.setSecondLevelDictionary(1);
72         dictionaryTest2.setSubDictionaryType("testType");
73
74         DictionaryElement element2 = new DictionaryElement();
75         element2.setDictionary(dictionaryTest2);
76         element2.setName("element2");
77         element2.setShortName("shortName2");
78         element2.setSubDictionary("subDictionary2");
79         element2.setType("type2");
80         element2.setDescription("description2");
81
82         LinkedList<DictionaryElement> elementList2 = new LinkedList<DictionaryElement>();
83         elementList2.add(element2);
84         dictionaryTest2.setDictionaryElements(elementList2);
85
86         dictionaryRepository.save(dictionaryTest1);
87         List<String> res1 = dictionaryRepository.getAllDictionaryNames();
88         assertThat(res1.size()).isEqualTo(1);
89         assertThat(res1.get(0)).isEqualTo("testDictionary1");
90
91         dictionaryRepository.save(dictionaryTest2);
92         List<String> res2 = dictionaryRepository.getAllDictionaryNames();
93         assertThat(res2.size()).isEqualTo(2);
94         assertThat(res2.get(0)).isEqualTo("testDictionary1");
95         assertThat(res2.get(1)).isEqualTo("testDictionary2");
96     }
97 }