From 9c6175cbf9ef0f2bfcd84e24974858c32d6ba587 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Mon, 8 Feb 2021 11:02:39 +0200 Subject: Data fragment update by xpath - parsing and validation Issue-ID: CPS-58 Change-Id: I6363c39d7046afc3b20dcd1224d6399b043c4386 Signed-off-by: Ruslan Kashapov --- .../src/test/java/org/onap/cps/TestUtils.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cps-service/src/test/java/org') 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 4ec4e4a00..bf59e1713 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 getFlattenMapByXpath(final DataNode dataNode) { + final ImmutableMap.Builder dataNodeMapBuilder = ImmutableMap.builder(); + buildFlattenMapByXpath(dataNode, dataNodeMapBuilder); + return dataNodeMapBuilder.build(); + } + + private static void buildFlattenMapByXpath(final DataNode dataNode, + final ImmutableMap.Builder dataNodeMapBuilder) { + dataNodeMapBuilder.put(dataNode.getXpath(), dataNode); + dataNode.getChildDataNodes() + .forEach(childDataNode -> buildFlattenMapByXpath(childDataNode, dataNodeMapBuilder)); + } } -- cgit 1.2.3-korg