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