9c696dcc7a31ab661279cb09bb343bc83ab3d1da
[cps.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.impl.data
22
23 import org.onap.cps.api.CpsDataService
24 import org.onap.cps.ncmp.api.data.models.CmResourceAddress
25 import org.onap.cps.spi.model.DataNode
26 import reactor.core.publisher.Mono
27 import spock.lang.Specification
28
29 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
30 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
31
32 class NcmpCachedResourceRequestHandlerSpec extends Specification {
33
34     def cpsDataService = Mock(CpsDataService)
35     def networkCmProxyQueryService= Mock(NetworkCmProxyQueryService)
36
37     def objectUnderTest = new NcmpCachedResourceRequestHandler(cpsDataService, networkCmProxyQueryService)
38
39     def 'Execute a request with include descendants = #includeDescendants.'() {
40         when: 'executing a request'
41             objectUnderTest.executeRequest('ch-1', 'resource', includeDescendants)
42         then: 'it is delegated to the ncmp query service with the correct option'
43             1 * networkCmProxyQueryService.queryResourceDataOperational('ch-1','resource', expectedFetchDescendantsOption)
44         where: 'the following options are used'
45             includeDescendants || expectedFetchDescendantsOption
46             true               || INCLUDE_ALL_DESCENDANTS
47             false              || OMIT_DESCENDANTS
48     }
49
50     def 'Get resource data.'() {
51         given: 'the data service returns 2 nodes for the given resource address'
52             def cmResourceAddress = new CmResourceAddress('datastore','ch-1','resource')
53             def dataNode1 = new DataNode(xpath:'p1')
54             def dataNode2 = new DataNode(xpath:'p2')
55             cpsDataService.getDataNodes('datastore','ch-1','resource',OMIT_DESCENDANTS) >> [dataNode1, dataNode2]
56         when: 'getting the resource data'
57             def result = objectUnderTest.getResourceDataForCmHandle(cmResourceAddress, 'options', 'topic', 'request id', false, 'authorization')
58         then: 'the result is a "Mono" holding just the first data node'
59             assert result instanceof Mono
60             assert result.block() == dataNode1
61     }
62
63 }