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;
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.persist.api.Persister;
30 public class ConfigPersisterNotificationHandlerTest {
33 private MBeanServerConnection mBeanServer;
35 private Persister notificationListener;
38 public void setUp() throws Exception {
39 MockitoAnnotations.initMocks(this);
40 doNothing().when(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
41 any(NotificationFilter.class), anyObject());
45 public void testNotificationHandler() throws Exception {
46 doReturn(true).when(mBeanServer).isRegistered(any(ObjectName.class));
47 doThrow(Exception.class).when(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
49 final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener);
50 verify(mBeanServer).addNotificationListener(any(ObjectName.class), any(NotificationListener.class),
51 any(NotificationFilter.class), anyObject());
53 testedHandler.close();
54 verify(mBeanServer).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));
58 public void testNotificationHandlerCloseNotRegistered() throws Exception {
59 doReturn(false).when(mBeanServer).isRegistered(any(ObjectName.class));
61 final ConfigPersisterNotificationHandler testedHandler = new ConfigPersisterNotificationHandler(mBeanServer, notificationListener);
63 testedHandler.close();
64 verify(mBeanServer, times(0)).removeNotificationListener(any(ObjectName.class), any(NotificationListener.class));