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;
12 import org.junit.Test;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer.NodeResult;
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.TreeComplexUsesAugmentBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
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.InstanceIdentifier;
24 public class AugmentationSubstitutionTest extends AbstractBindingCodecTest {
25 private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
26 private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier.builder(Top.class)
27 .child(TopLevelList.class, TOP_FOO_KEY).build();
30 public void augmentationInGroupingSubstituted() {
31 final TopLevelList baRpc = new TopLevelListBuilder()
33 .addAugmentation(new RpcComplexUsesAugmentBuilder(createComplexData()).build())
35 final TopLevelList baTree = new TopLevelListBuilder()
37 .addAugmentation(new TreeComplexUsesAugmentBuilder(createComplexData()).build())
39 final var domTreeEntry = ((NodeResult) codecContext.toNormalizedNode(BA_TOP_LEVEL_LIST, baTree)).node();
40 final var domRpcEntry = ((NodeResult) codecContext.toNormalizedNode(BA_TOP_LEVEL_LIST, baRpc)).node();
41 assertEquals(domTreeEntry, domRpcEntry);
45 public void copyBuilderWithAugmenationsTest() {
46 final TopLevelList manuallyConstructed = new TopLevelListBuilder()
48 .addAugmentation(new TreeComplexUsesAugmentBuilder(createComplexData()).build())
51 final var result = (NodeResult) codecContext.toNormalizedNode(BA_TOP_LEVEL_LIST, manuallyConstructed);
52 final TopLevelList deserialized =
53 (TopLevelList) codecContext.fromNormalizedNode(result.path(), result.node()).getValue();
54 assertEquals(manuallyConstructed, deserialized);
55 final TopLevelList copiedFromDeserialized = new TopLevelListBuilder(deserialized).build();
56 assertEquals(manuallyConstructed, copiedFromDeserialized);
59 private static RpcComplexUsesAugment createComplexData() {
60 return new RpcComplexUsesAugmentBuilder()
61 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())