Rename Path search-db to search-data-service.
[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           produces = { "application/json"},
92           consumes = { "application/json", "application/xml" })
93   public ResponseEntity<String> processGetDocument(
94           HttpServletRequest request,
95           HttpServletResponse httpResponse,
96           @RequestHeader HttpHeaders headers,
97           @PathVariable("index") String index,
98           @PathVariable("id") String id) {
99
100     return super.processGetDocument(request, httpResponse, headers, index, id);
101   }
102
103   @Override
104   @RequestMapping (value="/indexes/{index}/documents",
105                    method = RequestMethod.POST,
106                    consumes = { "application/json", "application/xml" })
107   public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody,
108                                                           HttpServletRequest request,
109                                                           HttpServletResponse httpResponse,
110                                                           @RequestHeader HttpHeaders headers,
111                                                           @PathVariable("index") String index) {
112
113     return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
114   }
115
116   @Override
117   @RequestMapping (value="/indexes/{index}/documents/{id}",
118           method = RequestMethod.PUT,
119           consumes = { "application/json", "application/xml" })
120   public ResponseEntity<String> processUpsertDoc(@RequestBody  String requestBody,
121                                     HttpServletRequest request,
122                                    HttpServletResponse httpResponse,
123                                    @RequestHeader  HttpHeaders headers,
124                                    @PathVariable("index") String index,
125                                    @PathVariable("id") String id) {
126
127     return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
128   }
129
130   @Override
131   @RequestMapping(value = "/indexes/{index}/documents/{id}",
132           method = RequestMethod.DELETE,
133           consumes = { "application/json"})
134   public ResponseEntity<String> processDeleteDoc(HttpServletRequest request,
135                                    HttpServletResponse httpResponse,
136                                    @RequestHeader HttpHeaders headers,
137                                    @PathVariable("index") String index,
138                                    @PathVariable("id") String id) {
139
140     return super.processDeleteDoc(request, httpResponse, headers, index, id);
141   }
142
143   @Override
144   @RequestMapping(value = "/indexes/{index}/query/{queryText}",
145           method = RequestMethod.GET,
146           consumes = { "application/json"})
147   public ResponseEntity<String> processInlineQuery(HttpServletRequest request,
148                                      @RequestHeader HttpHeaders headers,
149                                      @PathVariable("index") String index,
150                                      @PathVariable("queryText") String queryText) {
151
152     return super.processInlineQuery(request, headers, index, queryText);
153   }
154
155   @Override
156   @RequestMapping(value = "/indexes/{index}/query",
157           method = RequestMethod.GET,
158           consumes = { "application/json"})
159   public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody,
160                                                     HttpServletRequest request,
161                                       @RequestHeader HttpHeaders headers,
162                                       @PathVariable("index") String index) {
163
164     return super.processQueryWithGet(requestBody, request, headers, index);
165   }
166
167   @Override
168   @RequestMapping(value = "/indexes/{index}/query",
169           method = RequestMethod.POST,
170           consumes = { "application/json"})
171   public ResponseEntity<String> processQuery(@RequestBody String requestBody,
172                                              HttpServletRequest request,
173                                              @RequestHeader HttpHeaders headers,
174                                              @PathVariable("index") String index) {
175
176     return super.processQuery(requestBody, request, headers, index);
177   }
178
179   @Override
180   @RequestMapping(value = "/bulk",
181                   method = RequestMethod.POST,
182                   consumes = { "application/json", "application/xml" })
183   public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody,
184                                                    HttpServletRequest request,
185                                                    @RequestHeader HttpHeaders headers) {
186
187     // If the operations string contains a special keyword, set the
188     // harness to fail the authentication validation.
189     if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
190       authenticationShouldSucceed = false;
191     }
192
193     // Just pass the request up to the parent, since that is the code
194     // that we really want to test.
195     //return super.processPost(operations, request, headers, index);
196     return super.processBulkRequest(requestBody, request, headers);
197   }
198
199   @Override
200   protected boolean validateRequest(HttpHeaders headers,
201                                     HttpServletRequest req,
202                                     ApiUtils.Action action,
203                                     String authPolicyFunctionName) throws Exception {
204
205     return authenticationShouldSucceed;
206   }
207 }