[cps] Fix getResourceDataForPassthroughOperational endpoint
[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  *  Modifications Copyright (C) 2022 Bell Canada
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.ncmp.api.impl.client
23
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.HttpEntity
29 import org.springframework.http.HttpHeaders
30 import org.springframework.http.HttpMethod
31 import org.springframework.http.ResponseEntity
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.web.client.RestTemplate
34 import spock.lang.Specification
35
36 @SpringBootTest
37 @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient])
38 class DmiRestClientSpec extends Specification {
39
40     @SpringBean
41     RestTemplate mockRestTemplate = Mock(RestTemplate)
42
43     @Autowired
44     DmiRestClient objectUnderTest
45     def resourceUrl = 'some url'
46
47     def 'DMI POST operation with JSON.'() {
48         given: 'the rest template returns a valid response entity'
49             def mockResponseEntity = Mock(ResponseEntity)
50             mockRestTemplate.postForEntity(resourceUrl, _ as HttpEntity, Object.class) >> mockResponseEntity
51         when: 'POST operation is invoked'
52             def result = objectUnderTest.postOperationWithJsonData(resourceUrl, 'json-data')
53         then: 'the output of the method is equal to the output from the test template'
54             result == mockResponseEntity
55     }
56
57 }