Merge "Fetching data node by xpath - persistence layer"
[cps.git] / cps-nf-proxy-rest / src / test / groovy / org / onap / cps / nfproxy / rest / controller / NfProxyControllerSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Pantheon.tech
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  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.cps.nfproxy.rest.controller
21
22 import org.springframework.beans.factory.annotation.Autowired
23 import org.springframework.beans.factory.annotation.Value
24 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
25 import org.springframework.http.HttpStatus
26 import org.springframework.test.web.servlet.MockMvc
27 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
28 import spock.lang.Specification
29
30 @WebMvcTest
31 class NfProxyControllerSpec extends Specification {
32
33     @Autowired
34     MockMvc mvc
35
36     @Value('${rest.api.xnf-base-path}')
37     def basePath
38
39     def 'Hello world method invocation.'(){
40         when: 'hello-world request performed'
41             def response = mvc.perform(MockMvcRequestBuilders.get("$basePath/v1/hello-world")).andReturn().response
42         then: 'success response returned'
43             response.status == HttpStatus.OK.value()
44             response.getContentAsString().contains("Hello World!")
45     }
46
47     def 'Example error handling.'(){
48         when: 'hello-error request performed'
49             def response = mvc.perform(MockMvcRequestBuilders.get("$basePath/v1/hello-error")).andReturn().response
50         then: 'error response returned'
51             response.status == HttpStatus.INTERNAL_SERVER_ERROR.value()
52             response.getContentAsString().contains("Example error")
53     }
54 }