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.client
23 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
24 import org.spockframework.spring.SpringBean
25 import org.springframework.beans.factory.annotation.Autowired
26 import org.springframework.boot.test.context.SpringBootTest
27 import org.springframework.http.HttpEntity
28 import org.springframework.http.HttpHeaders
29 import org.springframework.http.HttpMethod
30 import org.springframework.http.ResponseEntity
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.web.client.RestTemplate
33 import spock.lang.Specification
36 @ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient])
37 class DmiRestClientSpec extends Specification {
40 RestTemplate mockRestTemplate = Mock(RestTemplate)
43 DmiRestClient objectUnderTest
45 def 'DMI PUT operation.'() {
47 def getResourceDataUrl = 'http://some-uri/getResourceDataUrl'
48 and: 'the rest template returns a valid response entity'
49 def mockResponseEntity = Mock(ResponseEntity)
50 mockRestTemplate.exchange(getResourceDataUrl, HttpMethod.PUT, _ as HttpEntity, Object.class) >> mockResponseEntity
51 when: 'PUT operation is invoked'
52 def result = objectUnderTest.putOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
53 then: 'the output of the method is equal to the output from the test template'
54 result == mockResponseEntity
57 def 'DMI POST operation.'() {
59 def getResourceDataUrl = 'http://some-uri/createResourceDataUrl'
60 and: 'the rest template returns a valid response entity'
61 def mockResponseEntity = Mock(ResponseEntity)
62 mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, String.class) >> mockResponseEntity
63 when: 'POST operation is invoked'
64 def result = objectUnderTest.postOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
65 then: 'the output of the method is equal to the output from the test template'
66 result == mockResponseEntity