Refactor ConvertORTopoToFullTapiTopoTest step 6
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / ConvertORTopoToFullTapiTopoTest.java
index 55887fbc100f990f05b1b9780254ab66ec7fa07f..cee42205b75164af7ebbe63d044b2798e8990e0c 100644 (file)
@@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.fail;
 
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -296,7 +295,7 @@ public class ConvertORTopoToFullTapiTopoTest extends AbstractTest {
         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes =
             tapiFullFactory.getTapiNodes().values().stream().collect(Collectors.toList());
         checkOtsiNode(
-            tapiNodes.get(getNodeRank("ROADM-A1", tapiNodes)),
+            getNode("ROADM-A1", tapiNodes),
             new Uuid(UUID.nameUUIDFromBytes(
                     (roadmA.getNodeId().getValue() + "+PHOTONIC_MEDIA").getBytes(Charset.forName("UTF-8")))
                 .toString()),
@@ -327,9 +326,8 @@ public class ConvertORTopoToFullTapiTopoTest extends AbstractTest {
                     myInt, node.getName(), node.getUuid());
             }
         }
-        LOG.info("ROADM node found at rank {} from getrank", getNodeRank("ROADM-A1", tapiNodes));
         checkOtsiNode(
-            tapiNodes.get(getNodeRank("ROADM-A1", tapiNodes)),
+            getNode("ROADM-A1", tapiNodes),
             new Uuid(UUID.nameUUIDFromBytes((roadmA.getNodeId().getValue() + "+PHOTONIC_MEDIA")
                     .getBytes(Charset.forName("UTF-8")))
                 .toString()),
@@ -385,7 +383,7 @@ public class ConvertORTopoToFullTapiTopoTest extends AbstractTest {
             nodeMap.values().stream()
                 .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
                 .collect(Collectors.toList());
-        checkOtsiNode(tapiNodes.get(getNodeRank("ROADM-A1", tapiNodes)),
+        checkOtsiNode(getNode("ROADM-A1", tapiNodes),
              new Uuid(UUID.nameUUIDFromBytes((roadmA.getNodeId().getValue() + "+PHOTONIC_MEDIA")
                     .getBytes(Charset.forName("UTF-8")))
                 .toString()),
@@ -602,28 +600,28 @@ public class ConvertORTopoToFullTapiTopoTest extends AbstractTest {
                 // For Degree node
                 String mcnepUuidSeed = nodeId + "+PHOTONIC_MEDIA_OMS+DEG1-TTP-TXRX";
                 checkNepOtsiRdmNode(
-                    nepsOMS.get(getRank("DEG1-TTP", nepsOMS)),
+                    getOnep("DEG1-TTP", nepsOMS),
                     new Uuid(UUID.nameUUIDFromBytes(mcnepUuidSeed.getBytes(Charset.forName("UTF-8"))).toString()),
                     mcnepUuidSeed, pmOMSnep , false);
                 String otmcnepUuidSeed = nodeId + "+PHOTONIC_MEDIA_OTS+DEG1-TTP-TXRX";
                 checkNepOtsiRdmNode(
-                    nepsOTS.get(getRank("DEG1-TTP", nepsOTS)),
+                    getOnep("DEG1-TTP", nepsOTS),
                     new Uuid(UUID.nameUUIDFromBytes(otmcnepUuidSeed.getBytes(Charset.forName("UTF-8"))).toString()),
                     otmcnepUuidSeed, pmOTSnep, false);
                 // TODO the test below is redundant with the first one
                 checkNepOtsiRdmNode(
-                    nepsOMS.get(getRank("DEG1-TTP", nepsOMS)),
+                    getOnep("DEG1-TTP", nepsOMS),
                     new Uuid(UUID.nameUUIDFromBytes(mcnepUuidSeed.getBytes(Charset.forName("UTF-8"))).toString()),
                     mcnepUuidSeed, pmOMSnep, false);
                 // For srg node
                 String otscnepUuidSeed = nodeId + "+PHOTONIC_MEDIA_OTS+SRG1-PP1-TXRX";
                 checkNepOtsiRdmNode(
-                    nepsOTS.get(getRank("SRG1-PP1", nepsOTS)),
+                    getOnep("SRG1-PP1", nepsOTS),
                     new Uuid(UUID.nameUUIDFromBytes(otscnepUuidSeed.getBytes(Charset.forName("UTF-8"))).toString()),
                     otscnepUuidSeed, pmOTSnep, false);
                 String otscnep4UuidSeed = nodeId + "+PHOTONIC_MEDIA_OTS+SRG1-PP3-TXRX";
                 checkNepOtsiRdmNode(
-                    nepsOTS.get(getRank("SRG1-PP3", nepsOTS)),
+                    getOnep("SRG1-PP3", nepsOTS),
                     new Uuid(UUID.nameUUIDFromBytes(otscnep4UuidSeed.getBytes(Charset.forName("UTF-8"))).toString()),
                     otscnep4UuidSeed, pmOTSnep, false);
                 List<NodeRuleGroup> nrgList4 = node.nonnullNodeRuleGroup().values().stream()
@@ -1013,31 +1011,31 @@ public class ConvertORTopoToFullTapiTopoTest extends AbstractTest {
         return new NodeBuilder(initialNode).addAugmentation(tpdr1Bldr.setTerminationPoint(tps).build()).build();
     }
 
-    private int getRank(String searchedChar, List<OwnedNodeEdgePoint> onepList) {
-        return rawRank(
-            searchedChar, onepList.stream().map(entry -> entry.getName().values()).collect(Collectors.toList()));
-    }
-
-    private int getNodeRank(String searchedChar,
-        List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> nodeList) {
-        return rawRank(
-            searchedChar, nodeList.stream().map(entry -> entry.getName().values()).collect(Collectors.toList()));
+    private OwnedNodeEdgePoint getOnep(String searchedChar, List<OwnedNodeEdgePoint> onepList) {
+        for (OwnedNodeEdgePoint onep : onepList) {
+            for (Name name : onep.getName().values()) {
+                if (name.getValue().contains(searchedChar)) {
+                    return onep;
+                }
+            }
+        }
+        LOG.info("pattern '{}' not found in list of OwnedNodeEdgePoint", searchedChar);
+        return null;
     }
 
-    private int rawRank(String searchedChar, List<Collection<Name>> nameCL) {
-        int foundAtRank = 0;
-        int rank = 0;
-        for (var nameC: nameCL) {
-            for (Name name: nameC) {
+    private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node getNode(
+            String searchedChar,
+            List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> nodeList) {
+        org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node foundNode = null;
+        for (var node : nodeList) {
+            for (Name name : node.getName().values()) {
                 if (name.getValue().contains(searchedChar)) {
-                    foundAtRank = rank;
-                    //TODO should we really pursue once it is found ?
+                    return node;
                 }
             }
-            rank++;
         }
-        LOG.info("searched Char {} found at rank {}", searchedChar, foundAtRank);
-        return foundAtRank;
+        LOG.info("pattern '{}' not found in list of nodes", searchedChar);
+        return null;
     }
 
     private Integer nrgContainsClientAndNetwork(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid) {