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.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.common.Uint8;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
33 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 = codecContext.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 = codecContext.fromYangInstanceIdentifier(yangII);
49 assertEquals(BA_TREE_COMPLEX_USES, bindingII);
53 public void testLeafOnlyAugmentationSerialization() {
54 final PathArgument leafOnlyLastArg = codecContext.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY)
55 .getLastPathArgument();
56 assertTrue("Last argument should be AugmentationIdentifier", leafOnlyLastArg instanceof AugmentationIdentifier);
57 assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
61 public void testCamelCaseKeys() {
62 final InstanceIdentifier<?> result = codecContext.fromYangInstanceIdentifier(YangInstanceIdentifier.create(
63 NodeIdentifier.create(OspfStatLsdbBrief.QNAME),
64 NodeIdentifierWithPredicates.of(OspfStatLsdbBrief.QNAME, ImmutableMap.of(
65 QName.create(OspfStatLsdbBrief.QNAME, "AreaIndex"), 1,
66 QName.create(OspfStatLsdbBrief.QNAME, "LsaType"), Uint8.valueOf(2),
67 QName.create(OspfStatLsdbBrief.QNAME, "LsId"), 3,
68 QName.create(OspfStatLsdbBrief.QNAME, "AdvRtr"), "foo"))));
69 assertTrue(result instanceof KeyedInstanceIdentifier);
70 final Identifier<?> key = ((KeyedInstanceIdentifier<?, ?>) result).getKey();
71 assertEquals(new OspfStatLsdbBriefKey("foo", 1, 3, Uint8.valueOf(2)), key);