CDS: Add stress test RPC to the cars model
[controller.git] / opendaylight / config / config-persister-impl / src / test / java / org / opendaylight / controller / config / persist / impl / ConfigPersisterNotificationHandlerTest.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
9 package org.opendaylight.controller.config.persist.impl;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyObject;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.doThrow;
17 import static org.mockito.Mockito.times;
18 import static org.mockito.Mockito.verify;
19
20 import javax.management.MBeanServerConnection;
21 import javax.management.NotificationFilter;
22 import javax.management.NotificationListener;
23 import javax.management.ObjectName;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.MockitoAnnotations;
28 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
29 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory;
30 import org.opendaylight.controller.config.persist.api.Persister;
31 import org.opendaylight.controller.config.util.ConfigRegistryClient;
32
33 public class ConfigPersisterNotificationHandlerTest {
34
35     @Mock
36     private MBeanServerConnection mBeanServer;
37     @Mock
38     private Persister notificationListener;
39     @Mock
40     private ConfigSubsystemFacadeFactory facadeFactory;
41     @Mock
42     private ConfigSubsystemFacade facade;
43     @Mock
44     private ConfigRegistryClient configRegistryClient;
45
46     @Before
47     public void setUp() throws Exception {
48         MockitoAnnotations.initMocks(this);
49
50         doReturn(facade).when(facadeFactory).createFacade(anyString());
51
52         doNothing().when(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
53                 any(NotificationFilter.class), anyObject());
54     }
55
56     @Test
57     public void testNotificationHandler() throws Exception {
58         doReturn(true).when(mBeanServer).isRegistered(any(ObjectName.class));
59         doThrow(Exception.class).when(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
60
61         final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener, facadeFactory);
62         verify(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
63                 any(NotificationFilter.class), anyObject());
64
65         testedHandler.close();
66         verify(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
67     }
68
69     @Test
70     public void testNotificationHandlerCloseNotRegistered() throws Exception {
71         doReturn(false).when(mBeanServer).isRegistered(any(ObjectName.class));
72
73         final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener, facadeFactory);
74
75         testedHandler.close();
76         verify(mBeanServer, times(0)).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
77     }
78 }