--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import io.netty.channel.Channel;
+import java.util.List;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
+import org.opendaylight.controller.netconf.impl.NetconfServerSession;
+import org.opendaylight.controller.netconf.impl.NetconfServerSessionListener;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
+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.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class NetconfMonitoringServiceImplTest {
+
+ private NetconfMonitoringServiceImpl service;
+
+ @Mock
+ private NetconfOperationProvider operationProvider;
+ @Mock
+ private NetconfManagementSession managementSession;
+ @Mock
+ private NetconfOperationServiceSnapshot snapshot;
+ @Mock
+ private NetconfOperationService operationService;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ service = new NetconfMonitoringServiceImpl(operationProvider);
+ }
+
+ @Test
+ public void testSessions() throws Exception {
+ doReturn("sessToStr").when(managementSession).toString();
+ service.onSessionUp(managementSession);
+ List list = Lists.newArrayList(managementSession);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGetSchemas() throws Exception {
+ doThrow(RuntimeException.class).when(operationProvider).openSnapshot(anyString());
+ service.getSchemas();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetSchemas2() throws Exception {
+ doThrow(Exception.class).when(operationProvider).openSnapshot(anyString());
+ service.getSchemas();
+ }
+
+ @Test
+ public void testGetSchemas3() throws Exception {
+ doReturn("").when(managementSession).toString();
+ Capability cap = mock(Capability.class);
+ Set caps = Sets.newHashSet(cap);
+ Set services = Sets.newHashSet(operationService);
+ doReturn(snapshot).when(operationProvider).openSnapshot(anyString());
+ doReturn(services).when(snapshot).getServices();
+ doReturn(caps).when(operationService).getCapabilities();
+ Optional opt = mock(Optional.class);
+ doReturn(opt).when(cap).getCapabilitySchema();
+ doReturn(true).when(opt).isPresent();
+ doReturn(opt).when(cap).getModuleNamespace();
+ doReturn("namespace").when(opt).get();
+ Optional optRev = Optional.of("rev");
+ doReturn(optRev).when(cap).getRevision();
+ doReturn(Optional.of("modName")).when(cap).getModuleName();
+ doReturn(Optional.of(Lists.newArrayList("loc"))).when(cap).getLocation();
+ doNothing().when(snapshot).close();
+
+ assertNotNull(service.getSchemas());
+ verify(snapshot, times(1)).close();
+
+ NetconfServerSessionListener sessionListener = mock(NetconfServerSessionListener.class);
+ Channel channel = mock(Channel.class);
+ NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("name", "addr", "2", "tcp", "id");
+ NetconfServerSession sm = new NetconfServerSession(sessionListener, channel, 10, header);
+ doNothing().when(sessionListener).onSessionUp(any(NetconfServerSession.class));
+ sm.sessionUp();
+ service.onSessionUp(sm);
+ assertEquals(1, service.getSessions().getSession().size());
+
+ assertEquals(Long.valueOf(10), service.getSessions().getSession().get(0).getSessionId());
+
+ service.onSessionDown(sm);
+ assertEquals(0, service.getSessions().getSession().size());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.mapping.operations;
+
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
+public class DefaultCloseSessionTest {
+ @Test
+ public void testDefaultCloseSession() throws Exception {
+ AutoCloseable res = mock(AutoCloseable.class);
+ doNothing().when(res).close();
+ DefaultCloseSession session = new DefaultCloseSession("", res);
+ Document doc = XmlUtil.newDocument();
+ XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
+ session.handleWithNoSubsequentOperations(doc, elem);
+ }
+
+ @Test(expected = NetconfDocumentedException.class)
+ public void testDefaultCloseSession2() throws Exception {
+ AutoCloseable res = mock(AutoCloseable.class);
+ doThrow(NetconfDocumentedException.class).when(res).close();
+ DefaultCloseSession session = new DefaultCloseSession("", res);
+ Document doc = XmlUtil.newDocument();
+ XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
+ session.handleWithNoSubsequentOperations(doc, elem);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.mapping.operations;
+
+import com.google.common.collect.Sets;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
+import org.opendaylight.controller.netconf.impl.NetconfServerSession;
+import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import static org.mockito.Mockito.*;
+
+public class DefaultCommitTest {
+
+ private NetconfOperationChainedExecution operation;
+ private Document requestMessage;
+ private NetconfOperationRouter router;
+ private DefaultCommitNotificationProducer notifier;
+ private CapabilityProvider cap;
+ private DefaultCommit commit;
+
+ @Before
+ public void setUp() throws Exception {
+ operation = mock(NetconfOperationChainedExecution.class);
+ doReturn(XmlUtil.newDocument()).when(operation).execute(any(Document.class));
+ router = mock(NetconfOperationRouter.class);
+ doReturn(false).when(operation).isExecutionTermination();
+ notifier = mock(DefaultCommitNotificationProducer.class);
+ doNothing().when(notifier).sendCommitNotification(anyString(), any(Element.class), anySetOf(String.class));
+ cap = mock(CapabilityProvider.class);
+ doReturn(Sets.newHashSet()).when(cap).getCapabilities();
+ Document rpcData = XmlFileLoader.xmlFileToDocument("netconfMessages/editConfig_expectedResult.xml");
+ doReturn(rpcData).when(router).onNetconfMessage(any(Document.class), any(NetconfServerSession.class));
+ commit = new DefaultCommit(notifier, cap, "", router);
+ }
+
+ @Test
+ public void testHandleWithNotification() throws Exception {
+ requestMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/commit.xml");
+ commit.handle(requestMessage, operation);
+ verify(operation, times(1)).execute(requestMessage);
+ verify(notifier, times(1)).sendCommitNotification(anyString(), any(Element.class), anySetOf(String.class));
+ }
+
+ @Test
+ public void testHandleWithoutNotification() throws Exception {
+ requestMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/commit.xml");
+ Element elem = requestMessage.getDocumentElement();
+ elem.setAttribute("notify", "false");
+ commit.handle(requestMessage, operation);
+ verify(operation, times(1)).execute(requestMessage);
+ verify(notifier, never()).sendCommitNotification(anyString(), any(Element.class), anySetOf(String.class));
+ }
+
+ @Test(expected = NetconfDocumentedException.class)
+ public void testHandle() throws Exception {
+ Document rpcData = XmlFileLoader.xmlFileToDocument("netconfMessages/get.xml");
+ doReturn(rpcData).when(router).onNetconfMessage(any(Document.class), any(NetconfServerSession.class));
+ requestMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/commit.xml");
+ commit.handle(requestMessage, operation);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.mapping.operations;
+
+import com.google.common.base.Optional;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
+public class DefaultGetSchemaTest {
+
+ private CapabilityProvider cap;
+ private Document doc;
+ private String getSchema;
+
+ @Before
+ public void setUp() throws Exception {
+ cap = mock(CapabilityProvider.class);
+ doc = XmlUtil.newDocument();
+ getSchema = "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
+ " <identifier>threadpool-api</identifier>\n" +
+ " <version>2010-09-24</version>\n" +
+ " <format\n" +
+ " xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">ncm:yang\n" +
+ " </format>\n" +
+ " </get-schema>";
+ }
+
+ @Test(expected = NetconfDocumentedException.class)
+ public void testDefaultGetSchema() throws Exception {
+ DefaultGetSchema schema = new DefaultGetSchema(cap, "");
+ doThrow(IllegalStateException.class).when(cap).getSchemaForCapability(anyString(), any(Optional.class));
+ schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema)));
+ }
+
+ @Test
+ public void handleWithNoSubsequentOperations() throws Exception {
+ DefaultGetSchema schema = new DefaultGetSchema(cap, "");
+ doReturn("").when(cap).getSchemaForCapability(anyString(), any(Optional.class));
+ assertNotNull(schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema))));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.mapping.operations;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelPipeline;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.impl.NetconfServerSession;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.*;
+
+public class DefaultStopExiTest {
+ @Test
+ public void testHandleWithNoSubsequentOperations() throws Exception {
+ DefaultStopExi exi = new DefaultStopExi("");
+ Document doc = XmlUtil.newDocument();
+ Channel channel = mock(Channel.class);
+ ChannelPipeline pipeline = mock(ChannelPipeline.class);
+ doReturn(pipeline).when(channel).pipeline();
+ ChannelHandler channelHandler = mock(ChannelHandler.class);
+ doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
+
+ NetconfServerSession serverSession = new NetconfServerSession(null, channel, 2L, null);
+ exi.setNetconfSession(serverSession);
+
+ assertNotNull(exi.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"))));
+ verify(pipeline, times(1)).replace(anyString(), anyString(), any(ChannelHandler.class));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.osgi;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Dictionary;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
+import org.osgi.framework.*;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+public class NetconfImplActivatorTest {
+
+ @Mock
+ private BundleContext bundle;
+ @Mock
+ private Filter filter;
+ @Mock
+ private ServiceReference reference;
+ @Mock
+ private ServiceRegistration registration;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ doReturn(filter).when(bundle).createFilter(anyString());
+ doNothing().when(bundle).addServiceListener(any(ServiceListener.class), anyString());
+
+ ServiceReference[] refs = new ServiceReference[0];
+ doReturn(refs).when(bundle).getServiceReferences(anyString(), anyString());
+ doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), anyString());
+ doReturn("").when(bundle).getProperty(anyString());
+ doReturn(registration).when(bundle).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
+ doNothing().when(registration).unregister();
+ doNothing().when(bundle).removeServiceListener(any(ServiceListener.class));
+ }
+
+ @Test
+ public void testStart() throws Exception {
+ NetconfImplActivator activator = new NetconfImplActivator();
+ activator.start(bundle);
+ verify(bundle, times(2)).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
+ activator.stop(bundle);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.osgi;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+public class NetconfOperationServiceFactoryTrackerTest {
+
+ @Mock
+ private Filter filter;
+ @Mock
+ private BundleContext context;
+ @Mock
+ private NetconfOperationServiceFactoryListener listener;
+ @Mock
+ private NetconfOperationServiceFactory factory;
+ @Mock
+ private ServiceReference reference;
+
+ private NetconfOperationServiceFactoryTracker tracker;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
+ doReturn(filter).when(context).createFilter(anyString());
+ doReturn("").when(reference).toString();
+ doReturn(factory).when(context).getService(any(ServiceReference.class));
+ doReturn("").when(factory).toString();
+ doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
+ tracker = new NetconfOperationServiceFactoryTracker(context, listener);
+ }
+
+ @Test
+ public void testNetconfOperationServiceFactoryTracker() throws Exception {
+ tracker.removedService(null, factory);
+ verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
+ }
+
+ @Test
+ public void testAddingService() throws Exception {
+ assertNotNull(tracker.addingService(reference));
+ verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.impl.util;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.util.concurrent.GenericFutureListener;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.*;
+
+public class DeserializerExceptionHandlerTest {
+
+ private DeserializerExceptionHandler handler;
+ private ChannelFuture channelFuture;
+ private ChannelHandlerContext context;
+ private Channel channel;
+
+ @Before
+ public void setUp() throws Exception {
+ handler = new DeserializerExceptionHandler();
+ context = mock(ChannelHandlerContext.class);
+ channel = mock(Channel.class);
+ doReturn(channel).when(context).channel();
+ channelFuture = mock(ChannelFuture.class);
+ doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
+ doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
+ }
+
+ @Test
+ public void testExceptionCaught() throws Exception {
+ handler.exceptionCaught(context, new Exception());
+ verify(context, times(1)).channel();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.monitoring.osgi;
+
+import java.util.Arrays;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class NetconfMonitoringActivatorTest {
+
+ @Mock
+ BundleContext context;
+ @Mock
+ Filter filter;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ doReturn(filter).when(context).createFilter(anyString());
+ doNothing().when(context).addServiceListener(any(ServiceListener.class), anyString());
+ ServiceReference[] refs = new ServiceReference[2];
+ doReturn(Arrays.asList(refs)).when(context).getServiceReferences(any(Class.class), anyString());
+ doReturn(refs).when(context).getServiceReferences(anyString(), anyString());
+ }
+
+ @Test
+ public void testNetconfMonitoringActivator() throws Exception {
+ NetconfMonitoringActivator activator = new NetconfMonitoringActivator();
+ activator.start(context);
+ verify(context, times(1)).addServiceListener(any(ServiceListener.class), anyString());
+
+ activator.stop(context);
+ verify(context, times(1)).removeServiceListener(any(ServiceListener.class));
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.monitoring.osgi;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.controller.netconf.monitoring.MonitoringConstants;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+public class NetconfMonitoringOperationServiceTest {
+ @Test
+ public void testGetters() throws Exception {
+ NetconfMonitoringService monitor = mock(NetconfMonitoringService.class);
+ NetconfMonitoringOperationService service = new NetconfMonitoringOperationService(monitor);
+
+ assertEquals(1, service.getNetconfOperations().size());
+
+ assertEquals(Optional.absent(), service.getCapabilities().iterator().next().getCapabilitySchema());
+ assertEquals(Optional.absent(), service.getCapabilities().iterator().next().getLocation());
+ assertEquals(Optional.of(MonitoringConstants.MODULE_REVISION), service.getCapabilities().iterator().next().getRevision());
+ assertEquals(Optional.of(MonitoringConstants.MODULE_NAME), service.getCapabilities().iterator().next().getModuleName());
+ assertEquals(Optional.of(MonitoringConstants.NAMESPACE), service.getCapabilities().iterator().next().getModuleNamespace());
+ assertEquals(MonitoringConstants.URI, service.getCapabilities().iterator().next().getCapabilityUri());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.netconf.monitoring.osgi;
+
+import java.util.Hashtable;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Mockito.*;
+
+public class NetconfMonitoringServiceTrackerTest {
+
+ @Mock
+ private ServiceReference reference;
+ @Mock
+ private BundleContext context;
+ @Mock
+ private ServiceRegistration serviceRegistration;
+ @Mock
+ private Filter filter;
+ @Mock
+ private NetconfMonitoringService monitoringService;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ doReturn(serviceRegistration).when(context).registerService(any(Class.class), any(NetconfOperationServiceFactory.class), any(Hashtable.class));
+ doNothing().when(serviceRegistration).unregister();
+ doReturn(filter).when(context).createFilter(anyString());
+ doReturn("").when(reference).toString();
+ doReturn(monitoringService).when(context).getService(any(ServiceReference.class));
+ }
+
+ @Test
+ public void testAddingService() throws Exception {
+ NetconfMonitoringServiceTracker tracker = new NetconfMonitoringServiceTracker(context);
+ tracker.addingService(reference);
+ verify(context, times(1)).registerService(any(Class.class), any(NetconfOperationServiceFactory.class), any(Hashtable.class));
+ tracker.removedService(reference, null);
+ verify(serviceRegistration, times(1)).unregister();
+ }
+}