Fix leafref-to-enum encoding
[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 java.io.IOException;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.mdsal552.norev.Mdsal552Data.OutputA;
15 import org.opendaylight.yang.gen.v1.mdsal552.norev.RefTestOutput;
16 import org.opendaylight.yang.gen.v1.mdsal552.norev.RefTestOutputBuilder;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22
23 public class Mdsal552Test extends AbstractBindingCodecTest {
24     private static final SchemaPath OUTPUT_PATH = SchemaPath.create(true, QName.create(RefTestOutput.QNAME, "ref_test"),
25         RefTestOutput.QNAME);
26     private static final QName OUTPUTREF = QName.create(RefTestOutput.QNAME, "outputref");
27
28     @Test
29     public void testLeafrefEnumerationToNormalized() throws IOException {
30         assertEquals(Builders.containerBuilder()
31             .withNodeIdentifier(new NodeIdentifier(RefTestOutput.QNAME))
32             .withChild(ImmutableNodes.leafNode(OUTPUTREF, OutputA.DownTest.getName()))
33             .build(),
34             codecContext.toNormalizedNodeRpcData(new RefTestOutputBuilder().setOutputref(OutputA.DownTest).build()));
35     }
36
37     @Test
38     public void testLeafrefEnumerationFromNormalized() throws IOException {
39         assertEquals(new RefTestOutputBuilder().setOutputref(OutputA.DownTest).build(),
40             codecContext.fromNormalizedNodeRpcData(OUTPUT_PATH, Builders.containerBuilder()
41                 .withNodeIdentifier(new NodeIdentifier(RefTestOutput.QNAME))
42                 .withChild(ImmutableNodes.leafNode(OUTPUTREF, OutputA.DownTest.getName()))
43                 .build()));
44     }
45 }