2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 TechMahindra Ltd.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.api.impl
23 import org.onap.cps.spi.model.DataNode
24 import org.onap.cps.spi.model.DataNodeBuilder
25 import spock.lang.Shared
26 import spock.lang.Specification
28 class CpsDeltaServiceImplSpec extends Specification{
30 def objectUnderTest = new CpsDeltaServiceImpl()
33 def dataNodeWithLeafAndChildDataNode = [new DataNodeBuilder().withXpath('/parent').withLeaves(['parent-leaf': 'parent-payload'])
34 .withChildDataNodes([new DataNodeBuilder().withXpath("/parent/child").withLeaves('child-leaf': 'child-payload').build()]).build()]
36 def dataNodeWithChildDataNode = [new DataNodeBuilder().withXpath('/parent').withLeaves(['parent-leaf': 'parent-payload'])
37 .withChildDataNodes([new DataNodeBuilder().withXpath("/parent/child").build()]).build()]
39 def emptyDataNode = [new DataNodeBuilder().withXpath('/parent').build()]
41 def 'Get delta between data nodes for removed data where source data node has #scenario'() {
42 when: 'attempt to get delta between 2 data nodes'
43 def result = objectUnderTest.getDeltaReports(sourceDataNode as Collection<DataNode>, emptyDataNode)
44 then: 'the delta report contains "remove" action with right data'
45 assert result.first().action.equals("remove")
46 assert result.first().xpath == "/parent/child"
47 assert result.first().sourceData == expectedSourceData
48 where: 'following data was used'
49 scenario | sourceDataNode || expectedSourceData
50 'leaf data' | dataNodeWithLeafAndChildDataNode || ['child-leaf': 'child-payload']
51 'no leaf data' | dataNodeWithChildDataNode || null
54 def 'Get delta between data nodes with new data where target data node has #scenario'() {
55 when: 'attempt to get delta between 2 data nodes'
56 def result = objectUnderTest.getDeltaReports(emptyDataNode, targetDataNode)
57 then: 'the delta report contains "add" action with right data'
58 assert result.first().action.equals("add")
59 assert result.first().xpath == "/parent/child"
60 assert result.first().targetData == expectedTargetData
61 where: 'following data was used'
62 scenario | targetDataNode || expectedTargetData
63 'leaf data' | dataNodeWithLeafAndChildDataNode || ['child-leaf': 'child-payload']
64 'no leaf data' | dataNodeWithChildDataNode || null