2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.test.model;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
13 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.Def;
17 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.DefBuilder;
18 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.grp.Lst;
19 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.grp.LstBuilder;
20 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.grp.LstKey;
21 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container;
22 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder;
23 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed;
24 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedBuilder;
25 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedKey;
26 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Unkeyed;
27 import org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.UnkeyedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.test.pattern.rev170101.Cont;
29 import org.opendaylight.yang.gen.v1.urn.test.pattern.rev170101.ContBuilder;
31 public class TestListSquashing {
33 public void testEmptyLeafList() {
34 final Cont obj = new ContBuilder().setTest3(List.of()).build();
35 // Eventhough return type is List, it should be retained
36 assertEquals(List.of(), obj.getTest3());
40 public void testEmptyUserOrderedList() {
41 final Container cont = new ContainerBuilder()
43 .setUnkeyed(List.of())
45 // Empty Lists should become null
46 assertNull(cont.getKeyed());
47 assertNull(cont.getUnkeyed());
51 public void testUserOrderedList() {
52 final Keyed keyed = new KeyedBuilder().withKey(new KeyedKey("a")).build();
53 final Unkeyed unkeyed = new UnkeyedBuilder().build();
54 final Container cont = new ContainerBuilder()
55 .setKeyed(List.of(keyed))
56 .setUnkeyed(List.of(unkeyed))
58 // Non-empty Lists should be retained
59 assertEquals(List.of(keyed), cont.getKeyed());
60 assertEquals(List.of(unkeyed), cont.getUnkeyed());
64 public void testEmptySystemOrderedList() {
65 final Def cont = new DefBuilder().setLst(Map.of()).build();
66 // Empty Map should become null
67 assertNull(cont.getLst());
71 public void testSystemOrderedList() {
72 final Lst lst = new LstBuilder().withKey(new LstKey("a")).build();
73 final Def cont = new DefBuilder().setLst(Map.of(lst.key(), lst)).build();
74 // Non-empty Map should be retained
75 assertEquals(Map.of(lst.key(), lst), cont.getLst());