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.junit.Assert.assertNull;
13 import static org.mockito.Matchers.any;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
17 import com.google.common.base.Optional;
18 import java.io.FileNotFoundException;
19 import java.util.HashMap;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
25 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
26 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
27 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
28 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
29 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
30 import org.opendaylight.yangtools.yang.common.QName;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.model.api.Module;
33 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
36 public class Bug8072Test {
37 private static final String EXTERNAL_MODULE_NAME = "test-module";
38 private static final QName MODULES_QNAME = QName.create("test:module", "2014-01-09", "modules");
39 private static final QName MODULE_QNAME = QName.create("test:module", "2014-01-09", "module");
40 private static final QName NAME_QNAME = QName.create("test:module", "2014-01-09", "name");
41 private static final QName TYPE_QNAME = QName.create("test:module", "2014-01-09", "type");
42 private static final QName MODULE_TYPE_QNAME = QName.create("test:module", "2014-01-09", "module-type");
44 private static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
47 public static void init() throws FileNotFoundException, ReactorException {
48 final SchemaContext globalContext = TestUtils.loadSchemaContext("/full-versions/yangs");
49 assertNull(globalContext.findModuleByName(EXTERNAL_MODULE_NAME, null));
50 final Set<Module> allModules = globalContext.getModules();
51 assertNotNull(allModules);
52 CONTROLLER_CONTEXT.setSchemas(globalContext);
56 public void testIdentityRefFromExternalModule() throws FileNotFoundException, ReactorException {
58 final InstanceIdentifierContext<?> ctx = CONTROLLER_CONTEXT.toInstanceIdentifier(
59 "simple-nodes:users/yang-ext:mount/test-module:modules/module/test-module:module-type/name");
61 final Map<QName, Object> keyValues = new HashMap<>();
62 keyValues.put(NAME_QNAME, "name");
63 keyValues.put(TYPE_QNAME, MODULE_TYPE_QNAME);
64 final YangInstanceIdentifier expectedYII = YangInstanceIdentifier.of(MODULES_QNAME).node(MODULE_QNAME)
65 .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(MODULE_QNAME, keyValues));
67 assertEquals(expectedYII, ctx.getInstanceIdentifier());
70 private void initMountService() throws FileNotFoundException, ReactorException {
71 final DOMMountPointService mountService = mock(DOMMountPointService.class);
72 CONTROLLER_CONTEXT.setMountService(mountService);
73 final BrokerFacade brokerFacade = mock(BrokerFacade.class);
74 final RestconfImpl restconfImpl = RestconfImpl.getInstance();
75 restconfImpl.setBroker(brokerFacade);
76 restconfImpl.setControllerContext(CONTROLLER_CONTEXT);
77 final SchemaContext mountPointContext = TestUtils.loadSchemaContext("/full-versions/test-module");
78 final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
79 when(mountInstance.getSchemaContext()).thenReturn(mountPointContext);
80 when(mountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));