99c07a57834f0dacf7f653f3d5725093d5489c34
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / Mdsal552Test.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 org.junit.Assert.assertEquals;
11
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.mdsal552.norev.Mdsal552Data.OutputA;
14 import org.opendaylight.yang.gen.v1.mdsal552.norev.RefTestOutput;
15 import org.opendaylight.yang.gen.v1.mdsal552.norev.RefTestOutputBuilder;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21
22 public class Mdsal552Test extends AbstractBindingCodecTest {
23     private static final Absolute OUTPUT_PATH = Absolute.of(QName.create(RefTestOutput.QNAME, "ref_test"),
24         RefTestOutput.QNAME);
25     private static final QName OUTPUTREF = QName.create(RefTestOutput.QNAME, "outputref");
26
27     @Test
28     public void testLeafrefEnumerationToNormalized() {
29         assertEquals(Builders.containerBuilder()
30             .withNodeIdentifier(new NodeIdentifier(RefTestOutput.QNAME))
31             .withChild(ImmutableNodes.leafNode(OUTPUTREF, OutputA.DownTest.getName()))
32             .build(),
33             codecContext.toNormalizedNodeRpcData(new RefTestOutputBuilder().setOutputref(OutputA.DownTest).build()));
34     }
35
36     @Test
37     public void testLeafrefEnumerationFromNormalized() {
38         assertEquals(new RefTestOutputBuilder().setOutputref(OutputA.DownTest).build(),
39             codecContext.fromNormalizedNodeRpcData(OUTPUT_PATH, Builders.containerBuilder()
40                 .withNodeIdentifier(new NodeIdentifier(RefTestOutput.QNAME))
41                 .withChild(ImmutableNodes.leafNode(OUTPUTREF, OutputA.DownTest.getName()))
42                 .build()));
43     }
44 }