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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import com.google.common.collect.ImmutableMap;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.mdsal._355.norev.OspfStatLsdbBrief;
16 import org.opendaylight.yang.gen.v1.mdsal._355.norev.OspfStatLsdbBriefKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugment;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
22 import org.opendaylight.yangtools.yang.binding.Identifier;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
32 public class InstanceIdentifierTest extends AbstractBindingCodecTest {
34 private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
35 private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier.builder(Top.class)
36 .child(TopLevelList.class, TOP_FOO_KEY).build();
37 private static final InstanceIdentifier<TreeLeafOnlyAugment> BA_TREE_LEAF_ONLY = BA_TOP_LEVEL_LIST
38 .augmentation(TreeLeafOnlyAugment.class);
39 private static final InstanceIdentifier<TreeComplexUsesAugment> BA_TREE_COMPLEX_USES = BA_TOP_LEVEL_LIST
40 .augmentation(TreeComplexUsesAugment.class);
41 private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
44 public void testComplexAugmentationSerialization() {
45 final YangInstanceIdentifier yangII = registry.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES);
46 final PathArgument lastArg = yangII.getLastPathArgument();
47 assertTrue("Last argument should be AugmentationIdentifier", lastArg instanceof AugmentationIdentifier);
48 final InstanceIdentifier<?> bindingII = registry.fromYangInstanceIdentifier(yangII);
49 assertEquals(BA_TREE_COMPLEX_USES, bindingII);
53 public void testLeafOnlyAugmentationSerialization() {
54 final PathArgument leafOnlyLastArg = registry.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY).getLastPathArgument();
55 assertTrue("Last argument should be AugmentationIdentifier", leafOnlyLastArg instanceof AugmentationIdentifier);
56 assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
60 public void testCamelCaseKeys() {
61 final InstanceIdentifier<?> result = registry.fromYangInstanceIdentifier(YangInstanceIdentifier.create(
62 NodeIdentifier.create(OspfStatLsdbBrief.QNAME),
63 new NodeIdentifierWithPredicates(OspfStatLsdbBrief.QNAME, ImmutableMap.of(
64 QName.create(OspfStatLsdbBrief.QNAME, "AreaIndex"), 1,
65 QName.create(OspfStatLsdbBrief.QNAME, "LsaType"), (short) 2,
66 QName.create(OspfStatLsdbBrief.QNAME, "LsId"), 3,
67 QName.create(OspfStatLsdbBrief.QNAME, "AdvRtr"), "foo"))));
68 assertTrue(result instanceof KeyedInstanceIdentifier);
69 final Identifier<?> key = ((KeyedInstanceIdentifier<?, ?>) result).getKey();
70 assertEquals(new OspfStatLsdbBriefKey("foo", 1, 3, (short)2), key);