Merge "get resource data for operational passthrough"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / client / DmiRestClientSpec.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.client
22
23 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
24 import org.springframework.http.HttpEntity
25 import org.springframework.http.HttpHeaders
26 import org.springframework.http.ResponseEntity
27 import org.springframework.web.client.RestTemplate
28 import spock.lang.Specification
29 import  org.springframework.http.HttpMethod
30
31 class DmiRestClientSpec extends Specification {
32
33     def mockDmiProperties = Mock(NcmpConfiguration.DmiProperties)
34     def mockRestTemplate = Mock(RestTemplate)
35     def objectUnderTest = new DmiRestClient(mockRestTemplate, mockDmiProperties)
36
37     def 'DMI PUT operation.'() {
38         given: 'a get url'
39             def getResourceDataUrl = 'http://some-uri/getResourceDataUrl'
40         and: 'dmi properties'
41             setupTestConfigurationData()
42         and: 'the rest template returns a valid response entity'
43             def mockResponseEntity = Mock(ResponseEntity)
44             mockRestTemplate.exchange(getResourceDataUrl, HttpMethod.PUT, _ as HttpEntity, Object.class) >> mockResponseEntity
45         when: 'PUT operation is invoked'
46             def result = objectUnderTest.putOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
47         then: 'the output of the method is equal to the output from the test template'
48             result == mockResponseEntity
49     }
50
51     def setupTestConfigurationData() {
52         mockDmiProperties.authUsername >> 'some-username'
53         mockDmiProperties.authPassword >> 'some-password'
54     }
55 }