ofs | hex dump | ascii |
---|
0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 05 59 00 00 02 49 08 06 00 00 00 b0 15 37 | .PNG........IHDR...Y...I.......7 |
0020 | 5f 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 e3 | _....pHYs.................tIME.. |
0040 | 01 0a 0f 21 35 df a9 9c a5 00 00 00 1d 69 54 58 74 43 6f 6d 6d 65 6e 74 00 00 00 00 00 43 72 65 | ...!5........iTXtComment.....Cre |
0060 | 61 74 65 64 20 77 69 74 68 20 47 49 4d 50 64 2e 65 07 00 00 20 00 49 44 41 54 78 da ec bd 69 70 | ated.with.GIMPd.e.....IDATx...ip |
0080 | 5e d9 7d e6 f7 3b e7 dc 7b df 0d fb 4e 00 04 48 02 04 09 ee 4b b3 c9 6e aa 5b 6d 75 4b a3 76 8f | ^.}..;..{...N..H....K..n.[muK.v. |
00a0 | 64 d9 92 2c 79 22 7b 34 4e 52 49 2a 33 c9 7c 48 26 1f 9c 4a 4d aa 32 e5 2f 49 d5 8c 6a 52 95 54 | d..,y"{4NRI*3.|H&..JM.2./I..jR.T |
00c0 | 52 25 67 34 b6 c7 b2 ad 76 4b bd b7 d4 3b 9b 6c 36 f7 7d 01 08 02 c4 be 6f ef 7a ef 39 27 1f ee | R%g4....vK...;.l6.}.....o.z.9'.. |
00e0 | 7d 5f 00 4d 76 bb d9 d6 94 54 9e fb 54 a1 00 bc 78 71 ef 59 fe e7 dc f7 3c e7 39 cf 5f 4c 4e 8e | }_.Mv....T..T...xq.Y....<.9._LN. |
0100 | 5a 62 3c 34 84 10 0f f3 ee e8 2b 46 8c 18 31 3e 1d a5 52 e9 be d7 ac b5 68 ad e3 c6 89 f1 f7 0e | Zb<4......+F..1>..R.....h....... |
0120 | ae eb 3e d4 eb 31 62 c4 88 11 23 46 8c 18 31 62 fc a7 09 1b 7d dd bf 56 8c f1 ab c5 ef ff fe 3f | ..>..1b...#F..1b....}..V.......? |
0140 | e1 07 3f f8 01 67 ce 9c c1 c9 e5 72 71 8b fc 92 f0 60 e2 35 26 58 63 c4 88 11 23 46 8c 07 c1 f7 | ..?..g.....rq....`.5&Xc...#F.... |
0160 | fd 87 7a 3d 46 8c 18 31 62 c4 88 11 23 46 8c ff 74 61 ee 7b 25 26 59 7f f5 10 42 20 84 40 29 85 | ..z=F..1b...#F..ta.{%&Y...B..@). |
0180 | f3 70 8a cc 18 7f 5b 20 3f a8 3d e3 98 8f 11 23 c6 7f 8c b9 25 46 8c 18 31 62 c4 88 11 23 46 8c | .p....[.?.=....#....%F..1b...#F. |
01a0 | 18 31 62 fc fd 47 b8 1c 8c d7 84 bf 8e 90 52 22 84 c0 71 1c 9c 98 f5 fe bc 01 fe e0 e0 be bf 3d | .1b..G........R"..q............= |
01c0 | 45 4c 8e c4 88 11 e3 3f c2 dc 12 23 c6 df df 78 8f 11 23 46 8c 18 31 62 c4 88 11 23 c6 86 15 e1 | EL.....?...#...x..#F..1b...#.... |
01e0 | 03 d7 84 f1 3a f1 d7 63 4d 23 a5 0c 95 ac 52 ca b8 45 3e 4f 78 5b f3 80 86 95 9f a2 64 8d 17 92 | ....:..cM#....R..E>Ox[......d... |
0200 | 31 62 c4 f8 2c 13 f4 27 cd 39 f1 c3 33 c6 df 3f 18 63 1e f8 ba 94 2a 6e 9c 18 31 62 c4 88 11 23 | 1b..,..'.9..3..?.c....*n..1b...# |
0220 | 46 8c 18 31 d6 ad 13 85 90 f1 3a f1 d7 b2 6f d6 d9 05 18 f3 eb dc 21 65 b6 c1 7e ee 8a 5a 6b 2b | F..1......:...o.......!e..~..Zk+ |
0240 | df ef bf f6 df a5 ee 0f 08 6e 40 58 a2 7b ae dd 47 ca fb 7d 59 cb e5 ba 6f c1 b9 ee ea c2 da f0 | .........n@X.{..G..}Y...o....... |
0260 | 77 21 01 13 5d 41 ac 95 da 5a 10 51 2d ac 40 45 d5 2a db 21 cb e8 3f 2c 76 dd 6b e5 57 d6 da 57 | w!..]A...Z.Q-.@E.*.!..?,v.k.W./*
* ============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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.cps.utils
import org.onap.cps.TestUtils
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import org.opendaylight.yangtools.yang.common.QName
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode
import spock.lang.Specification
class YangUtilsSpec extends Specification {
def 'Parsing a valid Json String.'() {
given: 'a yang model (file)'
def jsonData = org.onap.cps.TestUtils.getResourceFileContent('bookstore.json')
and: 'a model for that data'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
when: 'the json data is parsed'
NormalizedNode<?, ?> result = YangUtils.parseJsonData(jsonData, schemaContext)
then: 'the result is a normalized node of the correct type'
result.nodeType == QName.create('org:onap:ccsdk:sample', '2020-09-15', 'bookstore')
}
def 'Parsing invalid data: #description.'() {
given: 'a yang model (file)'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
when: 'invalid data is parsed'
YangUtils.parseJsonData(invalidJson, schemaContext)
then: 'an exception is thrown'
thrown(DataValidationException)
where: 'the following invalid json is provided'
invalidJson | description
'{incomplete json' | 'incomplete json'
'{"test:bookstore": {"address": "Parnell st." }}' | 'json with un-modelled data'
'{" }' | 'json with syntax exception'
}
def 'Parsing json data fragment by xpath for #scenario.'() {
given: 'schema context'
def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
when: 'json string is parsed'
def result = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
then: 'result represents a node of expected type'
result.nodeType == QName.create('org:onap:cps:test:test-tree', '2020-02-02', nodeName)
where:
scenario | jsonData | parentNodeXpath || nodeName
'list element as container' | '{ "branch": { "name": "B", "nest": { "name": "N", "birds": ["bird"] } } }' | '/test-tree' || 'branch'
'list element within list' | '{ "branch": [{ "name": "B", "nest": { "name": "N", "birds": ["bird"] } }] }' | '/test-tree' || 'branch'
'container element' | '{ "nest": { "name": "N", "birds": ["bird"] } }' | '/test-tree/branch[@name=\'Branch\']' || 'nest'
}
def 'Parsing json data fragment by xpath error scenario: #scenario.'() {
given: 'schema context'
def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
when: 'json string is parsed'
YangUtils.parseJsonData('{"nest": {"name" : "Nest", "birds": ["bird"]}}', schemaContext,
parentNodeXpath)
then: 'expected exception is thrown'
thrown(DataValidationException)
where:
scenario | parentNodeXpath
'xpath has no identifiers' | '/'
'xpath has no valid identifiers' | '/[@name=\'Name\']'
'invalid parent path' | '/test-bush'
'another invalid parent path' | '/test-tree/branch[@name=\'Branch\']/nest/name/last-name'
'fragment does not belong to parent' | '/test-tree/'
}
def 'Parsing json data with invalid json string: #description.'() {
given: 'schema context'
def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
when: 'malformed json string is parsed'
YangUtils.parseJsonData(invalidJson, schemaContext)
then: 'an exception is thrown'
thrown(DataValidationException)
where: 'the following malformed json is provided'
description | invalidJson
'malformed json string with unterminated array data' | '{bookstore={categories=[{books=[{authors=[Iain M. Banks]}]}]}}'
'incorrect json' | '{" }'
}
def 'Parsing json data with space.'() {
given: 'schema context'
def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
and: 'some json data with space in the array elements'
def jsonDataWithSpacesInArrayElement = TestUtils.getResourceFileContent('bookstore.json')
when: 'that json data is parsed'
YangUtils.parseJsonData(jsonDataWithSpacesInArrayElement, schemaContext)
then: 'no exception thrown'
noExceptionThrown()
}
}
|