Merge "Add INFO.yaml for openflowplugin"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / batch / FlatBatchFlowAdaptersTest.java
index c604817978f44ee131bbcf25f78ff84448f2c87a..f22546aa4cc5f1597311abd396a4b613d1e89109 100644 (file)
@@ -5,10 +5,10 @@
  * 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.services.batch;
 
 import com.google.common.collect.Lists;
+import java.util.Iterator;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
@@ -28,8 +28,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.Add
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowOutputListGrouping;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.add.flows.batch.input.BatchAddFlows;
 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.batch.flow.output.list.grouping.BatchFailedFlowsOutputBuilder;
+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.update.flows.batch.input.BatchUpdateFlows;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -51,7 +54,7 @@ public class FlatBatchFlowAdaptersTest {
     private static final NodeRef NODE_REF = new NodeRef(NODE_II);
 
     @Test
-    public void testAdaptFlatBatchAddFlow() throws Exception {
+    public void testAdaptFlatBatchAddFlow() {
         final BatchPlanStep planStep = new BatchPlanStep(BatchStepType.FLOW_ADD);
         planStep.setBarrierAfter(true);
         planStep.getTaskBag().addAll(Lists.newArrayList(
@@ -59,65 +62,70 @@ public class FlatBatchFlowAdaptersTest {
                 createAddFlowBatch("2")));
 
         final AddFlowsBatchInput addFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, NODE_REF);
+        Iterator<BatchAddFlows> iterator = addFlowsBatchInput.nonnullBatchAddFlows().values().iterator();
 
         Assert.assertTrue(addFlowsBatchInput.isBarrierAfter());
         Assert.assertEquals(2, addFlowsBatchInput.getBatchAddFlows().size());
-        Assert.assertEquals("1", addFlowsBatchInput.getBatchAddFlows().get(0).getFlowId().getValue());
-        Assert.assertEquals("2", addFlowsBatchInput.getBatchAddFlows().get(1).getFlowId().getValue());
+        Assert.assertEquals("1", iterator.next().getFlowId().getValue());
+        Assert.assertEquals("2", iterator.next().getFlowId().getValue());
     }
 
-    private FlatBatchAddFlow createAddFlowBatch(final String flowIdValue) {
+    private static FlatBatchAddFlow createAddFlowBatch(final String flowIdValue) {
         return new FlatBatchAddFlowBuilder()
                 .setFlowId(new FlowId(flowIdValue))
                 .build();
     }
 
-    private FlatBatchRemoveFlow createRemoveFlowBatch(final String flowIdValue) {
+    private static FlatBatchRemoveFlow createRemoveFlowBatch(final String flowIdValue) {
         return new FlatBatchRemoveFlowBuilder()
                 .setFlowId(new FlowId(flowIdValue))
                 .build();
     }
 
-    private FlatBatchUpdateFlow createUpdateFlowBatch(final String flowIdValue) {
+    private static FlatBatchUpdateFlow createUpdateFlowBatch(final String flowIdValue) {
         return new FlatBatchUpdateFlowBuilder()
                 .setFlowId(new FlowId(flowIdValue))
                 .build();
     }
 
     @Test
-    public void testAdaptFlatBatchRemoveFlow() throws Exception {
+    public void testAdaptFlatBatchRemoveFlow() {
         final BatchPlanStep planStep = new BatchPlanStep(BatchStepType.FLOW_REMOVE);
         planStep.setBarrierAfter(true);
         planStep.getTaskBag().addAll(Lists.newArrayList(
                 createRemoveFlowBatch("1"),
                 createRemoveFlowBatch("2")));
 
-        final RemoveFlowsBatchInput removeFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, NODE_REF);
+        final RemoveFlowsBatchInput removeFlowsBatchInput =
+                FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, NODE_REF);
+        Iterator<BatchRemoveFlows> iterator = removeFlowsBatchInput.nonnullBatchRemoveFlows().values().iterator();
 
         Assert.assertTrue(removeFlowsBatchInput.isBarrierAfter());
         Assert.assertEquals(2, removeFlowsBatchInput.getBatchRemoveFlows().size());
-        Assert.assertEquals("1", removeFlowsBatchInput.getBatchRemoveFlows().get(0).getFlowId().getValue());
-        Assert.assertEquals("2", removeFlowsBatchInput.getBatchRemoveFlows().get(1).getFlowId().getValue());
+        Assert.assertEquals("1", iterator.next().getFlowId().getValue());
+        Assert.assertEquals("2", iterator.next().getFlowId().getValue());
     }
 
     @Test
-    public void testAdaptFlatBatchUpdateFlow() throws Exception {
+    public void testAdaptFlatBatchUpdateFlow() {
         final BatchPlanStep planStep = new BatchPlanStep(BatchStepType.FLOW_UPDATE);
         planStep.setBarrierAfter(true);
         planStep.getTaskBag().addAll(Lists.newArrayList(
                 createUpdateFlowBatch("1"),
                 createUpdateFlowBatch("2")));
 
-        final UpdateFlowsBatchInput updateFlowsBatchInput = FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, NODE_REF);
+        final UpdateFlowsBatchInput updateFlowsBatchInput =
+                FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, NODE_REF);
+        Iterator<BatchUpdateFlows> iterator = updateFlowsBatchInput.nonnullBatchUpdateFlows().values().iterator();
 
         Assert.assertTrue(updateFlowsBatchInput.isBarrierAfter());
         Assert.assertEquals(2, updateFlowsBatchInput.getBatchUpdateFlows().size());
-        Assert.assertEquals("1", updateFlowsBatchInput.getBatchUpdateFlows().get(0).getFlowId().getValue());
-        Assert.assertEquals("2", updateFlowsBatchInput.getBatchUpdateFlows().get(1).getFlowId().getValue());
+        Assert.assertEquals("1", iterator.next().getFlowId().getValue());
+        Assert.assertEquals("2", iterator.next().getFlowId().getValue());
     }
 
     @Test
-    public void testCreateBatchFlowChainingFunction_failures() throws Exception {
+    public void testCreateBatchFlowChainingFunction_failures() {
         final RpcResult<BatchFlowOutputListGrouping> input = RpcResultBuilder.<BatchFlowOutputListGrouping>failed()
                 .withError(RpcError.ErrorType.APPLICATION, "ut-flowError")
                 .withResult(new AddFlowsBatchOutputBuilder()
@@ -130,17 +138,22 @@ public class FlatBatchFlowAdaptersTest {
 
         final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchFlowAdapters
                 .convertBatchFlowResult(3).apply(input);
+        Iterator<BatchFailure> iterator = rpcResult.getResult().nonnullBatchFailure().values().iterator();
 
         Assert.assertFalse(rpcResult.isSuccessful());
         Assert.assertEquals(1, rpcResult.getErrors().size());
         Assert.assertEquals(2, rpcResult.getResult().getBatchFailure().size());
-        Assert.assertEquals(3, rpcResult.getResult().getBatchFailure().get(0).getBatchOrder().intValue());
-        Assert.assertEquals(4, rpcResult.getResult().getBatchFailure().get(1).getBatchOrder().intValue());
-        Assert.assertEquals("f2", ((FlatBatchFailureFlowIdCase) rpcResult.getResult().getBatchFailure().get(1).getBatchItemIdChoice()).getFlowId().getValue());
+        Assert.assertEquals(3, iterator.next()
+                .getBatchOrder().intValue());
+        BatchFailure secondBatchFailure = iterator.next();
+        Assert.assertEquals(4, secondBatchFailure.getBatchOrder().intValue());
+        Assert.assertEquals("f2",
+                ((FlatBatchFailureFlowIdCase) secondBatchFailure.getBatchItemIdChoice())
+                        .getFlowId().getValue());
     }
 
     @Test
-    public void testCreateBatchFlowChainingFunction_successes() throws Exception {
+    public void testCreateBatchFlowChainingFunction_successes() {
         final RpcResult<BatchFlowOutputListGrouping> input = RpcResultBuilder
                 .<BatchFlowOutputListGrouping>success(new AddFlowsBatchOutputBuilder().build())
                 .build();
@@ -150,17 +163,18 @@ public class FlatBatchFlowAdaptersTest {
 
         Assert.assertTrue(rpcResult.isSuccessful());
         Assert.assertEquals(0, rpcResult.getErrors().size());
-        Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
+        Assert.assertEquals(0, rpcResult.getResult().nonnullBatchFailure().size());
     }
 
-    private BatchFailedFlowsOutput createBatchFailedFlowsOutput(final Integer batchOrder, final String flowIdValue) {
+    private static BatchFailedFlowsOutput createBatchFailedFlowsOutput(final Integer batchOrder,
+            final String flowIdValue) {
         return new BatchFailedFlowsOutputBuilder()
                 .setFlowId(new FlowId(flowIdValue))
                 .setBatchOrder(batchOrder)
                 .build();
     }
 
-    private BatchFailure createChainFailure(final int batchOrder, final String flowIdValue) {
+    private static BatchFailure createChainFailure(final int batchOrder, final String flowIdValue) {
         return new BatchFailureBuilder()
                 .setBatchOrder(batchOrder)
                 .setBatchItemIdChoice(new FlatBatchFailureFlowIdCaseBuilder()