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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import java.util.Map.Entry;
14 import org.junit.Test;
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.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 public class LeafrefSerializeDeserializeTest extends AbstractBindingCodecTest {
29 public void listReferenceTest() {
30 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(Cont.QNAME).build();
31 final InstanceIdentifier<?> fromYangInstanceIdentifier = this.registry.fromYangInstanceIdentifier(contYII);
32 assertNotNull(fromYangInstanceIdentifier);
34 final InstanceIdentifier<Cont> BA_II_CONT = InstanceIdentifier.builder(Cont.class).build();
35 final Ref refVal = new Ref("myvalue");
36 final Cont data = new ContBuilder().setRef(refVal).build();
37 final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedNode =
38 this.registry.toNormalizedNode(BA_II_CONT, data);
39 assertNotNull(normalizedNode);
41 final Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode =
42 this.registry.fromNormalizedNode(contYII, normalizedNode.getValue());
43 assertNotNull(fromNormalizedNode);
44 final Cont value = (Cont) fromNormalizedNode.getValue();
45 assertEquals(refVal, value.getRef());
49 public void uint32LeafrefTest() {
50 final YangInstanceIdentifier contYII = YangInstanceIdentifier.builder().node(ContInt32.QNAME).build();
51 final InstanceIdentifier<?> fromYangInstanceIdentifier = this.registry.fromYangInstanceIdentifier(contYII);
52 assertNotNull(fromYangInstanceIdentifier);
54 final InstanceIdentifier<ContInt32> BA_II_CONT = InstanceIdentifier.builder(ContInt32.class).build();
55 final RefUnionInt32 refVal = new RefUnionInt32(5L);
56 final ContInt32 data = new ContInt32Builder().setRefUnionInt32(refVal).build();
57 final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedNode =
58 this.registry.toNormalizedNode(BA_II_CONT, data);
59 assertNotNull(normalizedNode);
61 final Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode =
62 this.registry.fromNormalizedNode(contYII, normalizedNode.getValue());
63 assertNotNull(fromNormalizedNode);
64 final ContInt32 value = (ContInt32) fromNormalizedNode.getValue();
65 assertEquals(refVal, value.getRefUnionInt32());