Merge dev/fluorine work across to master
[unimgr.git] / impl / src / test / java / org / opendaylight / unimgr / mef / nrp / impl / decomposer / BasicDecomposerForDirectedTopologyTest.java
index b16342d1e6cf87815ff0230b2338937fb652045c..1c06e82472e04d076edace15fb74ca36c334fb63 100644 (file)
@@ -8,30 +8,31 @@
 
 package org.opendaylight.unimgr.mef.nrp.impl.decomposer;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.unimgr.mef.nrp.api.FailureResult;
 import org.opendaylight.unimgr.mef.nrp.api.Subrequrest;
 import org.opendaylight.unimgr.mef.nrp.impl.AbstractTestWithTopo;
 import org.opendaylight.unimgr.mef.nrp.impl.NrpInitializer;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.ForwardingDirection;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.OperationalState;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.PortDirection;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.ForwardingDirection;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.OperationalState;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.PortDirection;
 import org.opendaylight.yangtools.yang.common.OperationFailedException;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.*;
 
-/**
- * @author bartosz.michalik@amartus.com
- */
 public class BasicDecomposerForDirectedTopologyTest extends AbstractTestWithTopo {
 
     private BasicDecomposer decomposer;
@@ -48,100 +49,139 @@ public class BasicDecomposerForDirectedTopologyTest extends AbstractTestWithTopo
     public ExpectedException expected = ExpectedException.none();
 
     @Test
-    public void twoNodesTestDirection() throws FailureResult, OperationFailedException {
+    public void twoNodesTestDirection()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
-        n(tx, true, "n1", Stream.of(pI("n1:1"), pO("n1:2")));
-        n(tx, true, "n2", Stream.of(pO("n2:1"), pI("n2:2")));
-        n(tx, true, "n3", Stream.of(pI("n3:1")));
-        l(tx, "n1", "n1:1", "n2", "n2:1", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        tx.submit().checkedGet();
+        n(tx, true, "n1","d1", Stream.of(pI("n1:1"), pO("n1:2")));
+        n(tx, true, "n2", "d2", Stream.of(pO("n2:1"), pI("n2:2")));
+        n(tx, true, "n3", "d3", Stream.of(pI("n3:1")));
+        l(tx, "n1", "n1:1", "n2", "n2:1",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        tx.commit().get();
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:2", PortDirection.OUTPUT), ep("n2:2", PortDirection.INPUT)), null);
+        List<Subrequrest> decomposed = decomposer.decompose(
+                Arrays.asList(
+                        ep("n1:2", PortDirection.OUTPUT),
+                        ep("n2:2", PortDirection.INPUT)
+                ), null);
         assertNotNull(decomposed);
         assertEquals(2, decomposed.size());
     }
 
     @Test
-    public void threeNodesTestAll() throws FailureResult, OperationFailedException {
+    public void threeNodesTestAll()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         //having
         threeNodesTopo();
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:2", PortDirection.OUTPUT), ep("n3:3", PortDirection.INPUT)), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n1:2", PortDirection.OUTPUT),
+                ep("n3:3", PortDirection.INPUT)
+        ), null);
         assertNotNull(decomposed);
         assertEquals(3, decomposed.size());
+        assertEquals(2, decomposed.stream()
+                .flatMap(s -> s.getEndpoints().stream()).filter(e -> e.getAttrs() != null).count());
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void threeNodesTestIncompatible() throws FailureResult, OperationFailedException {
+    public void threeNodesTestIncompatible()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         //having
         threeNodesTopo();
         //when
-        decomposer.decompose(Arrays.asList(ep("n1:2", PortDirection.INPUT), ep("n3:3", PortDirection.OUTPUT)), null);
+        decomposer.decompose(Arrays.asList(ep("n1:2", PortDirection.INPUT),
+                ep("n3:3", PortDirection.OUTPUT)), null);
         fail();
     }
 
     @Test
-    public void fourNodesTestThreeSelected() throws FailureResult, OperationFailedException {
+    public void fourNodesTestThreeSelected()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         //having
         fourNodesTopo();
 
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n2:2"), ep("n3:2")), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n2:2"),
+                ep("n3:2")
+        ), null);
         assertNotNull(decomposed);
         assertEquals(3, decomposed.size());
+        assertEquals(2, decomposed.stream()
+                .flatMap(s -> s.getEndpoints().stream()).filter(e -> e.getAttrs() != null).count());
     }
 
 
     @Test
-    public void fourNodesTestNone() throws FailureResult, OperationFailedException {
+    public void fourNodesTestNone()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         //having
         fourNodesTopo();
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n2:1", PortDirection.INPUT), ep("n1:1")), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n2:1", PortDirection.INPUT),
+                ep("n1:1")
+        ), null);
         assertNull(decomposed);
 
     }
 
     @Test
