2 * Copyright (c) 2017 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
8 package org.opendaylight.controller.sal.restconf.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
14 import java.io.FileNotFoundException;
15 import java.util.HashMap;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
20 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
21 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
22 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
26 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 public class Bug8072Test {
31 private static final String EXTERNAL_MODULE_NAME = "test-module";
32 private static final QName MODULES_QNAME = QName.create("test:module", "2014-01-09", "modules");
33 private static final QName MODULE_QNAME = QName.create("test:module", "2014-01-09", "module");
34 private static final QName NAME_QNAME = QName.create("test:module", "2014-01-09", "name");
35 private static final QName TYPE_QNAME = QName.create("test:module", "2014-01-09", "type");
36 private static final QName MODULE_TYPE_QNAME = QName.create("test:module", "2014-01-09", "module-type");
38 private static EffectiveModelContext schemaContext;
40 private final ControllerContext controllerContext;
42 public Bug8072Test() throws FileNotFoundException {
43 final SchemaContext mountPointContext = TestUtils.loadSchemaContext("/full-versions/test-module");
44 final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
45 controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
46 doReturn(mountPointContext).when(mountInstance).getEffectiveModelContext();
50 public static void init() throws FileNotFoundException, ReactorException {
51 schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
52 assertEquals(0, schemaContext.findModules(EXTERNAL_MODULE_NAME).size());
56 public void testIdentityRefFromExternalModule() throws FileNotFoundException, ReactorException {
57 final InstanceIdentifierContext<?> ctx = controllerContext.toInstanceIdentifier(
58 "simple-nodes:users/yang-ext:mount/test-module:modules/module/test-module:module-type/name");
60 final Map<QName, Object> keyValues = new HashMap<>();
61 keyValues.put(NAME_QNAME, "name");
62 keyValues.put(TYPE_QNAME, MODULE_TYPE_QNAME);
63 final YangInstanceIdentifier expectedYII = YangInstanceIdentifier.of(MODULES_QNAME).node(MODULE_QNAME)
64 .node(NodeIdentifierWithPredicates.of(MODULE_QNAME, keyValues));
66 assertEquals(expectedYII, ctx.getInstanceIdentifier());