69d2ebd2573ec561cbec0a448d261ceec66ff6d0
[cps/ncmp-dmi-plugin.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 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
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.ncmp.dmi.datajobs.rest.controller
22
23 import org.onap.cps.ncmp.dmi.config.WebSecurityConfig
24 import org.springframework.beans.factory.annotation.Autowired
25 import org.springframework.beans.factory.annotation.Value
26 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
27 import org.springframework.context.annotation.Import
28 import org.springframework.http.HttpStatus
29 import org.springframework.security.test.context.support.WithMockUser
30 import org.springframework.test.web.servlet.MockMvc
31 import spock.lang.Specification
32
33 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
34 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
35
36 @Import(WebSecurityConfig)
37 @WebMvcTest(DmiDatajobsRestController.class)
38 @WithMockUser
39 class DmiDatajobsRestControllerSpec extends Specification{
40
41     @Autowired
42     private MockMvc mvc
43
44     @Value('${rest.api.dmi-base-path}/v1')
45     def basePathV1
46
47     def 'write request should return 501 HTTP Status' () {
48         given: 'URL to write a data job'
49             def getModuleUrl = "${basePathV1}/writeJob/001"
50         when: 'the request is posted'
51             def response = mvc.perform(
52                 post(getModuleUrl)
53                         .contentType('application/3gpp-json-patch+json')
54         ).andReturn().response
55         then: 'response value is Not Implemented'
56             response.status == HttpStatus.NOT_IMPLEMENTED.value()
57     }
58
59     def 'read request should return 501 HTTP Status' () {
60         given: 'URL to write a data job'
61             def getModuleUrl = "${basePathV1}/readJob/001"
62         when: 'the request is posted'
63             def response = mvc.perform(
64                 post(getModuleUrl)
65                         .contentType('application/3gpp-json-patch+json')
66         ).andReturn().response
67         then: 'response value is Not Implemented'
68         response.status == HttpStatus.NOT_IMPLEMENTED.value()
69     }
70
71     def 'get status request should return 501 HTTP Status' () {
72         given: 'URL to get the status of a data job'
73             def getStatus = "${basePathV1}/dataJob/some-identifier/dataProducerJob/some-producer-job-identifier/status?dataProducerId=some-data-producer-identifier"
74         when: 'the request is performed'
75             def response = mvc.perform(
76                     get(getStatus)
77                             .contentType('application/json')
78             ).andReturn().response
79         then: 'response value is Not Implemented'
80             response.status == HttpStatus.NOT_IMPLEMENTED.value()
81     }
82 }