2 * Copyright (c) 2020 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 junit.framework.TestCase.assertTrue;
11 import static org.junit.Assert.assertEquals;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarCont;
17 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarContBuilder;
18 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
19 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanContBuilder;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 public class SpecializingLeafrefTest extends AbstractBindingCodecTest {
25 private static final InstanceIdentifier<BooleanCont> BOOLEAN_CONT_II = InstanceIdentifier
26 .builder(BooleanCont.class).build();
28 private static final InstanceIdentifier<BarCont> BAR_CONT_II = InstanceIdentifier
29 .builder(BarCont.class).build();
32 public void specifiedBooleanLeafTest() {
33 final BooleanCont booleanCont = new BooleanContBuilder().setIsFoo(true).build();
35 final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
36 .toNormalizedNode(BOOLEAN_CONT_II, booleanCont);
38 final BooleanCont booleanContBinding = (BooleanCont)codecContext
39 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
41 assertTrue(booleanContBinding.getIsFoo());
45 public void specifiedCommonLeafTest() {
46 final BarCont barCont = new BarContBuilder().setLeaf2("foo").build();
48 final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
49 .toNormalizedNode(BAR_CONT_II, barCont);
51 final BarCont booleanContBinding = (BarCont)codecContext
52 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
54 assertEquals(booleanContBinding.getLeaf2(), "foo");
58 public void specifiedLeafListTest() {
59 final Set<String> testSet = Set.of("test");
60 final BarCont barCont = new BarContBuilder().setLeafList1(testSet).build();
62 final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
63 .toNormalizedNode(BAR_CONT_II, barCont);
65 final BarCont barContAfterConverting = (BarCont)codecContext
66 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
68 assertEquals(barContAfterConverting.getLeafList1(), testSet);