X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2FSalRegistrationManagerTest.java;h=4bf473ac6c4d62b678750935a73f13660861660e;hb=0d5980ab7f1b45b5226e8d235fd4672e64dfbbe4;hp=a0282a5fc99483608889daa85c290d188d88094d;hpb=a9803346775508965175a091cb5c5980bc2c277d;p=openflowplugin.git diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManagerTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManagerTest.java index a0282a5fc9..4bf473ac6c 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManagerTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/SalRegistrationManagerTest.java @@ -10,14 +10,12 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; - +import static org.junit.Assert.assertNull; import com.google.common.util.concurrent.Futures; - +import com.google.common.util.concurrent.ListeningExecutorService; import java.math.BigInteger; import java.util.Collections; -import java.util.Set; -import java.util.concurrent.ExecutorService; - +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,18 +23,19 @@ import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.NotificationListener; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; -import org.opendaylight.openflowplugin.openflow.md.core.NotificationEnqueuer; +import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch; +import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor; +import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer; import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; -import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService; -import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; -import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContextOFImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -45,12 +44,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yangtools.concepts.CompositeObjectRegistration; -import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService; /** * Created by Martin Bobak mbobak@cisco.com on 8/26/14. @@ -62,8 +62,8 @@ public class SalRegistrationManagerTest { private static final BigInteger dataPathId = BigInteger.ONE; private SalRegistrationManager salRegistrationManager; - @Mock - private SessionContext context; + + private SessionContextOFImpl context; @Mock private ConnectionConductor conductor; @Mock @@ -74,39 +74,66 @@ public class SalRegistrationManagerTest { private BindingAwareBroker.ProviderContext providerContext; @Mock private NotificationEnqueuer notificationEnqueuer; + @Mock + private ListeningExecutorService rpcPool; + @Mock + private NotificationProviderService notificationProviderService; + @Mock + private RpcProviderRegistry rpcProviderRegistry; + @Mock + private DataBroker dataBroker; + @Mock + private EntityOwnershipService entityOwnershipService; + + @Mock + private ModelDrivenSwitchImpl ofSwitch; private ModelDrivenSwitch mdSwitchOF13; + CompositeObjectRegistration registration; + @Before public void setUp() { - - Mockito.when(context.getPrimaryConductor()).thenReturn(conductor); - Mockito.when(context.getMessageDispatchService()).thenReturn(messageDispatchService); + OFSessionUtil.getSessionManager().setRpcPool(rpcPool); Mockito.when(conductor.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0) .thenReturn(OFConstants.OFP_VERSION_1_3); - Mockito.when(context.getFeatures()).thenReturn(features); - - mdSwitchOF13 = new ModelDrivenSwitchImpl(null, null, context); - registration = new CompositeObjectRegistration<>(mdSwitchOF13, Collections.EMPTY_LIST); - - Mockito.when(context.getProviderRegistration()).thenReturn(registration); - Mockito.when(context.getNotificationEnqueuer()).thenReturn(notificationEnqueuer); + context = new SessionContextOFImpl(); + context.setPrimaryConductor(conductor); Mockito.when(features.getDatapathId()).thenReturn(BigInteger.valueOf(1)); Mockito.when(features.getVersion()).thenReturn((short) 1); + context.setFeatures(features); + context.setNotificationEnqueuer(notificationEnqueuer); + + OfEntityManager entManager = new OfEntityManager(entityOwnershipService); + mdSwitchOF13 = new ModelDrivenSwitchImpl(null, null, context); + registration = new CompositeObjectRegistration<>(mdSwitchOF13, Collections.emptyList()); + context.setProviderRegistration(registration); - Set errorSet = Collections.emptySet(); UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder(); - RpcResult result = Rpcs.getRpcResult(true, updateFlowOutput.build(), errorSet); + RpcResult result = RpcResultBuilder.success(updateFlowOutput.build()).build(); Mockito.when( messageDispatchService.flowMod(Matchers.any(FlowModInput.class), Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result)); salRegistrationManager = new SalRegistrationManager(); - salRegistrationManager.onSessionInitiated(providerContext); - salRegistrationManager.setPublishService(new MockNotificationProviderService()); + salRegistrationManager.setPublishService(notificationProviderService); + salRegistrationManager.setDataService(dataBroker); + salRegistrationManager.setRpcProviderRegistry(rpcProviderRegistry); + salRegistrationManager.setOfEntityManager(entManager); + + salRegistrationManager.init(); + + } + + /** + * free sesion manager + */ + @After + public void tearDown() { + OFSessionUtil.releaseSessionManager(); } /** @@ -114,9 +141,9 @@ public class SalRegistrationManagerTest { */ @Test public void testIdentifierFromDatapathId() { - InstanceIdentifier node = salRegistrationManager.identifierFromDatapathId(dataPathId); + InstanceIdentifier node = SalRegistrationManager.identifierFromDatapathId(dataPathId); assertNotNull(node); - assertEquals("NodeKey [_id=Uri [_value=openflow:1]]", ((KeyedInstanceIdentifier) node).getKey().toString()); + assertEquals("NodeKey [_id=Uri [_value=openflow:1]]", ((KeyedInstanceIdentifier) node).getKey().toString()); } /** @@ -124,7 +151,7 @@ public class SalRegistrationManagerTest { */ @Test public void testNodeKeyFromDatapathId() { - NodeKey nodeKey = salRegistrationManager.nodeKeyFromDatapathId(dataPathId); + NodeKey nodeKey = SalRegistrationManager.nodeKeyFromDatapathId(dataPathId); assertNotNull(nodeKey); assertEquals("openflow:1", nodeKey.getId().getValue()); } @@ -134,7 +161,7 @@ public class SalRegistrationManagerTest { */ @Test public void testNodeIdFromDatapathId() { - NodeId nodeId = salRegistrationManager.nodeIdFromDatapathId(dataPathId); + NodeId nodeId = SalRegistrationManager.nodeIdFromDatapathId(dataPathId); assertNotNull(nodeId); assertEquals("openflow:1", nodeId.getValue()); } @@ -149,49 +176,22 @@ public class SalRegistrationManagerTest { /** - * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionRemoved(org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext)} + * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionRemoved(org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext)} */ @Test public void testOnSessionRemoved() { - salRegistrationManager.onSessionRemoved(context); +// assertNotNull(context.getProviderRegistration()); +// salRegistrationManager.onSessionAdded(null,context); +// salRegistrationManager.onSessionRemoved(context); +// assertNull(context.getProviderRegistration()); } /** - * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionAdded(org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF, org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext)} + * Test for {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SalRegistrationManager#onSessionAdded(org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF, org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext)} */ public void testOnAdded() { SwitchSessionKeyOF switchSessionKeyOF = new SwitchSessionKeyOF(); salRegistrationManager.onSessionAdded(switchSessionKeyOF, context); } - - - private class MockNotificationProviderService implements NotificationProviderService { - - @Override - public void publish(Notification notification) { - - } - - @Override - public void publish(Notification notification, ExecutorService executorService) { - - } - - @Override - public ListenerRegistration registerInterestListener(NotificationInterestListener notificationInterestListener) { - return null; - } - - @Override - public ListenerRegistration> registerNotificationListener(Class tClass, NotificationListener tNotificationListener) { - return null; - } - - @Override - public ListenerRegistration registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener notificationListener) { - return null; - } - } - }