2 * Copyright (c) 2017 Pantheon Technologies 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 org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
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;
25 public class LeafrefSerializeDeserializeTest extends AbstractBindingCodecTest {
28 public void listReferenceTest() {
29 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(Cont.QNAME).build();
30 final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
31 assertNotNull(fromYangInstanceIdentifier);
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);
39 final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
40 assertNotNull(fromNormalizedNode);
41 final Cont value = (Cont) fromNormalizedNode.getValue();
42 assertEquals(refVal, value.getRef());
46 public void uint32LeafrefTest() {
47 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(ContInt32.QNAME).build();
48 final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
49 assertNotNull(fromYangInstanceIdentifier);
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);
57 final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
58 assertNotNull(fromNormalizedNode);
59 final ContInt32 value = (ContInt32) fromNormalizedNode.getValue();
60 assertEquals(refVal, value.getRefUnionInt32());