2 * Copyright (c) 2014 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.mdsal.dom.broker;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.verify;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
21 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
22 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
23 import org.opendaylight.mdsal.dom.api.DOMMountPointService.DOMMountPointBuilder;
24 import org.opendaylight.mdsal.dom.api.DOMRpcService;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 public class DOMMountPointServiceImplTest {
31 private static final YangInstanceIdentifier PATH =
32 YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
35 private DOMMountPointService mountPointService;
39 mountPointService = new DOMMountPointServiceImpl();
43 public void testMountPointRegistration() {
44 final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
45 doNothing().when(mountPointListener).onMountPointCreated(PATH);
46 mountPointService.registerProvisionListener(mountPointListener);
48 // Create a mount point with schema context and a DOMService
49 final DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(PATH);
51 final DOMRpcService rpcService = mock(DOMRpcService.class);
52 mountPointBuilder.addService(DOMRpcService.class, rpcService);
54 mountPointBuilder.register();
56 // Verify listener has been notified and mount point is accessible from mount point service
57 verify(mountPointListener).onMountPointCreated(eq(PATH));
58 assertTrue(mountPointService.getMountPoint(PATH).isPresent());
60 // Verify mount point schema context and service
61 final DOMMountPoint mountPoint = mountPointService.getMountPoint(PATH).get();
62 assertTrue(mountPoint.getService(DOMRpcService.class).isPresent());
63 assertEquals(rpcService, mountPoint.getService(DOMRpcService.class).get());
67 public void testMountPointDestruction() {
68 final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
69 doNothing().when(mountPointListener).onMountPointRemoved(PATH);
71 final ObjectRegistration<DOMMountPoint> mountPointRegistration =
72 mountPointService.createMountPoint(PATH).register();
74 mountPointService.registerProvisionListener(mountPointListener);
76 mountPointRegistration.close();
78 // Verify listener has been notified and mount point is not present in mount point service
79 verify(mountPointListener).onMountPointRemoved(eq(PATH));
80 assertFalse(mountPointService.getMountPoint(PATH).isPresent());