X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fimpl%2FConfigPersisterNotificationListenerTest.java;fp=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2FConfigPersisterNotificationListenerTest.java;h=1d5d0132d9f91c6447dd1d8adaf8894e812c3eca;hp=f0cd267dd6a77c03487616e03abd5a01151a5bb6;hb=refs%2Fchanges%2F13%2F23413%2F26;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2 diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationListenerTest.java b/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/ConfigPersisterNotificationListenerTest.java similarity index 50% rename from opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationListenerTest.java rename to opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/ConfigPersisterNotificationListenerTest.java index f0cd267dd6..1d5d0132d9 100644 --- a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationListenerTest.java +++ b/opendaylight/config/config-persister-impl/src/test/java/org/opendaylight/controller/config/persist/impl/ConfigPersisterNotificationListenerTest.java @@ -6,23 +6,33 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.persist.impl; +package org.opendaylight.controller.config.persist.impl; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; + +import com.google.common.base.Optional; import com.google.common.collect.Lists; import java.util.Collections; import javax.management.Notification; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.config.api.jmx.notifications.CommitJMXNotification; +import org.opendaylight.controller.config.api.jmx.notifications.ConfigJMXNotification; +import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade; +import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory; +import org.opendaylight.controller.config.facade.xml.Datastore; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.api.Persister; -import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; -import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.opendaylight.controller.config.util.ConfigRegistryClient; +import org.opendaylight.controller.config.util.capability.Capability; +import org.opendaylight.controller.config.util.xml.XmlUtil; +import org.w3c.dom.Document; public class ConfigPersisterNotificationListenerTest { @@ -31,39 +41,52 @@ public class ConfigPersisterNotificationListenerTest { private PersisterAggregator persisterAggregator; @Mock - private NetconfJMXNotification unknownNetconfNotif; + private ConfigJMXNotification unknownNetconfNotif; @Mock private CommitJMXNotification commitNetconfNotif; @Mock private Notification unknownNotif; + @Mock + private ConfigSubsystemFacadeFactory facadeFactory; + @Mock + private ConfigSubsystemFacade facade; + @Mock + private ConfigRegistryClient configRegistryClient; + @Mock + private Capability cap; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - Mockito.doNothing().when(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class)); - Mockito.doReturn("persister").when(mockPersister).toString(); + Mockito.doNothing().when(mockPersister).persistConfig(any(ConfigSnapshotHolder.class)); + doReturn("persister").when(mockPersister).toString(); final PersisterAggregator.PersisterWithConfiguration withCfg = new PersisterAggregator.PersisterWithConfiguration(mockPersister, false); persisterAggregator = new PersisterAggregator(Lists.newArrayList(withCfg)); - Mockito.doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString(); - Mockito.doReturn("netconfCommitNotification").when(commitNetconfNotif).toString(); + doReturn("netconfUnknownNotification").when(unknownNetconfNotif).toString(); + doReturn("netconfCommitNotification").when(commitNetconfNotif).toString(); + + doReturn("config client").when(configRegistryClient).toString(); - Mockito.doReturn(XmlUtil.readXmlToElement("")).when(commitNetconfNotif).getConfigSnapshot(); - Mockito.doReturn(Collections.emptySet()).when(commitNetconfNotif).getCapabilities(); + doReturn("cap").when(cap).getCapabilityUri(); + doReturn(facade).when(facadeFactory).createFacade(anyString()); + doReturn(Collections.singleton(cap)).when(facadeFactory).getCurrentCapabilities(); + doReturn(XmlUtil.readXmlToElement("")).when(facade) + .getConfiguration(any(Document.class), any(Datastore.class), any(Optional.class)); } @Test public void testNotificationListenerUnknownNotification() throws Exception { - final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator); + final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator, facadeFactory); testeListener.handleNotification(unknownNotif, null); Mockito.verifyZeroInteractions(mockPersister); } @Test public void testNotificationListenerUnknownNetconfNotification() throws Exception { - final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator); + final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator, facadeFactory); try { testeListener.handleNotification(unknownNetconfNotif, null); Assert.fail("Unknown netconf notification should fail"); @@ -74,8 +97,8 @@ public class ConfigPersisterNotificationListenerTest { @Test public void testNotificationListenerCommitNetconfNotification() throws Exception { - final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator); + final ConfigPersisterNotificationListener testeListener = new ConfigPersisterNotificationListener(persisterAggregator, facadeFactory); testeListener.handleNotification(commitNetconfNotif, null); - Mockito.verify(mockPersister).persistConfig(Matchers.any(ConfigSnapshotHolder.class)); + Mockito.verify(mockPersister).persistConfig(any(ConfigSnapshotHolder.class)); } }