Fix sonar code smells 17/129017/2
authorkissand <andras.zoltan.kiss@est.tech>
Mon, 2 May 2022 08:42:30 +0000 (10:42 +0200)
committerkissand <andras.zoltan.kiss@est.tech>
Tue, 3 May 2022 08:50:36 +0000 (10:50 +0200)
* Increase code coverage in DataNodeBuilder

Issue-ID: CPS-475
Change-Id: I00a3b1c81911c1ccd3db810eec2f2989946809c5
Signed-off-by: kissand <andras.zoltan.kiss@est.tech>
cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy [moved from cps-service/src/test/groovy/org/onap/cps/model/DataNodeBuilderSpec.groovy with 90% similarity]

@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2021 Nordix Foundation.
+ *  Modifications Copyright (C) 2021-2022 Nordix Foundation.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.model
+package org.onap.cps.spi.model
 
 import org.onap.cps.TestUtils
 import org.onap.cps.spi.model.DataNodeBuilder
 import org.onap.cps.utils.YangUtils
 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
+import org.opendaylight.yangtools.yang.common.QName
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode
 import spock.lang.Specification
 
 class DataNodeBuilderSpec extends Specification {
@@ -157,6 +160,18 @@ class DataNodeBuilderSpec extends Specification {
             'multiple entries' | '{"branch": [{"name": "One"}, {"name": "Two"}]}' | 2            | ['/test-tree/branch[@name=\'One\']', '/test-tree/branch[@name=\'Two\']']
     }
 
+    def 'Converting NormalizedNode to a DataNode collection -- edge cases: #scenario.'() {
+        when: 'the normalized node is #node'
+            def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).buildCollection()
+        then: 'the resulting collection contains data nodes for expected list elements'
+            assert result.size() == expectedSize
+            assert result.containsAll(expectedNodes)
+        where: 'following parameters are used'
+            scenario                                | node            | normalizedNode       | expectedSize | expectedNodes
+            'NormalizedNode is null'                | 'null'          | null                 | 1            | [ new DataNode() ]
+            'NormalizedNode is an unsupported type' | 'not supported' | Mock(NormalizedNode) | 0            | [ ]
+    }
+
     def static assertLeavesMaps(actualLeavesMap, expectedLeavesMap) {
         expectedLeavesMap.each { key, value ->
             {