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