2 * Copyright (c) 2014 Cisco Systems, Inc. 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.dom.codec.impl;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
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;
29 public class EmptyLeafTest extends AbstractBindingCodecTest {
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();
36 public void testCaseWithEmptyLeafType() {
37 final TopLevelList withEmptyCase = new TopLevelListBuilder()
39 .setChoiceInList(new EmptyLeafBuilder().setEmptyType(Empty.value()).build())
41 final var dom = (NodeResult) codecContext.toNormalizedNode(BA_TOP_LEVEL_LIST,
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());
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())