Update binding-dom adaptation to remove AugmentationNode
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / LeafrefSerializeDeserializeTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies 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 org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import org.junit.Test;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer.NodeResult;
15 import org.opendaylight.yang.gen.v1.bug8449.rev170516.Cont;
16 import org.opendaylight.yang.gen.v1.bug8449.rev170516.Cont.Ref;
17 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContBuilder;
18 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32;
19 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32.RefUnionInt32;
20 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32Builder;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24
25 public class LeafrefSerializeDeserializeTest extends AbstractBindingCodecTest {
26
27     @Test
28     public void listReferenceTest() {
29         final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(Cont.QNAME).build();
30         final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
31         assertNotNull(fromYangInstanceIdentifier);
32
33         final InstanceIdentifier<Cont> BA_II_CONT = InstanceIdentifier.builder(Cont.class).build();
34         final Ref refVal = new Ref("myvalue");
35         final Cont data = new ContBuilder().setRef(refVal).build();
36         final var normalizedNode = (NodeResult) codecContext.toNormalizedNode(BA_II_CONT, data);
37         assertNotNull(normalizedNode);
38
39         final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
40         assertNotNull(fromNormalizedNode);
41         final Cont value = (Cont) fromNormalizedNode.getValue();
42         assertEquals(refVal, value.getRef());
43     }
44
45     @Test
46     public void uint32LeafrefTest() {
47         final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(ContInt32.QNAME).build();
48         final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
49         assertNotNull(fromYangInstanceIdentifier);
50
51         final InstanceIdentifier<ContInt32> BA_II_CONT = InstanceIdentifier.builder(ContInt32.class).build();
52         final RefUnionInt32 refVal = new RefUnionInt32(Uint32.valueOf(5));
53         final ContInt32 data = new ContInt32Builder().setRefUnionInt32(refVal).build();
54         final var normalizedNode = (NodeResult) codecContext.toNormalizedNode(BA_II_CONT, data);
55         assertNotNull(normalizedNode);
56
57         final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
58         assertNotNull(fromNormalizedNode);
59         final ContInt32 value = (ContInt32) fromNormalizedNode.getValue();
60         assertEquals(refVal, value.getRefUnionInt32());
61     }
62 }
63