X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Frpc%2FRpcManagerImplTest.java;h=90c920f6f78a181fbd36da439b83992fc4ebc9b2;hb=cfe3a97837951ebbedb337dc988027f10c49f714;hp=fe01124d6c94ab26c7fd4ccd7e398da7e40eccb3;hpb=85a27decf79695a8a0a2dcd21325dc5336398860;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java index fe01124d6c..90c920f6f7 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -7,46 +7,39 @@ */ package org.opendaylight.openflowplugin.impl.rpc; -import com.google.common.base.VerifyException; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.verify; + +import java.util.concurrent.ConcurrentMap; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; -import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler; -import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler; -import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor; -import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry; import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; +import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder; +import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; -import java.util.concurrent.ConcurrentMap; - -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - - @RunWith(MockitoJUnitRunner.class) public class RpcManagerImplTest { @@ -54,135 +47,61 @@ public class RpcManagerImplTest { private RpcManagerImpl rpcManager; @Mock - private ProviderContext rpcProviderRegistry; + private RpcProviderService rpcProviderRegistry; @Mock private DeviceContext deviceContext; @Mock - private DeviceInitializationPhaseHandler deviceINitializationPhaseHandler; + private ObjectRegistration routedRpcRegistration; @Mock - private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler; + private DeviceState deviceState; @Mock - private BindingAwareBroker.RoutedRpcRegistration routedRpcRegistration; + private ConnectionContext connectionContext; @Mock - private DeviceState deviceState; + private MessageSpy messageSpy; @Mock - private MessageSpy mockMsgSpy; + private RpcContext removedContexts; @Mock - private LifecycleConductor conductor; + private ConcurrentMap contexts; @Mock - private ConnectionContext connectionContext; + private DeviceInfo deviceInfo; @Mock - private ItemLifeCycleRegistry itemLifeCycleRegistry; + private ExtensionConverterProvider extensionConverterProvider; @Mock - private MessageSpy messageSpy; + private ConvertorExecutor convertorExecutor; @Mock - private RpcContext removedContexts; + private NotificationPublishService notificationPublishService; @Mock - private ConcurrentMap contexts; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private KeyedInstanceIdentifier nodePath; - private NodeId nodeId = new NodeId("openflow-junit:1"); + private final NodeId nodeId = new NodeId("openflow-junit:1"); @Before public void setUp() { final NodeKey nodeKey = new NodeKey(nodeId); - rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor); - rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler); + rpcManager = new RpcManagerImpl(new OpenflowProviderConfigBuilder() + .setRpcRequestsQuota(new NonZeroUint16Type(QUOTA_VALUE)) + .setIsStatisticsRpcEnabled(false) + .build(), + rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService); - GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder() + FeaturesReply features = new GetFeaturesOutputBuilder() .setVersion(OFConstants.OFP_VERSION_1_3) .build(); - FeaturesReply features = featuresOutput; - - Mockito.when(connectionContext.getFeatures()).thenReturn(features); - Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); - Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); - Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath); - Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput); - rpcManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler); - Mockito.when(connectionContext.getFeatures()).thenReturn(features); - Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); - Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); - Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath); + Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath); + Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy); - Mockito.when(deviceState.getNodeId()).thenReturn(nodeKey.getId()); - Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation( - Matchers.>any(), Matchers.any(RpcService.class))) - .thenReturn(routedRpcRegistration); - Mockito.when(conductor.getDeviceContext(Mockito.any())).thenReturn(deviceContext); - Mockito.when(contexts.remove(nodeId)).thenReturn(removedContexts); - } - - @Test - public void onDeviceContextLevelUp() throws Exception { - rpcManager.onDeviceContextLevelUp(nodeId); - verify(conductor).getDeviceContext(Mockito.any()); - } - - @Test - public void onDeviceContextLevelUpTwice() throws Exception { - rpcManager.onDeviceContextLevelUp(nodeId); - expectedException.expect(VerifyException.class); - rpcManager.onDeviceContextLevelUp(nodeId); - } - - @Test - public void testOnDeviceContextLevelUpMaster() throws Exception { - rpcManager.onDeviceContextLevelUp(nodeId); - verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId); - } - - @Test - public void testOnDeviceContextLevelUpSlave() throws Exception { - rpcManager.onDeviceContextLevelUp(nodeId); - verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId); } @Test - public void testOnDeviceContextLevelUpOther() throws Exception { - rpcManager.onDeviceContextLevelUp(nodeId); - verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId); - } - - @Test - public void testOnDeviceContextLevelDown() throws Exception { - rpcManager.onDeviceContextLevelDown(deviceContext); - verify(deviceTerminationPhaseHandler).onDeviceContextLevelDown(deviceContext); - } - - /** - * On non null context close and onDeviceContextLevelDown should be called - */ - @Test - public void onDeviceContextLevelDown1() { - rpcManager.addRecordToContexts(nodeId,removedContexts); - rpcManager.onDeviceContextLevelDown(deviceContext); - verify(removedContexts,times(1)).close(); - verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceContext); - } - - - /** - * On null context only onDeviceContextLevelDown should be called - */ - @Test - public void onDeviceContextLevelDown2() { - rpcManager.onDeviceContextLevelDown(deviceContext); - verify(removedContexts,never()).close(); - verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceContext); - + public void createContext() throws Exception { + final RpcContext context = rpcManager.createContext(deviceContext); + assertEquals(deviceInfo, context.getDeviceInfo()); } @Test public void close() { - rpcManager.addRecordToContexts(nodeId,removedContexts); + rpcManager.addRecordToContexts(deviceInfo,removedContexts); rpcManager.close(); verify(removedContexts,atLeastOnce()).close(); }