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.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
15 import java.io.FileNotFoundException;
16 import java.util.HashMap;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
22 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
23 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
24 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
31 public class Bug8072Test {
32 private static final String EXTERNAL_MODULE_NAME = "test-module";
33 private static final QName MODULES_QNAME = QName.create("test:module", "2014-01-09", "modules");
34 private static final QName MODULE_QNAME = QName.create("test:module", "2014-01-09", "module");
35 private static final QName NAME_QNAME = QName.create("test:module", "2014-01-09", "name");
36 private static final QName TYPE_QNAME = QName.create("test:module", "2014-01-09", "type");
37 private static final QName MODULE_TYPE_QNAME = QName.create("test:module", "2014-01-09", "module-type");
39 private static SchemaContext schemaContext;
41 private final ControllerContext controllerContext;
43 public Bug8072Test() throws FileNotFoundException {
44 final SchemaContext mountPointContext = TestUtils.loadSchemaContext("/full-versions/test-module");
45 final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
46 controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
47 doReturn(mountPointContext).when(mountInstance).getSchemaContext();
51 public static void init() throws FileNotFoundException, ReactorException {
52 schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
53 assertEquals(0, schemaContext.findModules(EXTERNAL_MODULE_NAME).size());
54 final Set<Module> allModules = schemaContext.getModules();
55 assertNotNull(allModules);
59 public void testIdentityRefFromExternalModule() throws FileNotFoundException, ReactorException {
60 final InstanceIdentifierContext<?> ctx = controllerContext.toInstanceIdentifier(
61 "simple-nodes:users/yang-ext:mount/test-module:modules/module/test-module:module-type/name");
63 final Map<QName, Object> keyValues = new HashMap<>();
64 keyValues.put(NAME_QNAME, "name");
65 keyValues.put(TYPE_QNAME, MODULE_TYPE_QNAME);
66 final YangInstanceIdentifier expectedYII = YangInstanceIdentifier.of(MODULES_QNAME).node(MODULE_QNAME)
67 .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(MODULE_QNAME, keyValues));
69 assertEquals(expectedYII, ctx.getInstanceIdentifier());