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;
13 import com.google.common.collect.ImmutableList;
14 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarCont;
18 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarContBuilder;
19 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
20 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanContBuilder;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 public class SpecializingLeafrefTest extends AbstractBindingCodecTest {
26 private static final InstanceIdentifier<BooleanCont> BOOLEAN_CONT_II = InstanceIdentifier
27 .builder(BooleanCont.class).build();
29 private static final InstanceIdentifier<BarCont> BAR_CONT_II = InstanceIdentifier
30 .builder(BarCont.class).build();
33 public void specifiedBooleanLeafTest() {
34 final BooleanCont booleanCont = new BooleanContBuilder().setIsFoo(true).build();
36 final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> res = codecContext
37 .toNormalizedNode(BOOLEAN_CONT_II, booleanCont);
39 final BooleanCont booleanContBinding = (BooleanCont)codecContext
40 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
42 assertTrue(booleanContBinding.isIsFoo());
46 public void specifiedCommonLeafTest() {
47 final BarCont barCont = new BarContBuilder().setLeaf2("foo").build();
49 final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> res = codecContext
50 .toNormalizedNode(BAR_CONT_II, barCont);
52 final BarCont booleanContBinding = (BarCont)codecContext
53 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
55 assertEquals(booleanContBinding.getLeaf2(), "foo");
59 public void specifiedLeafListTest() {
60 final List<String> testList = ImmutableList.of("test");
61 final BarCont barCont = new BarContBuilder().setLeafList1(testList).build();
63 final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> res = codecContext
64 .toNormalizedNode(BAR_CONT_II, barCont);
66 final BarCont barContAfterConverting = (BarCont)codecContext
67 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
69 assertEquals(barContAfterConverting.getLeafList1(), testList);