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
9 package org.opendaylight.controller.netconf.persist.impl;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyObject;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.doThrow;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
19 import javax.management.MBeanServerConnection;
20 import javax.management.NotificationFilter;
21 import javax.management.NotificationListener;
22 import javax.management.ObjectName;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.opendaylight.controller.config.persist.api.Persister;
29 public class ConfigPersisterNotificationHandlerTest {
32 private MBeanServerConnection mBeanServer;
34 private Persister notificationListener;
37 public void setUp() throws Exception {
38 MockitoAnnotations.initMocks(this);
39 doNothing().when(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
40 any(NotificationFilter.class), anyObject());
44 public void testNotificationHandler() throws Exception {
45 doReturn(true).when(mBeanServer).isRegistered(any(ObjectName.class));
46 doThrow(Exception.class).when(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
48 final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener);
49 verify(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
50 any(NotificationFilter.class), anyObject());
52 testedHandler.close();
53 verify(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
57 public void testNotificationHandlerCloseNotRegistered() throws Exception {
58 doReturn(false).when(mBeanServer).isRegistered(any(ObjectName.class));
60 final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener);
62 testedHandler.close();
63 verify(mBeanServer, times(0)).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));