6ab6b85e0e0318825dc402515f335fcd5388e8dc
[controller.git] / opendaylight / md-sal / 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.controller.sal.restconf.impl.ControllerContext;
17 import org.opendaylight.controller.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
23 public class Bug3595Test {
24
25     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
26     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
27     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
28
29
30     private static ControllerContext controllerContext = ControllerContext.getInstance();
31
32     @BeforeClass
33     public static void initialize() throws FileNotFoundException {
34         SchemaContext schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
35         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
36         assertNotNull(module);
37         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
38         assertNotNull(module);
39
40         controllerContext.setGlobalSchema(schemaContext);
41     }
42
43     @Test
44     public void testLeafrefListKeyDeserializtion() {
45         final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
46                 .node(LST_WITH_LFREF_KEY_QNAME).node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
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 }