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.operations
23 import org.onap.cps.ncmp.api.impl.client.DmiRestClient
24 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.boot.test.context.SpringBootTest
27 import org.springframework.http.ResponseEntity
28 import org.springframework.test.context.ContextConfiguration
30 import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_OPERATIONAL
31 import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING
32 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE
33 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE
34 import org.springframework.http.HttpStatus
37 @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiDataOperations])
38 class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
41 DmiDataOperations objectUnderTest
43 def 'call get resource data for #expectedDatastoreInUrl from DMI #scenario.'() {
44 given: 'a persistence cm handle for #cmHandleId'
45 mockPersistenceCmHandleRetrieval(additionalProperties)
46 and: 'a positive response from dmi service when it is called with the expected parameters'
47 def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
48 mockDmiRestClient.putOperationWithJsonData(
49 "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds/ncmp-datastore:${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}",
50 expectedJson, [Accept:['sample accept header']]) >> responseFromDmi
51 when: 'get resource data is invoked'
52 def result = objectUnderTest.getResourceDataFromDmi(cmHandleId,resourceIdentifier, options,'sample accept header', dataStore)
53 then: 'the result is the response from the dmi service'
54 assert result == responseFromDmi
55 where: 'the following parameters are used'
56 scenario | additionalProperties | dataStore | options || expectedJson | expectedDatastoreInUrl | expectedOptionsInUrl
57 'without properties' | [] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
58 'null properties' | null | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
59 'with properties' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | '&options=(a=1,b=2)'
60 'null options' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | null || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
61 'empty options' | [sampleAdditionalProperty] | PASSTHROUGH_OPERATIONAL | '' || '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}' | 'passthrough-operational' | ''
62 'datastore running' | [] | PASSTHROUGH_RUNNING | '(a=1,b=2)' || '{"operation":"read","cmHandleProperties":{}}' | 'passthrough-running' | '&options=(a=1,b=2)'
65 def 'Write data for pass-through:running datastore in DMI.'() {
66 given: 'a persistence cm handle for #cmHandleId'
67 mockPersistenceCmHandleRetrieval([sampleAdditionalProperty])
68 and: 'a positive response from dmi service when it is called with the expected parameters'
69 def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds" +
70 "/ncmp-datastore:passthrough-running?resourceIdentifier=${resourceIdentifier}"
71 def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}'
72 def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
73 mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, [:]) >> responseFromDmi
74 when: 'write resource method is invoked'
75 def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId,'parent/child', operation, 'requestData', 'some data type')
76 then: 'the result is the response from the dmi service'
77 assert result == responseFromDmi
78 where: 'the following operation is performed'
79 operation || expectedOperationInUrl