*/
package org.opendaylight.controller.netconf.it;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.opendaylight.controller.config.util.xml.XmlUtil.readXmlToDocument;
import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElementWithName;
import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertElementsCount;
-import static org.opendaylight.controller.netconf.util.xml.XmlUtil.readXmlToDocument;
+import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import java.io.IOException;
-import java.lang.management.ManagementFactory;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.util.Collections;
import java.util.List;
-import java.util.Set;
import javax.management.InstanceNotFoundException;
import javax.management.Notification;
import javax.management.NotificationListener;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.opendaylight.controller.config.api.jmx.notifications.CommitJMXNotification;
+import org.opendaylight.controller.config.api.jmx.notifications.ConfigJMXNotification;
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
import org.opendaylight.controller.config.persist.api.Persister;
+import org.opendaylight.controller.config.persist.impl.ConfigPersisterNotificationHandler;
import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification;
-import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
-import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
-import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
-import org.opendaylight.controller.netconf.mapping.api.Capability;
-import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
-import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
-import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
-import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator;
-import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService;
-import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
+import org.opendaylight.controller.netconf.client.TestingNetconfClient;
import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
+import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.xml.sax.SAXException;
public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest {
public static final int PORT = 12026;
private static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT);
- private NetconfMonitoringServiceImpl netconfMonitoringService;
-
- @Override
- protected void setUpTestInitial() {
- netconfMonitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider());
- }
-
- @Override
- protected SessionMonitoringService getNetconfMonitoringService() throws Exception {
- return netconfMonitoringService;
- }
-
@Override
protected SocketAddress getTcpServerAddress() {
return TCP_ADDRESS;
}
- @Override
- protected Iterable<NetconfOperationServiceFactory> getAdditionalServiceFactories() {
- return Collections.<NetconfOperationServiceFactory>singletonList(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
- new NetconfMonitoringOperationService(netconfMonitoringService)));
- }
-
- @Override
- protected DefaultCommitNotificationProducer getNotificationProducer() {
- return new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
- }
-
@Test
public void testNetconfCommitNotifications() throws Exception {
final VerifyingNotificationListener notificationVerifier = createCommitNotificationListener();
try (TestingNetconfClient persisterClient = new TestingNetconfClient("persister", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) {
try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(
- platformMBeanServer, mockedAggregator)) {
-
+ platformMBeanServer, mockedAggregator, configSubsystemFacadeFactory)) {
try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) {
- NetconfMessage response = netconfClient.sendMessage(loadGetConfigMessage());
- assertContainsElementWithName(response.getDocument(), "modules");
- assertContainsElementWithName(response.getDocument(), "services");
- response = netconfClient.sendMessage(loadCommitMessage());
- assertContainsElementWithName(response.getDocument(), "ok");
-
- response = netconfClient.sendMessage(loadEditConfigMessage());
+ NetconfMessage response = netconfClient.sendMessage(loadEditConfigMessage());
assertContainsElementWithName(response.getDocument(), "ok");
response = netconfClient.sendMessage(loadCommitMessage());
assertContainsElementWithName(response.getDocument(), "ok");
+
+ response = netconfClient.sendMessage(loadGetConfigMessage());
+ assertContainsElementWithName(response.getDocument(), "modules");
+ assertContainsElementWithName(response.getDocument(), "services");
}
}
}
- notificationVerifier.assertNotificationCount(2);
- notificationVerifier.assertNotificationContent(0, 0, 0, 8);
- notificationVerifier.assertNotificationContent(1, 4, 3, 8);
+ notificationVerifier.assertNotificationCount(1);
- mockedAggregator.assertSnapshotCount(2);
+ mockedAggregator.assertSnapshotCount(1);
// Capabilities are stripped for persister
- mockedAggregator.assertSnapshotContent(0, 0, 0, 1);
- mockedAggregator.assertSnapshotContent(1, 4, 3, 3);
+ mockedAggregator.assertSnapshotContent(0, 4, 3, 3);
+ }
+
+ @Override
+ protected BindingRuntimeContext getBindingRuntimeContext() {
+ final BindingRuntimeContext ret = super.getBindingRuntimeContext();
+ doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME);
+ doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME);
+ final HashBiMap<String, String> toBeReturned = HashBiMap.create();
+ toBeReturned.put("two", "Two");
+ toBeReturned.put("one", "One");
+ toBeReturned.put("version1", "Version1");
+ doReturn(toBeReturned).when(ret).getEnumMapping(anyString());
+ return ret;
}
private VerifyingPersister mockAggregator() throws IOException {
private VerifyingNotificationListener createCommitNotificationListener() throws InstanceNotFoundException {
final VerifyingNotificationListener listener = new VerifyingNotificationListener();
- platformMBeanServer.addNotificationListener(DefaultCommitNotificationProducer.OBJECT_NAME, listener, null, null);
+ platformMBeanServer.addNotificationListener(ConfigJMXNotification.OBJECT_NAME, listener, null, null);
return listener;
}
return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml");
}
-
- public NetconfOperationProvider getNetconfOperationProvider() {
- final NetconfOperationProvider factoriesListener = mock(NetconfOperationProvider.class);
- final NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class);
- final NetconfOperationService service = mock(NetconfOperationService.class);
- final Set<Capability> caps = Sets.newHashSet();
- doReturn(caps).when(service).getCapabilities();
- final Set<NetconfOperationService> services = Sets.newHashSet(service);
- doReturn(services).when(snap).getServices();
- doReturn(snap).when(factoriesListener).openSnapshot(anyString());
-
- return factoriesListener;
- }
-
private static class VerifyingNotificationListener implements NotificationListener {
public List<Notification> notifications = Lists.newArrayList();
assertEquals(size, notifications.size());
}
- void assertNotificationContent(final int notificationIndex, final int expectedModulesSize, final int expectedServicesSize, final int expectedCapsSize) {
+ void assertNotificationContent(final int notificationIndex) {
final Notification notification = notifications.get(notificationIndex);
assertEquals(CommitJMXNotification.class, notification.getClass());
- final int capsSize = ((CommitJMXNotification) notification).getCapabilities().size();
- assertEquals("Expected capabilities count", expectedCapsSize, capsSize);
- final Element configSnapshot = ((CommitJMXNotification) notification).getConfigSnapshot();
- final int modulesSize = configSnapshot.getElementsByTagName("module").getLength();
- assertEquals("Expected modules count", expectedModulesSize, modulesSize);
- final int servicesSize = configSnapshot.getElementsByTagName("instance").getLength();
- assertEquals("Expected services count", expectedServicesSize, servicesSize);
}
}
throws SAXException, IOException {
final ConfigSnapshotHolder snapshot = snapshots.get(notificationIndex);
final int capsSize = snapshot.getCapabilities().size();
- assertEquals("Expected capabilities count", expectedCapsSize, capsSize);
+ assertEquals("Expected capabilities count should be " + expectedCapsSize + " but was " + snapshot.getCapabilities(), expectedCapsSize, capsSize);
final Document configSnapshot = readXmlToDocument(snapshot.getConfigSnapshot());
assertElementsCount(configSnapshot, "module", expectedModulesSize);
assertElementsCount(configSnapshot, "instance", expectedServicesSize);