X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fservices%2Fsal%2FSalFlowsBatchServiceImplTest.java;h=5825acd5a007d9803b9866cade4a94779ef297da;hb=777c94332871b8c34f56f7f2010de1536cb759ba;hp=bea9d1c9d8ceba148e3309442b402ebaef11db3b;hpb=4bc0c112b74a7ec57851aa662b7e9c4a67bb6879;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java index bea9d1c9d8..5825acd5a0 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java @@ -8,7 +8,7 @@ package org.opendaylight.openflowplugin.impl.services.sal; -import com.google.common.collect.Lists; +import java.util.Iterator; import java.util.List; import java.util.concurrent.Future; import org.junit.After; @@ -17,12 +17,12 @@ 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.InOrder; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; @@ -35,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Upda 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.flow.transaction.rev150304.FlowCapableTransactionService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInputBuilder; @@ -50,6 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.add import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.add.flows.batch.input.BatchAddFlowsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.OriginalBatchedFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.UpdatedBatchedFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.remove.flows.batch.input.BatchRemoveFlows; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.remove.flows.batch.input.BatchRemoveFlowsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.update.flows.batch.input.BatchUpdateFlows; @@ -60,9 +61,12 @@ 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.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.binding.util.BindingMap; +import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +80,8 @@ public class SalFlowsBatchServiceImplTest { public static final NodeId NODE_ID = new NodeId("ut-dummy-node"); public static final NodeKey NODE_KEY = new NodeKey(NODE_ID); - public static final NodeRef NODE_REF = new NodeRef(InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); + public static final NodeRef NODE_REF = + new NodeRef(InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); @Mock private SalFlowService salFlowService; @@ -94,21 +99,21 @@ public class SalFlowsBatchServiceImplTest { public static final String FLOW_ID_VALUE_2 = "ut-dummy-flow2"; @Before - public void setUp() throws Exception { + public void setUp() { salFlowsBatchService = new SalFlowsBatchServiceImpl(salFlowService, transactionService); - Mockito.when(transactionService.sendBarrier(Matchers.any())) - .thenReturn(RpcResultBuilder.success().buildFuture()); + Mockito.when(transactionService.sendBarrier(ArgumentMatchers.any())) + .thenReturn(RpcResultBuilder.success().buildFuture()); } @After - public void tearDown() throws Exception { + public void tearDown() { Mockito.verifyNoMoreInteractions(salFlowService, transactionService); } @Test public void testRemoveFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.removeFlow(Matchers.any())) + Mockito.when(salFlowService.removeFlow(ArgumentMatchers.any())) .thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()) .buildFuture()); @@ -120,7 +125,7 @@ public class SalFlowsBatchServiceImplTest { final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchRemoveFlows(Lists.newArrayList(batchFlow1, batchFlow2)) + .setBatchRemoveFlows(BindingMap.ordered(batchFlow1, batchFlow2)) .build(); final Future> resultFuture = salFlowsBatchService.removeFlowsBatch(input); @@ -129,7 +134,7 @@ public class SalFlowsBatchServiceImplTest { final RpcResult rpcResult = resultFuture.get(); Assert.assertTrue(rpcResult.isSuccessful()); final RemoveFlowsBatchOutput result = rpcResult.getResult(); - Assert.assertEquals(0, result.getBatchFailedFlowsOutput().size()); + Assert.assertEquals(0, result.nonnullBatchFailedFlowsOutput().size()); final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); @@ -139,14 +144,14 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } @Test public void testRemoveFlowsBatch_failed() throws Exception { - Mockito.when(salFlowService.removeFlow(Matchers.any())) + Mockito.when(salFlowService.removeFlow(ArgumentMatchers.any())) .thenReturn(RpcResultBuilder.failed() - .withError(RpcError.ErrorType.APPLICATION, "flow-remove-fail-1") + .withError(ErrorType.APPLICATION, "flow-remove-fail-1") .buildFuture()); final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_1, 42); @@ -155,7 +160,7 @@ public class SalFlowsBatchServiceImplTest { final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchRemoveFlows(Lists.newArrayList(batchFlow1, batchFlow2)) + .setBatchRemoveFlows(BindingMap.ordered(batchFlow1, batchFlow2)) .build(); final Future> resultFuture = salFlowsBatchService.removeFlowsBatch(input); @@ -164,9 +169,10 @@ public class SalFlowsBatchServiceImplTest { final RpcResult rpcResult = resultFuture.get(); Assert.assertFalse(rpcResult.isSuccessful()); final RemoveFlowsBatchOutput result = rpcResult.getResult(); - Assert.assertEquals(2, result.getBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, result.getBatchFailedFlowsOutput().get(0).getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, result.getBatchFailedFlowsOutput().get(1).getFlowId().getValue()); + Iterator iterator = result.nonnullBatchFailedFlowsOutput().values().iterator(); + Assert.assertEquals(2, result.nonnullBatchFailedFlowsOutput().size()); + Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); @@ -176,24 +182,24 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } private static BatchAddFlows createEmptyBatchAddFlow(final String flowIdValue, final int priority) { return new BatchAddFlowsBuilder() .setFlowId(new FlowId(flowIdValue)) - .setPriority(priority) + .setPriority(Uint16.valueOf(priority)) .setMatch(new MatchBuilder().build()) - .setTableId((short) 0) + .setTableId(Uint8.ZERO) .build(); } private static BatchRemoveFlows createEmptyBatchRemoveFlow(final String flowIdValue, final int priority) { return new BatchRemoveFlowsBuilder() .setFlowId(new FlowId(flowIdValue)) - .setPriority(priority) + .setPriority(Uint16.valueOf(priority)) .setMatch(new MatchBuilder().build()) - .setTableId((short) 0) + .setTableId(Uint8.ZERO) .build(); } @@ -209,13 +215,13 @@ public class SalFlowsBatchServiceImplTest { @Test public void testAddFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.addFlow(Matchers.any())) + Mockito.when(salFlowService.addFlow(ArgumentMatchers.any())) .thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture()); final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchAddFlows(Lists.newArrayList( + .setBatchAddFlows(BindingMap.ordered( createEmptyBatchAddFlow("ut-dummy-flow1", 42), createEmptyBatchAddFlow("ut-dummy-flow2", 43))) .build(); @@ -233,30 +239,33 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } @Test public void testAddFlowsBatch_failed() throws Exception { - Mockito.when(salFlowService.addFlow(Matchers.any())) - .thenReturn(RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError") + Mockito.when(salFlowService.addFlow(ArgumentMatchers.any())) + .thenReturn(RpcResultBuilder + .failed().withError(ErrorType.APPLICATION, "ut-groupAddError") .buildFuture()); final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchAddFlows(Lists.newArrayList( + .setBatchAddFlows(BindingMap.ordered( createEmptyBatchAddFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchAddFlow(FLOW_ID_VALUE_2, 43))) .build(); final Future> resultFuture = salFlowsBatchService.addFlowsBatch(input); + Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedFlowsOutput() + .values().iterator(); Assert.assertTrue(resultFuture.isDone()); Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(0).getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(1).getFlowId().getValue()); + Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedFlowsOutput().size()); + Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); Assert.assertEquals(2, resultFuture.get().getErrors().size()); final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); @@ -267,18 +276,18 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } @Test public void testUpdateFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.updateFlow(Matchers.any())) + Mockito.when(salFlowService.updateFlow(ArgumentMatchers.any())) .thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture()); final UpdateFlowsBatchInput input = new UpdateFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateFlows(Lists.newArrayList( + .setBatchUpdateFlows(BindingMap.ordered( createEmptyBatchUpdateFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchUpdateFlow(FLOW_ID_VALUE_2, 44))) .build(); @@ -298,31 +307,34 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); Assert.assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } @Test public void testUpdateFlowsBatch_failure() throws Exception { - Mockito.when(salFlowService.updateFlow(Matchers.any())) - .thenReturn(RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "ut-flowUpdateError") + Mockito.when(salFlowService.updateFlow(ArgumentMatchers.any())) + .thenReturn(RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "ut-flowUpdateError") .buildFuture()); final UpdateFlowsBatchInput input = new UpdateFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateFlows(Lists.newArrayList( + .setBatchUpdateFlows(BindingMap.ordered( createEmptyBatchUpdateFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchUpdateFlow(FLOW_ID_VALUE_2, 44))) .build(); final Future> resultFuture = salFlowsBatchService.updateFlowsBatch(input); + Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedFlowsOutput() + .values().iterator(); Assert.assertTrue(resultFuture.isDone()); Assert.assertFalse(resultFuture.get().isSuccessful()); Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(0).getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(1).getFlowId().getValue()); + Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedFlowsOutput().size()); + Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); Assert.assertEquals(2, resultFuture.get().getErrors().size()); final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); @@ -334,6 +346,6 @@ public class SalFlowsBatchServiceImplTest { Assert.assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); Assert.assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(Matchers.any()); + inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); } }