Merge "Use constants for magic numbers in perf tests"
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / model / DataNodeBuilder.java
index 6fc36eb..b040af5 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Bell Canada. All rights reserved.
  *  Modifications Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2022 Nordix Foundation.
+ *  Modifications Copyright (C) 2022-2023 Nordix Foundation.
  *  Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,6 +54,7 @@ public class DataNodeBuilder {
     private String parentNodeXpath = "";
     private Map<String, Serializable> leaves = Collections.emptyMap();
     private Collection<DataNode> childDataNodes = Collections.emptySet();
+    private String dataspaceName;
     private String anchorName;
 
     /**
@@ -89,6 +90,17 @@ public class DataNodeBuilder {
         return this;
     }
 
+    /**
+     * To use dataspace name for creating {@link DataNode}.
+     *
+     * @param dataspaceName dataspace name for the data node
+     * @return DataNodeBuilder
+     */
+    public DataNodeBuilder withDataspace(final String dataspaceName) {
+        this.dataspaceName = dataspaceName;
+        return this;
+    }
+
     /**
      * To use anchor name for creating {@link DataNode}.
      *
@@ -165,15 +177,15 @@ public class DataNodeBuilder {
         dataNode.setModuleNamePrefix(moduleNamePrefix);
         dataNode.setLeaves(leaves);
         dataNode.setChildDataNodes(childDataNodes);
+        dataNode.setDataspace(dataspaceName);
         dataNode.setAnchorName(anchorName);
         return dataNode;
     }
 
     private DataNode buildFromContainerNode() {
         final Collection<DataNode> dataNodeCollection = buildCollectionFromContainerNode();
-        if (!dataNodeCollection.iterator().hasNext()) {
-            throw new DataValidationException(
-                "Unsupported xpath: ", "Unsupported xpath as it is referring to one element");
+        if (dataNodeCollection.isEmpty()) {
+            throw new DataValidationException("Unsupported Normalized Node", "No valid node found");
         }
         return dataNodeCollection.iterator().next();
     }
@@ -265,5 +277,4 @@ public class DataNodeBuilder {
         }
     }
 
-
 }