Organise imports to ONAP Java standards
[aai/search-data-service.git] / src / test / java / org / onap / aai / sa / rest / SearchServiceApiHarness.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sa.rest;
22
23  import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.springframework.http.HttpHeaders;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.stereotype.Component;
28 import org.springframework.web.bind.annotation.PathVariable;
29 import org.springframework.web.bind.annotation.RequestBody;
30 import org.springframework.web.bind.annotation.RequestHeader;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RestController;
34
35 @Component
36 @RestController
37 @RequestMapping("/test")
38 public class SearchServiceApiHarness extends SearchServiceApi {
39
40
41   public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
42
43   private boolean authenticationShouldSucceed = true;
44
45
46   /**
47    * Performs all one-time initialization required for the end point.
48    */
49   @Override
50   public void init() {
51
52     // Instantiate our Document Store DAO.
53     documentStore = new StubEsController();
54   }
55
56   @Override
57   @RequestMapping (value="/indexes/dynamic/{index}",
58           method = RequestMethod.PUT,
59           consumes = { "application/json"})
60   public ResponseEntity<String> processCreateDynamicIndex(@RequestBody String requestBody,
61                                             HttpServletRequest request,
62                                             @RequestHeader HttpHeaders headers,
63                                             @PathVariable("index") String index) {
64
65     return super.processCreateDynamicIndex(requestBody, request, headers, index);
66   }
67
68
69   @Override
70   @RequestMapping (value="/indexes/{index}",
71           method = RequestMethod.PUT,
72           consumes = { "application/json"})
73   public ResponseEntity<String> processCreateIndex(@RequestBody  String requestBody,
74                                      HttpServletRequest request,
75                                      @RequestHeader HttpHeaders headers,
76                                      @PathVariable("index") String index) {
77
78     return super.processCreateIndex(requestBody, request, headers, index);
79   }
80
81   @Override
82   @RequestMapping (value="/indexes/{index}",
83           method = RequestMethod.DELETE,
84           consumes = { "application/json"})
85   public ResponseEntity<String> processDeleteIndex(HttpServletRequest request,
86                                      @RequestHeader HttpHeaders headers,
87                                      @PathVariable("index") String index) {
88
89     return super.processDeleteIndex(request, headers, index);
90   }
91
92   @Override
93   @RequestMapping (value="/indexes/{index}/documents/{id}",
94           method = RequestMethod.GET)
95   public ResponseEntity<String> processGetDocument(
96           HttpServletRequest request,
97           HttpServletResponse httpResponse,
98           @RequestHeader HttpHeaders headers,
99           @PathVariable("index") String index,
100           @PathVariable("id") String id) {
101
102     return super.processGetDocument(request, httpResponse, headers, index, id);
103   }
104
105   @Override
106   @RequestMapping (value="/indexes/{index}/documents",
107                    method = RequestMethod.POST,
108                    consumes = { "application/json", "application/xml" })
109   public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody,
110                                                           HttpServletRequest request,
111                                                           HttpServletResponse httpResponse,
112                                                           @RequestHeader HttpHeaders headers,
113                                                           @PathVariable("index") String index) {
114
115     return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
116   }
117
118   @Override
119   @RequestMapping (value="/indexes/{index}/documents/{id}",
120           method = RequestMethod.PUT,
121           consumes = { "application/json", "application/xml" })
122   public ResponseEntity<String> processUpsertDoc(@RequestBody  String requestBody,
123                                     HttpServletRequest request,
124                                    HttpServletResponse httpResponse,
125                                    @RequestHeader  HttpHeaders headers,
126                                    @PathVariable("index") String index,
127                                    @PathVariable("id") String id) {
128
129     return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
130   }
131
132   @Override
133   @RequestMapping(value = "/indexes/{index}/documents/{id}",
134           method = RequestMethod.DELETE,
135           consumes = { "application/json"})
136   public ResponseEntity<String> processDeleteDoc(HttpServletRequest request,
137                                    HttpServletResponse httpResponse,
138                                    @RequestHeader HttpHeaders headers,
139                                    @PathVariable("index") String index,
140                                    @PathVariable("id") String id) {
141
142     return super.processDeleteDoc(request, httpResponse, headers, index, id);
143   }
144
145   @Override
146   @RequestMapping(value = "/indexes/{index}/query/{queryText}",
147           method = RequestMethod.GET)
148   public ResponseEntity<String> processInlineQuery(HttpServletRequest request,
149                                      @RequestHeader HttpHeaders headers,
150                                      @PathVariable("index") String index,
151                                      @PathVariable("queryText") String queryText) {
152
153     return super.processInlineQuery(request, headers, index, queryText);
154   }
155
156   @Override
157   @RequestMapping(value = "/indexes/{index}/query",
158           method = RequestMethod.GET,
159           consumes = { "application/json"})
160   public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody,
161                                                     HttpServletRequest request,
162                                       @RequestHeader HttpHeaders headers,
163                                       @PathVariable("index") String index) {
164
165     return super.processQueryWithGet(requestBody, request, headers, index);
166   }
167
168   @Override
169   @RequestMapping(value = "/indexes/{index}/query",
170           method = RequestMethod.POST,
171           consumes = { "application/json"})
172   public ResponseEntity<String> processQuery(@RequestBody String requestBody,
173                                              HttpServletRequest request,
174                                              @RequestHeader HttpHeaders headers,
175                                              @PathVariable("index") String index) {
176
177     return super.processQuery(requestBody, request, headers, index);
178   }
179
180   @Override
181   @RequestMapping(value = "/bulk",
182                   method = RequestMethod.POST,
183                   consumes = { "application/json"},
184                   produces = { "application/json"})
185   public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody,
186                                                    HttpServletRequest request,
187                                                    @RequestHeader HttpHeaders headers) {
188
189     // If the operations string contains a special keyword, set the
190     // harness to fail the authentication validation.
191     if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
192       authenticationShouldSucceed = false;
193     }
194
195     // Just pass the request up to the parent, since that is the code
196     // that we really want to test.
197     //return super.processPost(operations, request, headers, index);
198     return super.processBulkRequest(requestBody, request, headers);
199   }
200
201   @Override
202   protected boolean validateRequest(HttpHeaders headers,
203                                     HttpServletRequest req,
204                                     ApiUtils.Action action,
205                                     String authPolicyFunctionName) throws Exception {
206
207     return authenticationShouldSucceed;
208   }
209 }