Update MRI projects for Aluminium
[openflowplugin.git] / applications / bulk-o-matic / src / test / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / SalBulkFlowServiceImplTest.java
index 116df5f200d363cb7bf197cdff776dca866991d7..f2935470757f32bc2caf4b550ee2052085d3bab3 100644 (file)
@@ -1,36 +1,38 @@
-/**
+/*
  * Copyright (c) 2016, 2017 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.openflowplugin.applications.bulk.o.matic;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.Future;
+import java.util.Optional;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Captor;
-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.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsDsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsDsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.AddFlowsRpcInput;
@@ -39,10 +41,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowRpcAddMultipleInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowRpcAddTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowRpcAddTestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowRpcAddTestOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.FlowTestInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.ReadFlowTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.ReadFlowTestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.ReadFlowTestOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsDsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsDsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInput;
@@ -56,19 +60,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.list.grouping.BulkFlowItemBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Test for {@link SalBulkFlowServiceImpl}.
@@ -76,8 +77,6 @@ import org.slf4j.LoggerFactory;
 @RunWith(MockitoJUnitRunner.class)
 public class SalBulkFlowServiceImplTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(SalBulkFlowServiceImplTest.class);
-
     @Mock
     private DataBroker mockDataBroker;
     @Mock
@@ -85,7 +84,7 @@ public class SalBulkFlowServiceImplTest {
     @Mock
     private WriteTransaction writeTransaction;
     @Mock
-    private ReadOnlyTransaction readOnlyTransaction;
+    private ReadTransaction readOnlyTransaction;
     @Mock
     private Nodes mockNodes;
     @Mock
@@ -96,17 +95,18 @@ public class SalBulkFlowServiceImplTest {
     private SalBulkFlowServiceImpl salBulkFlowService;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         when(mockDataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
         when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
-        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Node>>any()))
-                .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNode)));
+
+        lenient().doReturn(FluentFutures.immediateFluentFuture(Optional.of(mockNode))).when(readOnlyTransaction)
+            .read(any(LogicalDatastoreType.class), any());
         salBulkFlowService = new SalBulkFlowServiceImpl(mockSalFlowService, mockDataBroker);
     }
 
     @Test
-    public void testAddRemoveFlowsDs() throws Exception {
-        Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+    public void testAddRemoveFlowsDs() {
+        doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
 
         final BulkFlowDsItemBuilder bulkFlowDsItemBuilder = new BulkFlowDsItemBuilder().setFlowId(new FlowId("1"))
                 .setTableId((short) 2);
@@ -124,9 +124,9 @@ public class SalBulkFlowServiceImplTest {
         final AddFlowsDsInput addFlowsDsInput = addFlowsDsInputBuilder.build();
         salBulkFlowService.addFlowsDs(addFlowsDsInput);
 
-        verify(writeTransaction).submit();
-        verify(writeTransaction).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any(),
-                flowArgumentCaptor.capture(), Mockito.anyBoolean());
+        verify(writeTransaction).commit();
+        verify(writeTransaction).mergeParentStructurePut(ArgumentMatchers.any(), ArgumentMatchers.any(),
+                flowArgumentCaptor.capture());
 
         Flow flow = flowArgumentCaptor.getValue();
         Assert.assertEquals("1", flow.getId().getValue());
@@ -138,16 +138,17 @@ public class SalBulkFlowServiceImplTest {
         final RemoveFlowsDsInput removeFlowsDsInput = removeFlowsDsInputBuilder.build();
 
         salBulkFlowService.removeFlowsDs(removeFlowsDsInput);
-        verify(writeTransaction).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any());
-        verify(writeTransaction, times(2)).submit();
+        verify(writeTransaction).delete(ArgumentMatchers.any(),
+                ArgumentMatchers.<InstanceIdentifier<Flow>>any());
+        verify(writeTransaction, times(2)).commit();
     }
 
     @Test
-    public void testAddRemoveFlowsRpc() throws Exception {
-        Mockito.when(mockSalFlowService.addFlow(Matchers.<AddFlowInput>any()))
+    public void testAddRemoveFlowsRpc() {
+        Mockito.when(mockSalFlowService.addFlow(ArgumentMatchers.any()))
                 .thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
 
-        Mockito.when(mockSalFlowService.removeFlow(Matchers.<RemoveFlowInput>any()))
+        Mockito.when(mockSalFlowService.removeFlow(ArgumentMatchers.any()))
                 .thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()).buildFuture());
 
         final BulkFlowItemBuilder bulkFlowItemBuilder = new BulkFlowItemBuilder();
@@ -164,7 +165,7 @@ public class SalBulkFlowServiceImplTest {
         final AddFlowsRpcInput addFlowsRpcInput = addFlowsRpcInputBuilder.build();
         salBulkFlowService.addFlowsRpc(addFlowsRpcInput);
 
-        verify(mockSalFlowService).addFlow(Matchers.<AddFlowInput>any());
+        verify(mockSalFlowService).addFlow(ArgumentMatchers.any());
 
         final RemoveFlowsRpcInputBuilder removeFlowsRpcInputBuilder = new RemoveFlowsRpcInputBuilder();
         removeFlowsRpcInputBuilder.setBulkFlowItem(bulkFlowItems);
@@ -172,7 +173,7 @@ public class SalBulkFlowServiceImplTest {
         final RemoveFlowsRpcInput removeFlowsRpcInput = removeFlowsRpcInputBuilder.build();
         salBulkFlowService.removeFlowsRpc(removeFlowsRpcInput);
 
-        verify(mockSalFlowService).removeFlow(Matchers.<RemoveFlowInput>any());
+        verify(mockSalFlowService).removeFlow(ArgumentMatchers.any());
     }
 
     @Test
@@ -181,22 +182,23 @@ public class SalBulkFlowServiceImplTest {
                 .setStartTableId(1L).setEndTableId(2L).setIsConfigDs(false).setFlowsPerDpn(1L).setVerbose(true);
 
         final ReadFlowTestInput readFlowTestInput = readFlowTestInputBuilder.build();
-        final Future<RpcResult<Void>> resultFuture = salBulkFlowService.readFlowTest(readFlowTestInput);
+        final ListenableFuture<RpcResult<ReadFlowTestOutput>> resultFuture
+                = salBulkFlowService.readFlowTest(readFlowTestInput);
 
         Assert.assertTrue(resultFuture.get().isSuccessful());
     }
 
     @Test
     public void testFlowRpcAddTest() throws Exception {
-        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class),
-                Mockito.<InstanceIdentifier<Nodes>>any()))
-                        .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
+        doReturn(FluentFutures.immediateFluentFuture(Optional.of(mockNodes))).when(readOnlyTransaction)
+            .read(any(LogicalDatastoreType.class), any());
 
         final FlowRpcAddTestInputBuilder flowRpcAddTestInputBuilder = new FlowRpcAddTestInputBuilder().setFlowCount(1L)
                 .setDpnId("1").setRpcBatchSize(1L);
 
         final FlowRpcAddTestInput flowRpcAddTestInput = flowRpcAddTestInputBuilder.build();
-        final Future<RpcResult<Void>> resultFuture = salBulkFlowService.flowRpcAddTest(flowRpcAddTestInput);
+        final ListenableFuture<RpcResult<FlowRpcAddTestOutput>> resultFuture
+                = salBulkFlowService.flowRpcAddTest(flowRpcAddTestInput);
 
         Assert.assertTrue(resultFuture.get().isSuccessful());
     }
@@ -239,9 +241,8 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testFlowRpcAddMultiple() throws Exception {
-        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class),
-                Mockito.<InstanceIdentifier<Nodes>>any()))
-                        .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
+        doReturn(FluentFutures.immediateFluentFuture(Optional.of(mockNodes))).when(readOnlyTransaction)
+            .read(any(LogicalDatastoreType.class), any());
 
         final FlowRpcAddMultipleInputBuilder flowRpcAddMultipleInputBuilder = new FlowRpcAddMultipleInputBuilder()
                 .setFlowCount(1L).setRpcBatchSize(1L);