Fix the issue of ONOS-3423
Change-Id: I60c3105149f6ef46e2effb7de6d8f40152027ec7
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
index 0a4d385..d87682a 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
@@ -121,10 +121,10 @@
public List<Object> components() {
LinkedList<Object> components = new LinkedList<>();
- Optional<Discrete> parentPath = Optional.ofNullable(parent);
- while (parentPath.isPresent()) {
- components.addFirst(last);
- parentPath = parent.parent();
+ ResourcePath current = this;
+ while (current.parent().isPresent()) {
+ components.addFirst(current.last);
+ current = current.parent;
}
return components;
diff --git a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java b/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
index 8e44536..35dcf1e 100644
--- a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
+++ b/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
@@ -26,6 +26,7 @@
import java.util.Optional;
+import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -63,6 +64,13 @@
}
@Test
+ public void testComponents() {
+ ResourcePath port = ResourcePath.discrete(D1, P1);
+
+ assertThat(port.components(), contains(D1, P1));
+ }
+
+ @Test
public void testThereIsParent() {
ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1));