Switch to MD-SAL APIs
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / MdSalRegistrationUtilsTest.java
index cf0149cd79ffea230d337755f76834bdb7e5be30..bdf0a2a918d52e1132fbfacb068285c75da40dba 100644 (file)
 /*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
- *  * Copyright (c) 2015 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
- *
- *
+ * 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.openflowplugin.impl.util;
 
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+
 import java.math.BigInteger;
+import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 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.rpc.RpcContext;
+import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
+import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
 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.role.service.rev150727.OfpRole;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
+@RunWith(MockitoJUnitRunner.class)
 public class MdSalRegistrationUtilsTest {
 
     /**
      * Number of currently registrated services (can be changed)
-     * (RpcContext, DeviceContext)}
+     * (RpcContext, DeviceContext)}.
      */
-    private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 13;
+    private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 16;
+    private static final int NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION = 5;
 
-    @Test
-    public void registerServiceTest() {
+    @Mock
+    private RpcContext mockedRpcContext;
+    @Mock
+    private DeviceContext mockedDeviceContext;
+    @Mock
+    private ConnectionContext mockedConnectionContext;
+    @Mock
+    private DeviceState mockedDeviceState;
+    @Mock
+    private DeviceInfo mockedDeviceInfo;
+    @Mock
+    private FeaturesReply mockedFeatures;
+    @Mock
+    private BigInteger mockedDataPathId;
+    @Mock
+    private ExtensionConverterProvider extensionConverterProvider;
+    @Mock
+    private NotificationPublishService notificationPublishService;
 
-        final RpcContext mockedRpcContext = mock(RpcContext.class);
-        final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
-        final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
+    private ConvertorManager convertorManager;
 
-        final DeviceState mockedDeviceState = mock(DeviceState.class);
-        when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
-
-        final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
+    @Before
+    public void setUp() throws Exception {
+        convertorManager = ConvertorManagerFactory.createDefaultManager();
+        when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
+        when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
+        when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
+    }
 
-        final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
-        when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
+    @Test
+    public void registerServiceTest() {
+        MdSalRegistrationUtils.registerServices(mockedRpcContext,
+                                                mockedDeviceContext,
+                                                extensionConverterProvider,
+                                                convertorManager);
+        verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
+                any(), any(RpcService.class));
+    }
 
-        final BigInteger mockedDataPathId = mock(BigInteger.class);
-        when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
-        when(mockedFeaturesOutput.getDatapathId()).thenReturn(mockedDataPathId);
+    @Test
+    public void registerStatCompatibilityServices() throws Exception {
+        final OpendaylightFlowStatisticsService flowStatService = OpendaylightFlowStatisticsServiceImpl
+                .createWithOook(mockedRpcContext, mockedDeviceContext, convertorManager);
 
-        when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
-        MdSalRegistrationUtils.registerMasterServices(mockedRpcContext, mockedDeviceContext, OfpRole.BECOMEMASTER);
-        verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
-                Matchers.<Class<RpcService>> any(), any(RpcService.class));
+        when(mockedRpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class)).thenReturn(
+                flowStatService);
+        MdSalRegistrationUtils.registerStatCompatibilityServices(mockedRpcContext,
+                                                                 mockedDeviceContext,
+                                                                 notificationPublishService,
+                                                                 convertorManager);
+        verify(mockedRpcContext, times(NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION))
+                .registerRpcServiceImplementation(any(), any(RpcService.class));
     }
 
-}
+}
\ No newline at end of file