2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.sa.rest;
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.*;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
33 @RequestMapping("/test")
34 public class SearchServiceApiHarness extends SearchServiceApi {
37 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
39 private boolean authenticationShouldSucceed = true;
43 * Performs all one-time initialization required for the end point.
48 // Instantiate our Document Store DAO.
49 documentStore = new StubEsController();
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) {
61 return super.processCreateDynamicIndex(requestBody, request, headers, index);
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) {
74 return super.processCreateIndex(requestBody, request, headers, index);
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) {
85 return super.processDeleteIndex(request, headers, index);
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) {
98 return super.processGetDocument(request, httpResponse, headers, index, id);
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) {
111 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
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) {
125 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
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) {
138 return super.processDeleteDoc(request, httpResponse, headers, index, id);
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) {
149 return super.processInlineQuery(request, headers, index, queryText);
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) {
161 return super.processQueryWithGet(requestBody, request, headers, index);
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) {
173 return super.processQuery(requestBody, request, headers, index);
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) {
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;
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);
198 protected boolean validateRequest(HttpHeaders headers,
199 HttpServletRequest req,
200 ApiUtils.Action action,
201 String authPolicyFunctionName) throws Exception {
203 return authenticationShouldSucceed;