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.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
31 class DmiRestClientSpec extends Specification {
33 def mockDmiProperties = Mock(NcmpConfiguration.DmiProperties)
34 def mockRestTemplate = Mock(RestTemplate)
35 def objectUnderTest = new DmiRestClient(mockRestTemplate, mockDmiProperties)
37 def 'DMI PUT operation.'() {
39 def getResourceDataUrl = 'http://some-uri/getResourceDataUrl'
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
51 def 'DMI POST operation.'() {
53 def getResourceDataUrl = 'http://some-uri/createResourceDataUrl'
55 setupTestConfigurationData()
56 and: 'the rest template returns a valid response entity'
57 def mockResponseEntity = Mock(ResponseEntity)
58 mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, Void.class) >> mockResponseEntity
59 when: 'POST operation is invoked'
60 def result = objectUnderTest.postOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
61 then: 'the output of the method is equal to the output from the test template'
62 result == mockResponseEntity
65 def setupTestConfigurationData() {
66 mockDmiProperties.authUsername >> 'some-username'
67 mockDmiProperties.authPassword >> 'some-password'