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