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 com.google.common.collect.Lists;
12 import java.util.Collections;
13 import javax.management.Notification;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Matchers;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
22 import org.opendaylight.controller.config.persist.api.Persister;
23 import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification;
24 import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification;
25 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
27 public class ConfigPersisterNotificationListenerTest {
30 private Persister mockPersister;
31 private PersisterAggregator persisterAggregator;
34 private NetconfJMXNotification unknownNetconfNotif;
36 private CommitJMXNotification commitNetconfNotif;
38 private Notification unknownNotif;
41 public void setUp() throws Exception {
42 MockitoAnnotations.initMocks(this);
44 Mockito.doNothing().when(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class));
45 Mockito.doReturn("persister").when(mockPersister).toString();
46 final PersisterAggregator.PersisterWithConfiguration withCfg = new PersisterAggregator.PersisterWithConfiguration(mockPersister, false);
47 persisterAggregator = new PersisterAggregator(Lists.newArrayList(withCfg));
49 Mockito.doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString();
50 Mockito.doReturn("netconfCommitNotification").when(commitNetconfNotif).toString();
52 Mockito.doReturn(XmlUtil.readXmlToElement("<config-snapshot/>")).when(commitNetconfNotif).getConfigSnapshot();
53 Mockito.doReturn(Collections.emptySet()).when(commitNetconfNotif).getCapabilities();
58 public void testNotificationListenerUnknownNotification() throws Exception {
59 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
60 testeListener.handleNotification(unknownNotif, null);
61 Mockito.verifyZeroInteractions(mockPersister);
65 public void testNotificationListenerUnknownNetconfNotification() throws Exception {
66 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
68 testeListener.handleNotification(unknownNetconfNotif, null);
69 Assert.fail("Unknown netconf notification should fail");
70 } catch (final IllegalStateException e) {
71 Mockito.verifyZeroInteractions(mockPersister);
76 public void testNotificationListenerCommitNetconfNotification() throws Exception {
77 final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
78 testeListener.handleNotification(commitNetconfNotif, null);
79 Mockito.verify(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class));