81d3570d14bc8323688c43c47b7add6811174008
[netconf.git] / restconf / sal-rest-connector / 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 import java.io.FileNotFoundException;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
17 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23
24 public class Bug3595Test {
25
26     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
27     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
28     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
29
30
31     private static ControllerContext controllerContext = ControllerContext.getInstance();
32
33     @BeforeClass
34     public static void initialize() throws FileNotFoundException, ReactorException {
35         final SchemaContext schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
36         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
37         assertNotNull(module);
38         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
39         assertNotNull(module);
40
41         controllerContext.setGlobalSchema(schemaContext);
42     }
43
44     @Test
45     public void testLeafrefListKeyDeserializtion() {
46         final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
47                 .node(LST_WITH_LFREF_KEY_QNAME).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
48                         LST_WITH_LFREF_KEY_QNAME, LFREF_KEY_QNAME, "node1"));
49         final InstanceIdentifierContext<?> iiContext =
50                 controllerContext.toInstanceIdentifier("leafref-module:cont/lst-with-lfref-key/node1");
51         iiContext.getInstanceIdentifier();
52         assertEquals(node1IIexpected, iiContext.getInstanceIdentifier());
53     }
54 }