Improve BindingNormalizedNodeSerializer API
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / EmptyLeafTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.dom.codec.impl;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.Map;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.RpcComplexUsesAugment;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.RpcComplexUsesAugmentBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.top.level.list.choice.in.list.EmptyLeaf;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.top.level.list.choice.in.list.EmptyLeafBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.ChoiceInList;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.common.Empty;
27
28 public class EmptyLeafTest extends AbstractBindingCodecTest {
29
30     private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
31     private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier.builder(Top.class)
32             .child(TopLevelList.class, TOP_FOO_KEY).build();
33
34     @Test
35     public void testCaseWithEmptyLeafType() {
36         final TopLevelList withEmptyCase = new TopLevelListBuilder()
37             .withKey(TOP_FOO_KEY)
38             .setChoiceInList(new EmptyLeafBuilder().setEmptyType(Empty.value()).build())
39             .build();
40         final var dom = codecContext.toNormalizedDataObject(BA_TOP_LEVEL_LIST, withEmptyCase);
41         final var readed = codecContext.fromNormalizedNode(dom.path(), dom.node());
42         final ChoiceInList list = ((TopLevelList) readed.getValue()).getChoiceInList();
43         assertTrue(list instanceof EmptyLeaf);
44         assertNotNull(((EmptyLeaf) list).getEmptyType());
45     }
46
47     // FIXME: either remove this method or take advantage of it
48     private static RpcComplexUsesAugment createComplexData() {
49         return new RpcComplexUsesAugmentBuilder()
50             .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
51             .setListViaUses(Map.of())
52             .build();
53     }
54 }