2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 com.google.common.collect.ImmutableMap;
13 import java.util.Map.Entry;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.Def;
16 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.DefBuilder;
17 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.grp.LstBuilder;
18 import org.opendaylight.yang.gen.v1.mdsal442.keydef.norev.grp.LstKey;
19 import org.opendaylight.yang.gen.v1.mdsal442.keyuse.norev.Use;
20 import org.opendaylight.yang.gen.v1.mdsal442.keyuse.norev.UseBuilder;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 public class KeyInheritenceTest extends AbstractBindingCodecTest {
27 private static final LstKey KEY = new LstKey("foo");
28 private static final InstanceIdentifier<Def> DEF_IID = InstanceIdentifier.create(Def.class);
29 private static final InstanceIdentifier<Use> USE_IID = InstanceIdentifier.create(Use.class);
31 private static final Def DEF = new DefBuilder()
32 .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
34 private static final Use USE = new UseBuilder()
35 .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
39 public void testFromBinding() {
40 final Entry<YangInstanceIdentifier, NormalizedNode> domDef = codecContext.toNormalizedNode(DEF_IID, DEF);
41 Entry<InstanceIdentifier<?>, DataObject> entry = codecContext.fromNormalizedNode(domDef.getKey(),
43 assertEquals(DEF_IID, entry.getKey());
44 final Def codecDef = (Def) entry.getValue();
46 final Entry<YangInstanceIdentifier, NormalizedNode> domUse = codecContext.toNormalizedNode(USE_IID, USE);
47 entry = codecContext.fromNormalizedNode(domUse.getKey(), domUse.getValue());
48 assertEquals(USE_IID, entry.getKey());
49 final Use codecUse = (Use) entry.getValue();
51 Use copiedUse = new UseBuilder(DEF).build();
52 assertEquals(USE, copiedUse);
53 assertEquals(domUse.getValue(), codecContext.toNormalizedNode(USE_IID, copiedUse).getValue());
54 copiedUse = new UseBuilder(codecDef).build();
55 assertEquals(USE, copiedUse);
56 assertEquals(domUse.getValue(), codecContext.toNormalizedNode(USE_IID, copiedUse).getValue());
57 copiedUse = new UseBuilder(codecUse).build();
58 assertEquals(USE, copiedUse);
59 assertEquals(domUse.getValue(), codecContext.toNormalizedNode(USE_IID, copiedUse).getValue());