-    public void fourTestPartialPath() throws FailureResult {
+    public void fourTestPartialPath()
+            throws FailureResult, InterruptedException, ExecutionException {
         //having
         fourNodesTopo();
 
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:1", PortDirection.OUTPUT), ep("n2:1"), ep("n4:1")), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n1:1", PortDirection.OUTPUT),
+                ep("n2:1"),
+                ep("n4:1")
+        ), null);
         assertNull(decomposed);
     }
 
     @Test
-    public void fourTestSingleSink() throws FailureResult {
+    public void fourTestSingleSink() throws FailureResult, InterruptedException, ExecutionException {
         //having
         fourNodesTopo();
 
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:1", PortDirection.INPUT), ep("n2:1", PortDirection.INPUT), ep("n4:1", PortDirection.OUTPUT)),
-                null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n1:1", PortDirection.INPUT),
+                ep("n2:1", PortDirection.INPUT),
+                ep("n4:1", PortDirection.OUTPUT)
+                ), null);
         assertNotNull(decomposed);
     }
 
-
-
     @Test
-    public void fiveNodesTestAll() throws FailureResult, OperationFailedException {
+    public void fiveNodesTestAll()
+            throws FailureResult, OperationFailedException, InterruptedException, ExecutionException {
         //having
         fiveNodesTopo();
 
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:2"), ep("n5:3")), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n1:2"),
+                ep("n5:3")
+        ), null);
         assertNotNull(decomposed);
         assertEquals(5, decomposed.size());
+        assertEquals(2, decomposed.stream()
+                .flatMap(s -> s.getEndpoints().stream()).filter(e -> e.getAttrs() != null).count());
     }
 
     @Test
-    public void fiveNodesTestDirected() throws FailureResult {
+    public void fiveNodesTestDirected() throws FailureResult, InterruptedException, ExecutionException {
         //having
         fiveNodesTopo();
         //when
-        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(ep("n1:2", PortDirection.OUTPUT), ep("n5:3", PortDirection.INPUT)), null);
+        List<Subrequrest> decomposed = decomposer.decompose(Arrays.asList(
+                ep("n1:2", PortDirection.OUTPUT),
+                ep("n5:3", PortDirection.INPUT)
+        ), null);
         assertNotNull(decomposed);
         assertEquals(3, decomposed.size());
     }
@@ -153,18 +193,19 @@ public class BasicDecomposerForDirectedTopologyTest extends AbstractTestWithTopo
     n3--(1)-->--(2)--n2
 
      */
