Update DOMStoreThreePhaseCommitCohort design
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / DOMMountPointServiceImplTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.broker;
9
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;
17
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;
28
29 public class DOMMountPointServiceImplTest {
30
31     private static final YangInstanceIdentifier PATH =
32             YangInstanceIdentifier.of(QName.create("namespace", "2012-12-12",
33         "top"));
34
35     private DOMMountPointService mountPointService;
36
37     @Before
38     public void setup() {
39         mountPointService = new DOMMountPointServiceImpl();
40     }
41
42     @Test
43     public void testMountPointRegistration() {
44         final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
45         doNothing().when(mountPointListener).onMountPointCreated(PATH);
46         mountPointService.registerProvisionListener(mountPointListener);
47
48         // Create a mount point with schema context and a DOMService
49         final DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(PATH);
50
51         final DOMRpcService rpcService = mock(DOMRpcService.class);
52         mountPointBuilder.addService(DOMRpcService.class, rpcService);
53
54         mountPointBuilder.register();
55
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());
59
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());
64     }
65
66     @Test
67     public void testMountPointDestruction() {
68         final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
69         doNothing().when(mountPointListener).onMountPointRemoved(PATH);
70
71         final ObjectRegistration<DOMMountPoint> mountPointRegistration =
72                 mountPointService.createMountPoint(PATH).register();
73
74         mountPointService.registerProvisionListener(mountPointListener);
75
76         mountPointRegistration.close();
77
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());
81     }
82 }