Get resource data from pass through running (Ncmp impl.)
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / operation / DmiOperationsSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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.operation
22
23 import org.onap.cps.ncmp.api.impl.client.DmiRestClient
24 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
25 import org.onap.cps.ncmp.api.impl.operation.DmiOperations
26 import org.spockframework.spring.SpringBean
27 import org.springframework.beans.factory.annotation.Autowired
28 import org.springframework.boot.test.context.SpringBootTest
29 import org.springframework.http.HttpHeaders
30 import org.springframework.test.context.ContextConfiguration
31 import spock.lang.Specification
32
33 @SpringBootTest
34 @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiOperations])
35 class DmiOperationsSpec extends Specification {
36
37     @SpringBean
38     DmiRestClient mockDmiRestClient = Mock()
39
40     @Autowired
41     DmiOperations objectUnderTest = new DmiOperations(mockDmiRestClient)
42
43     def 'call get resource data for pass-through:operational datastore from dmi.'() {
44         given: 'expected url'
45             def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
46                     '/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10'
47         when: 'get resource data is called to dmi'
48             objectUnderTest.getResouceDataOperationalFromDmi('testDmiBasePath',
49                     'testCmhandle',
50                     'testResourceId',
51                     'testFieldsQuery',
52                     10,
53                     'testAcceptJson',
54                     'testJsonbody')
55         then: 'the put operation is executed with the correct URL'
56             1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
57     }
58     def 'call get resource data for pass-through:running datastore from dmi.'() {
59         given: 'expected url'
60             def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
61                     '/ncmp-datastore:passthrough-running/testResourceId?fields=testFieldsQuery&depth=10'
62         when: 'get resource data is called to dmi'
63             objectUnderTest.getResouceDataPassThroughRunningFromDmi('testDmiBasePath',
64                     'testCmhandle',
65                     'testResourceId',
66                     'testFieldsQuery',
67                     10,
68                     'testAcceptJson',
69                     'testJsonbody')
70         then: 'the put operation is executed with the correct URL'
71             1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
72     }
73 }