Add InstanceNotification(Publish)ServiceAdapter
[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.Map;
14 import java.util.Set;
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;
23
24 public class SpecializingLeafrefTest extends AbstractBindingCodecTest {
25     private static final InstanceIdentifier<BooleanCont> BOOLEAN_CONT_II = InstanceIdentifier
26             .builder(BooleanCont.class).build();
27
28     private static final InstanceIdentifier<BarCont> BAR_CONT_II = InstanceIdentifier
29             .builder(BarCont.class).build();
30
31     @Test
32     public void specifiedBooleanLeafTest() {
33         final BooleanCont booleanCont  = new BooleanContBuilder().setIsFoo(true).build();
34
35         final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
36                 .toNormalizedNode(BOOLEAN_CONT_II, booleanCont);
37
38         final BooleanCont booleanContBinding = (BooleanCont)codecContext
39                 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
40
41         assertTrue(booleanContBinding.getIsFoo());
42     }
43
44     @Test
45     public void specifiedCommonLeafTest() {
46         final BarCont barCont  = new BarContBuilder().setLeaf2("foo").build();
47
48         final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
49                 .toNormalizedNode(BAR_CONT_II, barCont);
50
51         final BarCont booleanContBinding = (BarCont)codecContext
52                 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
53
54         assertEquals(booleanContBinding.getLeaf2(), "foo");
55     }
56
57     @Test
58     public void specifiedLeafListTest() {
59         final Set<String> testSet = Set.of("test");
60         final BarCont barCont  = new BarContBuilder().setLeafList1(testSet).build();
61
62         final Map.Entry<YangInstanceIdentifier, NormalizedNode> res = codecContext
63                 .toNormalizedNode(BAR_CONT_II, barCont);
64
65         final BarCont barContAfterConverting = (BarCont)codecContext
66                 .fromNormalizedNode(res.getKey(), res.getValue()).getValue();
67
68         assertEquals(barContAfterConverting.getLeafList1(), testSet);
69     }
70 }