2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
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.ncmp.impl.data
23 import org.onap.cps.api.CpsDataService
24 import org.onap.cps.ncmp.api.data.models.CmResourceAddress
25 import org.onap.cps.ncmp.config.CpsApplicationContext
26 import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
27 import org.onap.cps.api.model.DataNode
28 import org.spockframework.spring.SpringBean
29 import org.springframework.boot.test.context.SpringBootTest
30 import org.springframework.context.ApplicationContext
31 import org.springframework.test.context.ContextConfiguration
32 import reactor.core.publisher.Mono
33 import spock.lang.Specification
35 import static org.onap.cps.api.parameters.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
36 import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS
39 @ContextConfiguration(classes = [CpsApplicationContext])
40 class NcmpCachedResourceRequestHandlerSpec extends Specification {
42 def cpsDataService = Mock(CpsDataService)
43 def networkCmProxyQueryService= Mock(NetworkCmProxyQueryService)
46 AlternateIdMatcher alternateIdMatcher = Mock()
49 ApplicationContext applicationContext = Mock()
51 def objectUnderTest = new NcmpCachedResourceRequestHandler(cpsDataService, networkCmProxyQueryService)
53 def 'Execute a request with include descendants = #includeDescendants.'() {
54 when: 'executing a request'
55 objectUnderTest.executeRequest('ch-1', 'resource', includeDescendants)
56 then: 'it is delegated to the ncmp query service with the correct option'
57 1 * networkCmProxyQueryService.queryResourceDataOperational('ch-1','resource', expectedFetchDescendantsOption)
58 where: 'the following options are used'
59 includeDescendants || expectedFetchDescendantsOption
60 true || INCLUDE_ALL_DESCENDANTS
61 false || OMIT_DESCENDANTS
64 def 'Get resource data.'() {
65 given: 'the data service returns 2 nodes for the given resource address'
66 def cmResourceAddress = new CmResourceAddress('datastore','ch-1','resource')
67 def dataNode1 = new DataNode(xpath:'p1')
68 def dataNode2 = new DataNode(xpath:'p2')
69 cpsDataService.getDataNodes('datastore','ch-1','resource',OMIT_DESCENDANTS) >> [dataNode1, dataNode2]
70 when: 'getting the resource data'
71 alternateIdMatcher.getCmHandleId('ch-1') >> 'ch-1'
72 def result = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, 'options', 'topic', 'request id', false, 'authorization')
73 then: 'the result is a "Mono" holding just the first data node'
74 assert result instanceof Mono
75 assert result.block() == dataNode1