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 java.util.Collections;
13 import javax.management.Notification;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Matchers;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
23 import org.opendaylight.controller.config.persist.api.Persister;
24 import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification;
25 import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification;
26 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
28 import com.google.common.collect.Lists;
30 public class ConfigPersisterNotificationListenerTest {
33 private Persister mockPersister;
34 private PersisterAggregator persisterAggregator;
37 private NetconfJMXNotification unknownNetconfNotif;
39 private CommitJMXNotification commitNetconfNotif;
41 private Notification unknownNotif;
44 public void setUp() throws Exception {
45 MockitoAnnotations.initMocks(this);
47 Mockito.doNothing().when(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class));
48 Mockito.doReturn("persister").when(mockPersister).toString();
49 final PersisterAggregator.PersisterWithConfiguration withCfg = new PersisterAggregator.PersisterWithConfiguration(mockPersister, false);
50 persisterAggregator = new PersisterAggregator(Lists.newArrayList(withCfg));
52 Mockito.doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString();
53 Mockito.doReturn("netconfCommitNotification").when(commitNetconfNotif).toString();
55 Mockito.doReturn(XmlUtil.readXmlToElement("<config-snapshot/>")).when(commitNetconfNotif).getConfigSnapshot();
56 Mockito.doReturn(Collections.emptySet()).when(commitNetconfNotif).getCapabilities();
61 public void testNotificationListenerUnknownNotification() throws Exception {
62 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
63 testeListener.handleNotification(unknownNotif, null);
64 Mockito.verifyZeroInteractions(mockPersister);
68 public void testNotificationListenerUnknownNetconfNotification() throws Exception {
69 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
71 testeListener.handleNotification(unknownNetconfNotif, null);
72 Assert.fail("Unknown netconf notification should fail");
73 } catch (final IllegalStateException e) {
74 Mockito.verifyZeroInteractions(mockPersister);
79 public void testNotificationListenerCommitNetconfNotification() throws Exception {
80 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
81 testeListener.handleNotification(commitNetconfNotif, null);
82 Mockito.verify(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class));