Fix checkstyle warnings for config-persister-impl
[controller.git] / opendaylight / netconf / config-persister-impl / src / test / java / org / opendaylight / controller / netconf / persist / impl / ConfigPersisterNotificationListenerTest.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.netconf.persist.impl;
10
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;
26
27 public class ConfigPersisterNotificationListenerTest {
28
29     @Mock
30     private Persister mockPersister;
31     private PersisterAggregator persisterAggregator;
32
33     @Mock
34     private NetconfJMXNotification unknownNetconfNotif;
35     @Mock
36     private CommitJMXNotification commitNetconfNotif;
37     @Mock
38     private Notification unknownNotif;
39
40     @Before
41     public void setUp() throws Exception {
42         MockitoAnnotations.initMocks(this);
43
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));
48
49         Mockito.doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString();
50         Mockito.doReturn("netconfCommitNotification").when(commitNetconfNotif).toString();
51
52         Mockito.doReturn(XmlUtil.readXmlToElement("<config-snapshot/>")).when(commitNetconfNotif).getConfigSnapshot();
53         Mockito.doReturn(Collections.emptySet()).when(commitNetconfNotif).getCapabilities();
54
55     }
56
57     @Test
58     public void testNotificationListenerUnknownNotification() throws Exception {
59         final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
60         testeListener.handleNotification(unknownNotif, null);
61         Mockito.verifyZeroInteractions(mockPersister);
62     }
63
64     @Test
65     public void testNotificationListenerUnknownNetconfNotification() throws Exception {
66         final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator);
67         try {
68             testeListener.handleNotification(unknownNetconfNotif, null);
69             Assert.fail("Unknown netconf notification should fail");
70         } catch (final IllegalStateException e) {
71             Mockito.verifyZeroInteractions(mockPersister);
72         }
73     }
74
75     @Test
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));
80     }
81 }