Split Restconf implementations (draft02 and RFC) - Prepare modules
[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
9 package org.opendaylight.controller.sal.restconf.impl.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.io.FileNotFoundException;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
18 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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
31
32     private static ControllerContext controllerContext = ControllerContext.getInstance();
33
34     @BeforeClass
35     public static void initialize() throws FileNotFoundException, ReactorException {
36         final SchemaContext 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         controllerContext.setGlobalSchema(schemaContext);
43     }
44
45     @Test
46     public void testLeafrefListKeyDeserializtion() {
47         final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
48                 .node(LST_WITH_LFREF_KEY_QNAME).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
49                         LST_WITH_LFREF_KEY_QNAME, LFREF_KEY_QNAME, "node1"));
50         final InstanceIdentifierContext<?> iiContext =
51                 controllerContext.toInstanceIdentifier("leafref-module:cont/lst-with-lfref-key/node1");
52         iiContext.getInstanceIdentifier();
53         assertEquals(node1IIexpected, iiContext.getInstanceIdentifier());
54     }
55 }