2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.tosca;
26 import static org.assertj.core.api.Assertions.assertThat;
28 import java.util.LinkedList;
29 import java.util.List;
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;
42 @RunWith(SpringJUnit4ClassRunner.class)
43 @SpringBootTest(classes = Application.class)
44 public class DictionaryRepositoriesTestItCase {
46 private DictionaryRepository dictionaryRepository;
50 public void crudTest() {
52 Dictionary dictionaryTest1 = new Dictionary();
53 dictionaryTest1.setName("testDictionary1");
54 dictionaryTest1.setSecondLevelDictionary(1);
55 dictionaryTest1.setSubDictionaryType("testType");
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");
65 LinkedList<DictionaryElement> elementList1 = new LinkedList<DictionaryElement>();
66 elementList1.add(element1);
67 dictionaryTest1.setDictionaryElements(elementList1);
69 Dictionary dictionaryTest2 = new Dictionary();
70 dictionaryTest2.setName("testDictionary2");
71 dictionaryTest2.setSecondLevelDictionary(1);
72 dictionaryTest2.setSubDictionaryType("testType");
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");
82 LinkedList<DictionaryElement> elementList2 = new LinkedList<DictionaryElement>();
83 elementList2.add(element2);
84 dictionaryTest2.setDictionaryElements(elementList2);
86 dictionaryRepository.save(dictionaryTest1);
87 List<String> res1 = dictionaryRepository.getAllDictionaryNames();
88 assertThat(res1.size()).isEqualTo(1);
89 assertThat(res1.get(0)).isEqualTo("testDictionary1");
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");