0d7241df843ed80aa97d31aea1eefb7685b503b0
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / Bug3595Test.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.sal.restconf.impl.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.io.FileNotFoundException;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
17 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
18 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24
25 public class Bug3595Test {
26
27     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
28     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
29     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
30     private static EffectiveModelContext schemaContext;
31
32     private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
33
34     @BeforeClass
35     public static void initialize() throws FileNotFoundException {
36         schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
37         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
38         assertNotNull(module);
39         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
40         assertNotNull(module);
41     }
42
43     @Test
44     public void testLeafrefListKeyDeserializtion() {
45         final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
46                 .node(LST_WITH_LFREF_KEY_QNAME).node(NodeIdentifierWithPredicates.of(
47                         LST_WITH_LFREF_KEY_QNAME, LFREF_KEY_QNAME, "node1"));
48         final InstanceIdentifierContext iiContext =
49                 controllerContext.toInstanceIdentifier("leafref-module:cont/lst-with-lfref-key/node1");
50         iiContext.getInstanceIdentifier();
51         assertEquals(node1IIexpected, iiContext.getInstanceIdentifier());
52     }
53 }