e9f315715551a254e261ea379bf1870c84ab7380
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / Bug3595Test.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import java.io.FileNotFoundException;
6 import org.junit.BeforeClass;
7 import org.junit.Test;
8 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
9 import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
14
15 public class Bug3595Test {
16
17     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
18     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
19     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
20
21
22     private static ControllerContext controllerContext = ControllerContext.getInstance();
23
24     @BeforeClass
25     public static void initialize() throws FileNotFoundException {
26         SchemaContext schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
27         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
28         assertNotNull(module);
29         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
30         assertNotNull(module);
31
32         controllerContext.setGlobalSchema(schemaContext);
33     }
34
35     @Test
36     public void testLeafrefListKeyDeserializtion() {
37         final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
38                 .node(LST_WITH_LFREF_KEY_QNAME).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
39                         LST_WITH_LFREF_KEY_QNAME, LFREF_KEY_QNAME, "node1"));
40         final InstanceIdentifierContext<?> iiContext =
41                 controllerContext.toInstanceIdentifier("leafref-module:cont/lst-with-lfref-key/node1");
42         iiContext.getInstanceIdentifier();
43         assertEquals(node1IIexpected, iiContext.getInstanceIdentifier());
44     }
45 }