From: Moiz Raja Date: Thu, 16 Oct 2014 17:03:23 +0000 (+0000) Subject: Merge "Bug-1607: Clustering : Remove actorFor (deprecated) call from TransactionProx... X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3c2de556e2b813b8da925199cb2dc4389c76ef39;hp=c7e58fea5640aab14820b172d42d234f04249cd1;p=controller.git Merge "Bug-1607: Clustering : Remove actorFor (deprecated) call from TransactionProxy.java" --- diff --git a/opendaylight/config/config-api/src/main/yang/config.yang b/opendaylight/config/config-api/src/main/yang/config.yang index a0a4292adf..5d6c11fbee 100644 --- a/opendaylight/config/config-api/src/main/yang/config.yang +++ b/opendaylight/config/config-api/src/main/yang/config.yang @@ -122,7 +122,9 @@ module config { the actual service-type which is actually required."; mandatory true; - type service-type-ref; + type leafref { + path "/config:services/config:service/config:type"; + } } leaf name { diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java index 98f0908dc7..c6f4be64bb 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/InternalJMXRegistrator.java @@ -53,6 +53,7 @@ public class InternalJMXRegistrator implements Closeable { @GuardedBy("this") private final Set registeredObjectNames = new HashSet<>(); + @GuardedBy("this") private final List children = new ArrayList<>(); public synchronized InternalJMXRegistration registerMBean(Object object, @@ -79,9 +80,8 @@ public class InternalJMXRegistrator implements Closeable { } } - public InternalJMXRegistrator createChild() { - InternalJMXRegistrator child = new InternalJMXRegistrator( - configMBeanServer); + public synchronized InternalJMXRegistrator createChild() { + InternalJMXRegistrator child = new InternalJMXRegistrator(configMBeanServer); children.add(child); return child; } @@ -137,7 +137,7 @@ public class InternalJMXRegistrator implements Closeable { return getSameNames(result); } - private Set getSameNames(Set superSet) { + private synchronized Set getSameNames(Set superSet) { Set result = new HashSet<>(superSet); result.retainAll(registeredObjectNames); for (InternalJMXRegistrator child : children) { diff --git a/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleTest.java b/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleTest.java index 4cc9cc3dde..54c87604a4 100644 --- a/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleTest.java +++ b/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/ImmediateEventExecutorModuleTest.java @@ -21,12 +21,12 @@ import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; public class ImmediateEventExecutorModuleTest extends AbstractConfigTest { - private GlobalEventExecutorModuleFactory factory; + private ImmediateEventExecutorModuleFactory factory; private final String instanceName = ImmediateEventExecutorModuleFactory.SINGLETON_NAME; @Before public void setUp() { - factory = new GlobalEventExecutorModuleFactory(); + factory = new ImmediateEventExecutorModuleFactory(); super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory)); } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java index 4fc0cf75b3..6a8e3c0e5b 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.java @@ -7,9 +7,7 @@ */ package org.opendaylight.controller.sal.compatibility; -import java.util.Dictionary; -import java.util.Hashtable; - +import com.google.common.base.Preconditions; import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.IClusterGlobalServices; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; @@ -36,7 +34,8 @@ import org.opendaylight.controller.sal.utils.INodeConnectorFactory; import org.opendaylight.controller.sal.utils.INodeFactory; import org.osgi.framework.BundleContext; -import com.google.common.base.Preconditions; +import java.util.Dictionary; +import java.util.Hashtable; public class ComponentActivator extends ComponentActivatorAbstractBase { private final INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory(); @@ -90,8 +89,8 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { @Override public void start(final BundleContext context) { - super.start(context); this.context = Preconditions.checkNotNull(context); + super.start(context); } public ProviderContext setBroker(final BindingAwareBroker broker) { @@ -101,14 +100,14 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { @Override protected Object[] getGlobalImplementations() { return new Object[] { + this, // Used for setBroker callback flow, inventory, dataPacket, nodeFactory, nodeConnectorFactory, topology, - tpProvider, - this // Used for setBroker callback + tpProvider }; } @@ -216,6 +215,9 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { .setService(IDiscoveryService.class) .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") .setRequired(false)); + it.add(createServiceDependency() + .setService(BindingAwareBroker.class) + .setRequired(true)); } private void _instanceConfigure(final InventoryAndReadAdapter imp, final Component it, String containerName) { @@ -232,6 +234,9 @@ public class ComponentActivator extends ComponentActivatorAbstractBase { .setService(IPluginOutInventoryService.class) .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher") .setRequired(false)); + it.add(createServiceDependency() + .setService(BindingAwareBroker.class) + .setRequired(true)); } private void _configure(final TopologyAdapter imp, final Component it) { diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java index 3a6de300a0..bab26dfc01 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java @@ -16,7 +16,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; import javax.xml.stream.FactoryConfigurationError; @@ -28,6 +27,8 @@ import org.opendaylight.controller.sal.rest.api.RestconfService; import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext; import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; +import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; +import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -72,7 +73,9 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter deleteDataViaTransaction( final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType datastore, YangInstanceIdentifier path) { - LOG.info("Delete " + datastore.name() + " via Restconf: {}", path); + LOG.trace("Delete " + datastore.name() + " via Restconf: {}", path); writeTransaction.delete(datastore, path); return writeTransaction.submit(); } diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java new file mode 100644 index 0000000000..1b078be9a4 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfMonitoringServiceImplTest.java @@ -0,0 +1,111 @@ +/* + * 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()); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSessionTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSessionTest.java new file mode 100644 index 0000000000..ae3d65646f --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSessionTest.java @@ -0,0 +1,42 @@ +/* + * 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("")); + 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("")); + session.handleWithNoSubsequentOperations(doc, elem); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java new file mode 100644 index 0000000000..98050de565 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java @@ -0,0 +1,76 @@ +/* + * 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); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchemaTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchemaTest.java new file mode 100644 index 0000000000..b655e90f2b --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchemaTest.java @@ -0,0 +1,60 @@ +/* + * 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 = "\n" + + " threadpool-api\n" + + " 2010-09-24\n" + + " ncm:yang\n" + + " \n" + + " "; + } + + @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)))); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultStopExiTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultStopExiTest.java new file mode 100644 index 0000000000..b335165706 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultStopExiTest.java @@ -0,0 +1,40 @@ +/* + * 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("")))); + verify(pipeline, times(1)).replace(anyString(), anyString(), any(ChannelHandler.class)); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java new file mode 100644 index 0000000000..b59ea884c5 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivatorTest.java @@ -0,0 +1,58 @@ +/* + * 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); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java new file mode 100644 index 0000000000..374e8aeb9f --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java @@ -0,0 +1,62 @@ +/* + * 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)); + } +} diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/util/DeserializerExceptionHandlerTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/util/DeserializerExceptionHandlerTest.java new file mode 100644 index 0000000000..6512b4bd33 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/util/DeserializerExceptionHandlerTest.java @@ -0,0 +1,43 @@ +/* + * 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(); + } +} diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivatorTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivatorTest.java new file mode 100644 index 0000000000..40493569d6 --- /dev/null +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivatorTest.java @@ -0,0 +1,51 @@ +/* + * 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)); + } +} diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java new file mode 100644 index 0000000000..b8e35e934b --- /dev/null +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java @@ -0,0 +1,34 @@ +/* + * 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()); + } +} diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTrackerTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTrackerTest.java new file mode 100644 index 0000000000..2a53a6ce45 --- /dev/null +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTrackerTest.java @@ -0,0 +1,58 @@ +/* + * 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(); + } +} diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/Activator.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/Activator.java index 0f11284e53..deecf26e0d 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/Activator.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/Activator.java @@ -77,7 +77,7 @@ public class Activator extends ComponentActivatorAbstractBase { c.add(createContainerServiceDependency(containerName).setService( IInventoryService.class).setCallbacks( "setInventoryService", "unsetInventoryService") - .setRequired(false)); + .setRequired(true)); c.add(createContainerServiceDependency(containerName).setService( IStatisticsManager.class).setCallbacks( "setStatisticsManager", "unsetStatisticsManager")