aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy/org
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2024-11-06 22:20:11 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2024-11-17 17:09:51 +0000
commit5baf570979a06ec52e40dfaf613bb74665a8d9ff (patch)
treef3626a781fa367764de2607b2eaf5ea54c557617 /cps-service/src/test/groovy/org
parent37962e3faca4f2306546c4f70d480b0c323d2c68 (diff)
XML content support for only cps Query v2
Here to bring Support for XML Response Entity in query data nodes - Add ContentTypeInheadr in cpsQueryV2.yml to support application/xml - Add contentTypeInHeader parameter to accept xml in QueryRestController.java - Implement logic to convert data to xml - written testcase for above changes made Issue-ID: CPS-2359 Change-Id: Ieb7eeb66ccbb03703626132c6d5c2eade0e7cb4b Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-service/src/test/groovy/org')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy34
1 files changed, 17 insertions, 17 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy
index 3b21145293..9a932c9279 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy
@@ -32,7 +32,7 @@ import static org.onap.cps.utils.XmlFileUtils.convertDataMapsToXml
class XmlFileUtilsSpec extends Specification {
- def 'Parse a valid xml content #scenario'(){
+ def 'Parse a valid xml content #scenario'() {
given: 'YANG model schema context'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
@@ -41,13 +41,13 @@ class XmlFileUtilsSpec extends Specification {
then: 'the result xml is wrapped by root node defined in YANG schema'
assert parsedXmlContent == expectedOutput
where:
- scenario | xmlData || expectedOutput
- 'without root data node' | '<?xml version="1.0" encoding="UTF-8"?><class> </class>' || '<?xml version="1.0" encoding="UTF-8"?><stores xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><class> </class></stores>'
- 'with root data node' | '<?xml version="1.0" encoding="UTF-8"?><stores><class> </class></stores>' || '<?xml version="1.0" encoding="UTF-8"?><stores><class> </class></stores>'
- 'no xml header' | '<stores><class> </class></stores>' || '<stores><class> </class></stores>'
+ scenario | xmlData || expectedOutput
+ 'without root data node' | '<?xml version="1.0" encoding="UTF-8"?><class> </class>' || '<?xml version="1.0" encoding="UTF-8"?><stores xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><class> </class></stores>'
+ 'with root data node' | '<?xml version="1.0" encoding="UTF-8"?><stores><class> </class></stores>' || '<?xml version="1.0" encoding="UTF-8"?><stores><class> </class></stores>'
+ 'no xml header' | '<stores><class> </class></stores>' || '<stores><class> </class></stores>'
}
- def 'Parse a invalid xml content'(){
+ def 'Parse a invalid xml content'() {
given: 'YANG model schema context'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
@@ -84,9 +84,6 @@ class XmlFileUtilsSpec extends Specification {
'nested XML branch' | [['test-tree': [branch: [name: 'Left', nest: [name: 'Small', birds: 'Sparrow']]]]] || '<test-tree><branch><name>Left</name><nest><name>Small</name><birds>Sparrow</birds></nest></branch></test-tree>'
'list of branch within a test tree' | [['test-tree': [branch: [[name: 'Left', nest: [name: 'Small', birds: 'Sparrow']], [name: 'Right', nest: [name: 'Big', birds: 'Owl']]]]]] || '<test-tree><branch><name>Left</name><nest><name>Small</name><birds>Sparrow</birds></nest></branch><branch><name>Right</name><nest><name>Big</name><birds>Owl</birds></nest></branch></test-tree>'
'list of birds under a nest' | [['nest': ['name': 'Small', 'birds': ['Sparrow']]]] || '<nest><name>Small</name><birds>Sparrow</birds></nest>'
- 'XML Content map with null key/value' | [['test-tree': [branch: [name: 'Left', nest: []]]]] || '<test-tree><branch><name>Left</name><nest/></branch></test-tree>'
- 'XML Content list is empty' | [['nest': ['name': 'Small', 'birds': []]]] || '<nest><name>Small</name><birds/></nest>'
- 'XML with mixed content in list' | [['branch': ['name': 'Left', 'nest': ['name': 'Small', 'birds': ['', 'Sparrow']]]]] || '<branch><name>Left</name><nest><name>Small</name><birds/><birds>Sparrow</birds></nest></branch>'
}
def 'Convert data maps to XML with null or empty maps and lists'() {
@@ -95,11 +92,14 @@ class XmlFileUtilsSpec extends Specification {
then: 'the result contains the expected XML or handles nulls correctly'
assert result == expectedXmlOutput
where:
- scenario | dataMaps || expectedXmlOutput
- 'null entry in map' | [['branch': []]] || '<branch/>'
- 'list with null object' | [['branch': [name: 'Left', nest: [name: 'Small', birds: []]]]] || '<branch><name>Left</name><nest><name>Small</name><birds/></nest></branch>'
- 'list containing null list' | [['test-tree': [branch: '']]] || '<test-tree><branch/></test-tree>'
- 'nested map with null values' | [['test-tree': [branch: [name: 'Left', nest: '']]]] || '<test-tree><branch><name>Left</name><nest/></branch></test-tree>'
+ scenario | dataMaps || expectedXmlOutput
+ 'null entry in map' | [['branch': []]] || '<branch/>'
+ 'XML Content list is empty' | [['nest': ['name': 'Small', 'birds': [null]]]] || '<nest><name>Small</name><birds/></nest>'
+ 'XML with mixed content in list' | [['branch': ['name': 'Left', 'nest': ['name': 'Small', 'birds': [null, 'Sparrow']]]]] || '<branch><name>Left</name><nest><name>Small</name><birds/><birds>Sparrow</birds></nest></branch>'
+ 'list with null object' | [['branch': [name: 'Left', nest: [name: 'Small', birds: [null]]]]] || '<branch><name>Left</name><nest><name>Small</name><birds/></nest></branch>'
+ 'list containing null values' | [['branch': [null, null, null]]] || '<branch/><branch/><branch/>'
+ 'nested map with null values' | [['test-tree': [branch: [name: 'Left', nest: null]]]] || '<test-tree><branch><name>Left</name><nest/></branch></test-tree>'
+ 'mixed list with null values' | [['branch': ['name': 'Left', 'nest': ['name': 'Small', 'birds': [null, 'Sparrow', null]]]]] || '<branch><name>Left</name><nest><name>Small</name><birds/><birds>Sparrow</birds><birds/></nest></branch>'
}
def 'Converting data maps to xml with no data'() {
@@ -109,7 +109,7 @@ class XmlFileUtilsSpec extends Specification {
convertDataMapsToXml(dataMapWithNull)
then: 'a validation exception is thrown'
def exception = thrown(DataValidationException)
- and:'the cause is a null pointer exception'
+ and: 'the cause is a null pointer exception'
assert exception.cause instanceof NullPointerException
}
@@ -120,9 +120,9 @@ class XmlFileUtilsSpec extends Specification {
convertDataMapsToXml(dataMap)
then: 'a validation exception is thrown'
def exception = thrown(DataValidationException)
- and:'the cause is a document object model exception'
+ and: 'the cause is a document object model exception'
assert exception.cause instanceof DOMException
}
-}
+} \ No newline at end of file