generating swagger-ui and controller interface using openapi.yml
[cps/cps-temporal.git] / src / test / groovy / org / onap / cps / temporal / controller / rest / QueryControllerSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2021 Bell Canada.
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.temporal.controller.rest
22
23 import org.springframework.beans.factory.annotation.Autowired
24 import org.springframework.beans.factory.annotation.Value
25 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
26 import org.springframework.http.HttpStatus
27 import org.springframework.http.MediaType
28 import org.springframework.test.web.servlet.MockMvc
29
30 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
31
32 import spock.lang.Specification
33
34 /**
35  * Specification for Query Controller.
36  */
37 @WebMvcTest(QueryController)
38 class QueryControllerSpec extends Specification {
39
40     @Autowired
41     MockMvc mvc
42
43     @Value('${rest.api.base-path}')
44     def basePath
45
46     def myDataspace = 'my-dataspace'
47     def myAnchor = 'my-anchor'
48     def mySchemaset = 'my-schemaset'
49
50     def 'Get anchors by name is not implemented.'(){
51         given: 'an endpoint'
52             def getAnchorsByNameEndpoint = "${basePath}/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/history"
53
54         when: 'get anchors by name endpoint is called'
55             def response = mvc.perform( get(getAnchorsByNameEndpoint, myDataspace, myAnchor)
56                     .contentType(MediaType.APPLICATION_JSON))
57                     .andReturn().response
58
59         then: 'received unsupported operation response'
60             response.getStatus() == HttpStatus.NOT_IMPLEMENTED.value()
61
62     }
63
64     def 'Get anchors by dataspace name is not implemented.'(){
65         given: 'an endpoint'
66             def getAnchorsByDataspaceEndpoint = "${basePath}/v1/dataspaces/{dataspace-name}/anchors/history"
67
68         when: 'get anchors by dataspace name endpoint is called'
69             def response = mvc.perform( get(getAnchorsByDataspaceEndpoint, myDataspace).queryParam('schema-set-name', mySchemaset)
70                     .contentType(MediaType.APPLICATION_JSON))
71                     .andReturn().response
72
73         then: 'received unsupported operation response'
74             response.getStatus() == HttpStatus.NOT_IMPLEMENTED.value()
75
76     }
77
78 }