2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.sal.restconf.impl.test;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
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.restconf.common.context.InstanceIdentifierContext;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class Bug3595Test {
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");
32 private static ControllerContext controllerContext = ControllerContext.getInstance();
35 public static void initialize() throws FileNotFoundException {
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);
42 controllerContext.setGlobalSchema(schemaContext);
46 public void testLeafrefListKeyDeserializtion() {
47 final YangInstanceIdentifier node1IIexpected = YangInstanceIdentifier.of(CONT_QNAME)
48 .node(LST_WITH_LFREF_KEY_QNAME).node(new 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());