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