Add cosumes and produces type where necessary
[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 org.springframework.http.HttpHeaders;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.stereotype.Component;
26 import org.springframework.web.bind.annotation.*;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 @Component
32 @RestController
33 @RequestMapping("/test")
34 public class SearchServiceApiHarness extends SearchServiceApi {
35
36
37   public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
38
39   private boolean authenticationShouldSucceed = true;
40
41
42   /**
43    * Performs all one-time initialization required for the end point.
44    */
45   @Override
46   public void init() {
47
48     // Instantiate our Document Store DAO.
49     documentStore = new StubEsController();
50   }
51
52   @Override
53   @RequestMapping (value="/indexes/dynamic/{index}",
54           method = RequestMethod.PUT,
55           consumes = { "application/json"})
56   public ResponseEntity<String> processCreateDynamicIndex(@RequestBody String requestBody,
57                                             HttpServletRequest request,
58                                             @RequestHeader HttpHeaders headers,
59                                             @PathVariable("index") String index) {
60
61     return super.processCreateDynamicIndex(requestBody, request, headers, index);
62   }
63
64
65   @Override
66   @RequestMapping (value="/indexes/{index}",
67           method = RequestMethod.PUT,
68           consumes = { "application/json"})
69   public ResponseEntity<String> processCreateIndex(@RequestBody  String requestBody,
70                                      HttpServletRequest request,
71                                      @RequestHeader HttpHeaders headers,
72                                      @PathVariable("index") String index) {
73
74     return super.processCreateIndex(requestBody, request, headers, index);
75   }
76
77   @Override
78   @RequestMapping (value="/indexes/{index}",
79           method = RequestMethod.DELETE,
80           consumes = { "application/json"})
81   public ResponseEntity<String> processDeleteIndex(HttpServletRequest request,
82                                      @RequestHeader HttpHeaders headers,
83                                      @PathVariable("index") String index) {
84
85     return super.processDeleteIndex(request, headers, index);
86   }
87
88   @Override
89   @RequestMapping (value="/indexes/{index}/documents/{id}",
90           method = RequestMethod.GET)
91   public ResponseEntity<String> processGetDocument(
92           HttpServletRequest request,
93           HttpServletResponse httpResponse,
94           @RequestHeader HttpHeaders headers,
95           @PathVariable("index") String index,
96           @PathVariable("id") String id) {
97
98     return super.processGetDocument(request, httpResponse, headers, index, id);
99   }
100
101   @Override
102   @RequestMapping (value="/indexes/{index}/documents",
103                    method = RequestMethod.POST,
104                    consumes = { "application/json", "application/xml" })
105   public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody,
106                                                           HttpServletRequest request,
107                                                           HttpServletResponse httpResponse,
108                                                           @RequestHeader HttpHeaders headers,
109                                                           @PathVariable("index") String index) {
110
111     return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
112   }
113
114   @Override
115   @RequestMapping (value="/indexes/{index}/documents/{id}",
116           method = RequestMethod.PUT,
117           consumes = { "application/json", "application/xml" })
118   public ResponseEntity<String> processUpsertDoc(@RequestBody  String requestBody,
119                                     HttpServletRequest request,
120                                    HttpServletResponse httpResponse,
121                                    @RequestHeader  HttpHeaders headers,
122                                    @PathVariable("index") String index,
123                                    @PathVariable("id") String id) {
124
125     return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
126   }
127
128   @Override
129   @RequestMapping(value = "/indexes/{index}/documents/{id}",
130           method = RequestMethod.DELETE,
131           consumes = { "application/json"})
132   public ResponseEntity<String> processDeleteDoc(HttpServletRequest request,
133                                    HttpServletResponse httpResponse,
134                                    @RequestHeader HttpHeaders headers,
135                                    @PathVariable("index") String index,
136                                    @PathVariable("id") String id) {
137
138     return super.processDeleteDoc(request, httpResponse, headers, index, id);
139   }
140
141   @Override
142   @RequestMapping(value = "/indexes/{index}/query/{queryText}",
143           method = RequestMethod.GET)
144   public ResponseEntity<String> processInlineQuery(HttpServletRequest request,
145                                      @RequestHeader HttpHeaders headers,
146                                      @PathVariable("index") String index,
147                                      @PathVariable("queryText") String queryText) {
148
149     return super.processInlineQuery(request, headers, index, queryText);
150   }
151
152   @Override
153   @RequestMapping(value = "/indexes/{index}/query",
154           method = RequestMethod.GET,
155           consumes = { "application/json"})
156   public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody,
157                                                     HttpServletRequest request,
158                                       @RequestHeader HttpHeaders headers,
159                                       @PathVariable("index") String index) {
160
161     return super.processQueryWithGet(requestBody, request, headers, index);
162   }
163
164   @Override
165   @RequestMapping(value = "/indexes/{index}/query",
166           method = RequestMethod.POST,
167           consumes = { "application/json"})
168   public ResponseEntity<String> processQuery(@RequestBody String requestBody,
169                                              HttpServletRequest request,
170                                              @RequestHeader HttpHeaders headers,
171                                              @PathVariable("index") String index) {
172
173     return super.processQuery(requestBody, request, headers, index);
174   }
175
176   @Override
177   @RequestMapping(value = "/bulk",
178                   method = RequestMethod.POST,
179                   consumes = { "application/json"},
180                   produces = { "application/json"})
181   public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody,
182                                                    HttpServletRequest request,
183                                                    @RequestHeader HttpHeaders headers) {
184
185     // If the operations string contains a special keyword, set the
186     // harness to fail the authentication validation.
187     if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
188       authenticationShouldSucceed = false;
189     }
190
191     // Just pass the request up to the parent, since that is the code
192     // that we really want to test.
193     //return super.processPost(operations, request, headers, index);
194     return super.processBulkRequest(requestBody, request, headers);
195   }
196
197   @Override
198   protected boolean validateRequest(HttpHeaders headers,
199                                     HttpServletRequest req,
200                                     ApiUtils.Action action,
201                                     String authPolicyFunctionName) throws Exception {
202
203     return authenticationShouldSucceed;
204   }
205 }