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.yang.gen.v1.bug8449.rev170516.Cont;
15 import org.opendaylight.yang.gen.v1.bug8449.rev170516.Cont.Ref;
16 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContBuilder;
17 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32;
18 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32.RefUnionInt32;
19 import org.opendaylight.yang.gen.v1.bug8449.rev170516.ContInt32Builder;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.common.Uint32;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 public class LeafrefSerializeDeserializeTest extends AbstractBindingCodecTest {
27 public void listReferenceTest() {
28 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(Cont.QNAME).build();
29 final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
30 assertNotNull(fromYangInstanceIdentifier);
32 final InstanceIdentifier<Cont> BA_II_CONT = InstanceIdentifier.builder(Cont.class).build();
33 final Ref refVal = new Ref("myvalue");
34 final Cont data = new ContBuilder().setRef(refVal).build();
35 final var normalizedNode = codecContext.toNormalizedDataObject(BA_II_CONT, data);
36 assertNotNull(normalizedNode);
38 final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
39 assertNotNull(fromNormalizedNode);
40 final Cont value = (Cont) fromNormalizedNode.getValue();
41 assertEquals(refVal, value.getRef());
45 public void uint32LeafrefTest() {
46 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(ContInt32.QNAME).build();
47 final InstanceIdentifier<?> fromYangInstanceIdentifier = codecContext.fromYangInstanceIdentifier(contYII);
48 assertNotNull(fromYangInstanceIdentifier);
50 final InstanceIdentifier<ContInt32> BA_II_CONT = InstanceIdentifier.builder(ContInt32.class).build();
51 final RefUnionInt32 refVal = new RefUnionInt32(Uint32.valueOf(5));
52 final ContInt32 data = new ContInt32Builder().setRefUnionInt32(refVal).build();
53 final var normalizedNode = codecContext.toNormalizedDataObject(BA_II_CONT, data);
54 assertNotNull(normalizedNode);
56 final var fromNormalizedNode = codecContext.fromNormalizedNode(contYII, normalizedNode.node());
57 assertNotNull(fromNormalizedNode);
58 final ContInt32 value = (ContInt32) fromNormalizedNode.getValue();
59 assertEquals(refVal, value.getRefUnionInt32());