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
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.api.impl.operation
23 import org.onap.cps.ncmp.api.impl.client.DmiRestClient
24 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
25 import org.spockframework.spring.SpringBean
26 import org.springframework.beans.factory.annotation.Autowired
27 import org.springframework.boot.test.context.SpringBootTest
28 import org.springframework.http.HttpHeaders
29 import org.springframework.test.context.ContextConfiguration
30 import spock.lang.Specification
33 @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiOperations])
34 class DmiOperationsSpec extends Specification {
37 DmiRestClient mockDmiRestClient = Mock()
40 DmiOperations objectUnderTest = new DmiOperations(mockDmiRestClient)
42 def 'call get resource data for pass-through:operational datastore from DMI.'() {
44 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
45 '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)'
46 when: 'get resource data is called to DMI'
47 objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
53 then: 'the put operation is executed with the correct URL'
54 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
56 def 'call get resource data for pass-through:running datastore from DMI.'() {
58 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
59 '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)'
60 when: 'get resource data is called to DMI'
61 objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath',
67 then: 'the put operation is executed with the correct URL'
68 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
70 def 'call get resource data for pass-through:operational datastore from DMI when options is null.'() {
72 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
73 '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child'
74 when: 'get resource data is called to DMI'
75 objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
81 then: 'the put operation is executed with the correct URL'
82 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
84 def 'call create resource data for pass-through:running datastore from DMI.'() {
86 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
87 '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child'
88 when: 'get resource data is called to DMI'
89 objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath',
93 then: 'the put operation is executed with the correct URL'
94 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
97 def 'Call get resource from dmi.'() {
99 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/modules'
100 when: 'get resource data is called to dmi'
101 objectUnderTest.getResourceFromDmi('testDmiBasePath',
104 then: 'the post operation is executed with the correct URL'
105 1 * mockDmiRestClient.postOperation(expectedUrl, _ as HttpHeaders)
108 def 'Call get resource from dmi with json data.'() {
109 given: 'expected url & json data'
110 def requestBody = 'some json'
111 def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmHandle/modules'
112 def expectedHttpHeaders = new HttpHeaders()
113 when: 'get resource data is called to dmi'
114 objectUnderTest.getResourceFromDmiWithJsonData('testDmiBasePath',
118 then: 'the post operation is executed with the correct URL and json data'
119 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, requestBody, expectedHttpHeaders)
122 def 'Update resource data for pass-through:running datastore from DMI.'() {
123 given: 'the expected url'
124 def cmHandle = 'some-cmhandle'
125 def resourceIdentifier = 'parent/child'
126 def expectedUrl = 'some-dmi-service-name/dmi/v1/ch/' + cmHandle + '/data/ds' +
127 '/ncmp-datastore:passthrough-running?resourceIdentifier=' + resourceIdentifier
128 when: 'replace resource data is called for DMI'
129 objectUnderTest.updateResourceDataPassThroughRunningFromDmi('some-dmi-service-name',
133 then: 'the post operation is executed with the correct URL'
134 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'some-json-body', _ as HttpHeaders)