349c4359ccb487eacf13674dab145ab98feaa9d2
[mdsal.git] / binding / mdsal-binding-test-model / src / test / java / org / opendaylight / mdsal / binding / test / model / TestListSquashing.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.test.model;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12
13 import java.util.List;
14 import java.util.Map;
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;
30
31 public class TestListSquashing {
32     @Test
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());
37     }
38
39     @Test
40     public void testEmptyUserOrderedList() {
41         final Container cont = new ContainerBuilder()
42                 .setKeyed(List.of())
43                 .setUnkeyed(List.of())
44                 .build();
45         // Empty Lists should become null
46         assertNull(cont.getKeyed());
47         assertNull(cont.getUnkeyed());
48     }
49
50     @Test
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))
57                 .build();
58         // Non-empty Lists should be retained
59         assertEquals(List.of(keyed), cont.getKeyed());
60         assertEquals(List.of(unkeyed), cont.getUnkeyed());
61     }
62
63     @Test
64     public void testEmptySystemOrderedList() {
65         final Def cont = new DefBuilder().setLst(Map.of()).build();
66         // Empty Map should become null
67         assertNull(cont.getLst());
68     }
69
70     @Test
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());
76     }
77 }