summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/java/org/onap
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-08 11:02:39 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-09 18:43:07 +0200
commit9c6175cbf9ef0f2bfcd84e24974858c32d6ba587 (patch)
treef29b894849446207fb196215e1e081848d077243 /cps-service/src/test/java/org/onap
parent1f64d85f1cd85653a34b8656c67f4cc2565808e7 (diff)
Data fragment update by xpath - parsing and validation
Issue-ID: CPS-58 Change-Id: I6363c39d7046afc3b20dcd1224d6399b043c4386 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-service/src/test/java/org/onap')
-rw-r--r--cps-service/src/test/java/org/onap/cps/TestUtils.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/cps-service/src/test/java/org/onap/cps/TestUtils.java b/cps-service/src/test/java/org/onap/cps/TestUtils.java
index 4ec4e4a004..bf59e1713c 100644
--- a/cps-service/src/test/java/org/onap/cps/TestUtils.java
+++ b/cps-service/src/test/java/org/onap/cps/TestUtils.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;
+import org.onap.cps.spi.model.DataNode;
/**
* Common convenience methods for testing.
@@ -69,4 +71,24 @@ public class TestUtils {
}
return yangResourceNameToContentBuilder.build();
}
+
+ /**
+ * Represents given data node object as flatten map by xpath.
+ * For easy finding child node within hierarchy.
+ *
+ * @param dataNode data node representing a root of tree structure
+ * @return the map containing all the data nodes from given structure where key is xpath, value is datanode object
+ */
+ public static Map<String, DataNode> getFlattenMapByXpath(final DataNode dataNode) {
+ final ImmutableMap.Builder<String, DataNode> dataNodeMapBuilder = ImmutableMap.builder();
+ buildFlattenMapByXpath(dataNode, dataNodeMapBuilder);
+ return dataNodeMapBuilder.build();
+ }
+
+ private static void buildFlattenMapByXpath(final DataNode dataNode,
+ final ImmutableMap.Builder<String, DataNode> dataNodeMapBuilder) {
+ dataNodeMapBuilder.put(dataNode.getXpath(), dataNode);
+ dataNode.getChildDataNodes()
+ .forEach(childDataNode -> buildFlattenMapByXpath(childDataNode, dataNodeMapBuilder));
+ }
}