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;
24 public class KeyInheritenceTest extends AbstractBindingCodecTest {
25 private static final LstKey KEY = new LstKey("foo");
26 private static final InstanceIdentifier<Def> DEF_IID = InstanceIdentifier.create(Def.class);
27 private static final InstanceIdentifier<Use> USE_IID = InstanceIdentifier.create(Use.class);
29 private static final Def DEF = new DefBuilder()
30 .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
32 private static final Use USE = new UseBuilder()
33 .setLst(ImmutableMap.of(KEY, new LstBuilder().setFoo("foo").withKey(KEY).build()))
37 public void testFromBinding() {
38 final var domDef = codecContext.toNormalizedDataObject(DEF_IID, DEF);
39 Entry<InstanceIdentifier<?>, DataObject> entry = codecContext.fromNormalizedNode(domDef.path(), domDef.node());
40 assertEquals(DEF_IID, entry.getKey());
41 final Def codecDef = (Def) entry.getValue();
43 final var domUse = codecContext.toNormalizedDataObject(USE_IID, USE);
44 entry = codecContext.fromNormalizedNode(domUse.path(), domUse.node());
45 assertEquals(USE_IID, entry.getKey());
46 final Use codecUse = (Use) entry.getValue();
48 Use copiedUse = new UseBuilder(DEF).build();
49 assertEquals(USE, copiedUse);
50 assertEquals(domUse.node(), codecContext.toNormalizedDataObject(USE_IID, copiedUse).node());
51 copiedUse = new UseBuilder(codecDef).build();
52 assertEquals(USE, copiedUse);
53 assertEquals(domUse.node(), codecContext.toNormalizedDataObject(USE_IID, copiedUse).node());
54 copiedUse = new UseBuilder(codecUse).build();
55 assertEquals(USE, copiedUse);
56 assertEquals(domUse.node(), codecContext.toNormalizedDataObject(USE_IID, copiedUse).node());