diff options
author | xuegao <xg353y@intl.att.com> | 2020-01-20 10:35:16 +0100 |
---|---|---|
committer | xuegao <xg353y@intl.att.com> | 2020-01-20 13:54:17 +0100 |
commit | 62227fd4e49be7f61dee5ac0a6cb14d1609a58b6 (patch) | |
tree | 41eac60608aba0463f7ee6f33dccd5db7b61bc3a /src/test/java/org/onap | |
parent | 2e7b15f6a71764e2dba81b70187b17f1fbbb32ab (diff) |
Add tests
Add tests for Dictonary and DictionaryElements
Issue-ID: CLAMP-591
Change-Id: I1a810e0211685aa7d0831399e727c01b36416bab
Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r-- | src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java b/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java new file mode 100644 index 000000000..7f5b6901a --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/tosca/DictionaryRepositoriesTestItCase.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ +package org.onap.clamp.clds.tosca; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.clamp.clds.Application; +import org.onap.clamp.tosca.Dictionary; +import org.onap.clamp.tosca.DictionaryElement; +import org.onap.clamp.tosca.DictionaryRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class) +public class DictionaryRepositoriesTestItCase { + @Autowired + private DictionaryRepository dictionaryRepository; + + @Test + @Transactional + public void crudTest() { + // Setup + Dictionary dictionaryTest1 = new Dictionary(); + dictionaryTest1.setName("testDictionary1"); + dictionaryTest1.setSecondLevelDictionary(1); + dictionaryTest1.setSubDictionaryType("testType"); + + DictionaryElement element1 = new DictionaryElement(); + element1.setDictionary(dictionaryTest1); + element1.setName("element1"); + element1.setShortName("shortName1"); + element1.setSubDictionary("subDictionary1"); + element1.setType("type1"); + element1.setDescription("description1"); + + LinkedList<DictionaryElement> elementList1 = new LinkedList<DictionaryElement>(); + elementList1.add(element1); + dictionaryTest1.setDictionaryElements(elementList1); + + Dictionary dictionaryTest2 = new Dictionary(); + dictionaryTest2.setName("testDictionary2"); + dictionaryTest2.setSecondLevelDictionary(1); + dictionaryTest2.setSubDictionaryType("testType"); + + DictionaryElement element2 = new DictionaryElement(); + element2.setDictionary(dictionaryTest2); + element2.setName("element2"); + element2.setShortName("shortName2"); + element2.setSubDictionary("subDictionary2"); + element2.setType("type2"); + element2.setDescription("description2"); + + LinkedList<DictionaryElement> elementList2 = new LinkedList<DictionaryElement>(); + elementList2.add(element2); + dictionaryTest2.setDictionaryElements(elementList2); + + dictionaryRepository.save(dictionaryTest1); + List<String> res1 = dictionaryRepository.getAllDictionaryNames(); + assertThat(res1.size()).isEqualTo(1); + assertThat(res1.get(0)).isEqualTo("testDictionary1"); + + dictionaryRepository.save(dictionaryTest2); + List<String> res2 = dictionaryRepository.getAllDictionaryNames(); + assertThat(res2.size()).isEqualTo(2); + assertThat(res2.get(0)).isEqualTo("testDictionary1"); + assertThat(res2.get(1)).isEqualTo("testDictionary2"); + } +} |