Make sure we compare key members via their property name
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / test / CaseSubstitutionTest.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.test;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.util.Collections;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.RpcComplexUsesAugment;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.RpcComplexUsesAugmentBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugment;
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.complex.from.grouping.ListViaUses;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.put.top.input.choice.list.choice.in.choice.list.ComplexViaUsesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.list.choice.in.choice.list.ComplexViaUsesWithDifferentNameBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.ChoiceList;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.ChoiceListBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.ChoiceListKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
31
32 public class CaseSubstitutionTest extends AbstractBindingCodecTest {
33
34     private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
35     private static final ChoiceListKey CHOICE_FOO_KEY = new ChoiceListKey("foo");
36
37     private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier.builder(Top.class)
38             .child(TopLevelList.class, TOP_FOO_KEY).build();
39     private static final InstanceIdentifier<ChoiceList> BA_CHOICE_LIST = InstanceIdentifier.builder(Top.class)
40             .child(ChoiceList.class, CHOICE_FOO_KEY).build();
41     private static final InstanceIdentifier<TreeLeafOnlyAugment> BA_TREE_LEAF_ONLY = BA_TOP_LEVEL_LIST
42             .augmentation(TreeLeafOnlyAugment.class);
43     private static final InstanceIdentifier<TreeComplexUsesAugment> BA_TREE_COMPLEX_USES = BA_TOP_LEVEL_LIST
44             .augmentation(TreeComplexUsesAugment.class);
45     private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
46
47     @Test
48     public void choiceInGroupingSubstituted() {
49         final ChoiceList baRpc = new ChoiceListBuilder()
50             .withKey(CHOICE_FOO_KEY)
51             .setChoiceInChoiceList(new ComplexViaUsesWithDifferentNameBuilder(createComplexData()).build())
52             .build();
53         final ChoiceList baTree = new ChoiceListBuilder()
54             .withKey(CHOICE_FOO_KEY)
55             .setChoiceInChoiceList(new ComplexViaUsesBuilder(createComplexData()).build())
56             .build();
57         final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(BA_CHOICE_LIST, baTree).getValue();
58         final NormalizedNode<?, ?> domRpcEntry = registry.toNormalizedNode(BA_CHOICE_LIST, baRpc).getValue();
59         assertEquals(domTreeEntry, domRpcEntry);
60     }
61
62     private static RpcComplexUsesAugment createComplexData() {
63         return new RpcComplexUsesAugmentBuilder()
64         .setContainerWithUses(new ContainerWithUsesBuilder()
65             .setLeafFromGrouping("foo")
66         .build())
67         .setListViaUses(Collections.<ListViaUses>emptyList())
68         .build();
69     }
70
71 }