Add method to build ResourceId by NodeKeys
Change-Id: If0ee51f0d50f4a2210c3b16e2d43962a873ee99b
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceId.java b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
index 4222f55..f0087df 100644
--- a/model/src/main/java/org/onosproject/yang/model/ResourceId.java
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceId.java
@@ -157,6 +157,19 @@
}
/**
+ * Appends a given list of NodeKey to current builder.
+ *
+ * @param nodeKeys list of NodeKey to be appended
+ * @return builder
+ */
+ public Builder append(List<NodeKey> nodeKeys) {
+ processCurKey();
+ curKeyBuilder = null;
+ nodeKeyList.addAll(nodeKeys);
+ return this;
+ }
+
+ /**
* Validates, build and add current key.
*/
protected void processCurKey() {
diff --git a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
index f9a3474..cdfdb1a 100644
--- a/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
+++ b/model/src/test/java/org/onosproject/yang/model/ResourceIdTest.java
@@ -22,6 +22,8 @@
public class ResourceIdTest {
+ private static final ResourceId ROOT =
+ ResourceId.builder().addBranchPointSchema("/", "").build();
ResourceId ridA;
ResourceId ridAcopy;
@@ -37,12 +39,23 @@
}
@Test
- public void random() {
+ public void equality() {
new EqualsTester()
.addEqualityGroup(ridA, ridAcopy)
+ .addEqualityGroup(ROOT)
.testEquals();
}
+ public void appendNodeKeys() throws CloneNotSupportedException {
+ ResourceId devices = ResourceId.builder()
+ .append(ridA.nodeKeys().subList(1, 2))
+ .build();
+
+ assertEquals(1, devices.nodeKeys().size());
+ assertEquals("devices", devices.nodeKeys().get(0).schemaId().name());
+ assertEquals("onos", devices.nodeKeys().get(0).schemaId().namespace());
+ }
+
@Test
public void resourceIdConstruction() {
String sampleResId = "/card=8/port=5,eth/stats";