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 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;
37 @RequestMapping("/test")
38 public class SearchServiceApiHarness extends SearchServiceApi {
41 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
43 private boolean authenticationShouldSucceed = true;
47 * Performs all one-time initialization required for the end point.
52 // Instantiate our Document Store DAO.
53 documentStore = new StubEsController();
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) {
65 return super.processCreateDynamicIndex(requestBody, request, headers, index);
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) {
78 return super.processCreateIndex(requestBody, request, headers, index);
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) {
89 return super.processDeleteIndex(request, headers, index);
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) {
102 return super.processGetDocument(request, httpResponse, headers, index, id);
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) {
115 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
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) {
129 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
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) {
142 return super.processDeleteDoc(request, httpResponse, headers, index, id);
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) {
153 return super.processInlineQuery(request, headers, index, queryText);
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) {
165 return super.processQueryWithGet(requestBody, request, headers, index);
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) {
177 return super.processQuery(requestBody, request, headers, index);
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) {
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;
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);
202 protected boolean validateRequest(HttpHeaders headers,
203 HttpServletRequest req,
204 ApiUtils.Action action,
205 String authPolicyFunctionName) throws Exception {
207 return authenticationShouldSucceed;