-    private  void threeNodesTopo() {
+    private void threeNodesTopo() throws InterruptedException, ExecutionException {
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
-        n(tx, true, "n1", Stream.of(pI("n1:1"), pO("n1:2"), pI("n1:3")));
-        n(tx, true, "n2", Stream.of(pO("n2:1"), pI("n2:2")));
-        n(tx, true, "n3", Stream.of(pO("n3:1"), pO("n3:2"), pI("n3:3")));
-        l(tx, "n1", "n1:3", "n2", "n2:1", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n2", "n2:2", "n3", "n3:1", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        try {
-            tx.submit().checkedGet();
-        } catch (TransactionCommitFailedException e) {
-            e.printStackTrace();
-        }
+        n(tx, true, "n1", "d1",
+                Stream.of(pI("n1:1"), pO("n1:2"), pI("n1:3")));
+        n(tx, true, "n2", "d2",
+                Stream.of(pO("n2:1"), pI("n2:2")));
+        n(tx, true, "n3", "d3",
+                Stream.of(pO("n3:1"), pO("n3:2"), pI("n3:3")));
+        l(tx, "n1", "n1:3", "n2", "n2:1",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n2", "n2:2", "n3", "n3:1",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        tx.commit().get();
     }
 
     /*
@@ -176,22 +217,27 @@ public class BasicDecomposerForDirectedTopologyTest extends AbstractTestWithTopo
     n4--(5)-->--(5)--n3
 
      */
-    private  void fourNodesTopo() {
+    private void fourNodesTopo() throws InterruptedException, ExecutionException {
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
-        n(tx, true, "n1", Stream.of(pB("n1:1"), pB("n1:2"), pI("n1:3"), pO("n1:4"), pO("n1:5")));
-        n(tx, true, "n2", Stream.of(pB("n2:1"), pB("n2:2"), pO("n2:3"), pI("n2:4"), pI("n2:5")));
-        n(tx, true, "n3", Stream.of(pB("n3:1"), pB("n3:2"), pO("n3:3"), pO("n3:4"), pI("n3:5")));
-        n(tx, true, "n4", Stream.of(pB("n4:1"), pB("n4:2"), pI("n4:3"), pI("n4:4"), pO("n4:5")));
-        l(tx, "n1", "n1:5", "n2", "n2:5", OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
-        l(tx, "n1", "n1:4", "n4", "n4:4", OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
-        l(tx, "n2", "n2:3", "n4", "n4:3", OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
-        l(tx, "n3", "n3:4", "n2", "n2:4", OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
-        l(tx, "n4", "n4:5", "n3", "n3:5", OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
-        try {
-            tx.submit().checkedGet();
-        } catch (TransactionCommitFailedException e) {
-            e.printStackTrace();
-        }
+        n(tx, true, "n1", "d1",
+                Stream.of(pB("n1:1"), pB("n1:2"), pI("n1:3"), pO("n1:4"), pO("n1:5")));
+        n(tx, true, "n2", "d2",
+                Stream.of(pB("n2:1"), pB("n2:2"), pO("n2:3"), pI("n2:4"), pI("n2:5")));
+        n(tx, true, "n3", "d3",
+                Stream.of(pB("n3:1"), pB("n3:2"), pO("n3:3"), pO("n3:4"), pI("n3:5")));
+        n(tx, true, "n4", "d4",
+                Stream.of(pB("n4:1"), pB("n4:2"), pI("n4:3"), pI("n4:4"), pO("n4:5")));
+        l(tx, "n1", "n1:5", "n2", "n2:5",
+                OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
+        l(tx, "n1", "n1:4", "n4", "n4:4",
+                OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
+        l(tx, "n2", "n2:3", "n4", "n4:3",
+                OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
+        l(tx, "n3", "n3:4", "n2", "n2:4",
+                OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
+        l(tx, "n4", "n4:5", "n3", "n3:5",
+                OperationalState.ENABLED, ForwardingDirection.UNIDIRECTIONAL);
+        tx.commit().get();
     }
 
     /*
@@ -204,24 +250,31 @@ public class BasicDecomposerForDirectedTopologyTest extends AbstractTestWithTopo
     n5--(4)-->--(2)--n4
 
      */
-    private  void fiveNodesTopo() {
+    private  void fiveNodesTopo() throws InterruptedException, ExecutionException {
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
-        n(tx, true, "n1", Stream.of(pI("n1:1"), pB("n1:2"), pI("n1:3"), pO("n1:4")));
-        n(tx, true, "n2", Stream.of(pI("n2:1"), pB("n2:2"), pO("n2:3"), pI("n2:4")));
-        n(tx, true, "n3", Stream.of(pO("n3:1"), pB("n3:2"), pO("n3:3"), pI("n3:4")));
-        n(tx, true, "n4", Stream.of(pO("n4:1"), pI("n4:2"), pB("n4:3"), pB("n4:4")));
-        n(tx, true, "n5", Stream.of(pI("n5:1"), pB("n5:2"), pB("n5:3"), pO("n5:4")));
-        l(tx, "n2", "n2:3", "n3", "n3:4", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n3", "n3:1", "n1", "n1:1", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n3", "n3:3", "n5", "n5:1", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n4", "n4:1", "n1", "n1:3", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n1", "n1:4", "n2", "n2:4", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        l(tx, "n5", "n5:4", "n4", "n4:2", OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
-        try {
-            tx.submit().checkedGet();
-        } catch (TransactionCommitFailedException e) {
-            e.printStackTrace();
-        }
+        n(tx, true, "n1", "d1",
+                Stream.of(pI("n1:1"), pB("n1:2"), pI("n1:3"), pO("n1:4")));
+        n(tx, true, "n2", "d2",
+                Stream.of(pI("n2:1"), pB("n2:2"), pO("n2:3"), pI("n2:4")));
+        n(tx, true, "n3", "d3",
+                Stream.of(pO("n3:1"), pB("n3:2"), pO("n3:3"), pI("n3:4")));
+        n(tx, true, "n4", "d4",
+                Stream.of(pO("n4:1"), pI("n4:2"), pB("n4:3"), pB("n4:4")));
+        n(tx, true, "n5", "d5",
+                Stream.of(pI("n5:1"), pB("n5:2"), pB("n5:3"), pO("n5:4")));
+        l(tx, "n2", "n2:3", "n3", "n3:4",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n3", "n3:1", "n1", "n1:1",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n3", "n3:3", "n5", "n5:1",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n4", "n4:1", "n1", "n1:3",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n1", "n1:4", "n2", "n2:4",
+                OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        l(tx, "n5", "n5:4", "n4", "n4:2",
+                 OperationalState.ENABLED, ForwardingDirection.BIDIRECTIONAL);
+        tx.commit().get();
     }