Use ControllerContext non-statically
[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.controller.md.sal.rest.common.TestRestconfUtils;
18 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
19 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25
26 public class Bug3595Test {
27
28     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
29     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
30     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
31     private static SchemaContext schemaContext;
32
33     private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
34
35     @BeforeClass
36     public static void initialize() throws FileNotFoundException {
37         schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
38         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
39         assertNotNull(module);
40         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
41         assertNotNull(module);
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 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 }