Migrate users of Builders/ImmutableNodes
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / SpecializingLeafrefTest.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
9
10 import static junit.framework.TestCase.assertTrue;
11 import static org.junit.Assert.assertEquals;
12
13 import java.util.Set;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarCont;
16 import org.opendaylight.yang.gen.v1.mdsal426.norev.BarContBuilder;
17 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
18 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanContBuilder;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20
21 public class SpecializingLeafrefTest extends AbstractBindingCodecTest {
22     private static final InstanceIdentifier<BooleanCont> BOOLEAN_CONT_II = InstanceIdentifier
23             .builder(BooleanCont.class).build();
24
25     private static final InstanceIdentifier<BarCont> BAR_CONT_II = InstanceIdentifier
26             .builder(BarCont.class).build();
27
28     @Test
29     public void specifiedBooleanLeafTest() {
30         final BooleanCont booleanCont  = new BooleanContBuilder().setIsFoo(true).build();
31
32         final var res = codecContext.toNormalizedDataObject(BOOLEAN_CONT_II, booleanCont);
33
34         final var booleanContBinding = (BooleanCont) codecContext.fromNormalizedNode(res.path(), res.node()).getValue();
35
36         assertTrue(booleanContBinding.getIsFoo());
37     }
38
39     @Test
40     public void specifiedCommonLeafTest() {
41         final BarCont barCont  = new BarContBuilder().setLeaf2("foo").build();
42
43         final var res = codecContext.toNormalizedDataObject(BAR_CONT_II, barCont);
44
45         final var booleanContBinding = (BarCont) codecContext.fromNormalizedNode(res.path(), res.node()).getValue();
46
47         assertEquals(booleanContBinding.getLeaf2(), "foo");
48     }
49
50     @Test
51     public void specifiedLeafListTest() {
52         final Set<String> testSet = Set.of("test");
53         final BarCont barCont  = new BarContBuilder().setLeafList1(testSet).build();
54
55         final var res = codecContext.toNormalizedDataObject(BAR_CONT_II, barCont);
56
57         final var barContAfterConverting = (BarCont) codecContext.fromNormalizedNode(res.path(), res.node()).getValue();
58
59         assertEquals(barContAfterConverting.getLeafList1(), testSet);
60     }
61 }