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 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) {
100 return super.processGetDocument(request, httpResponse, headers, index, id);
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) {
113 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
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) {
127 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
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) {
140 return super.processDeleteDoc(request, httpResponse, headers, index, id);
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) {
152 return super.processInlineQuery(request, headers, index, queryText);
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) {
164 return super.processQueryWithGet(requestBody, request, headers, index);
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) {
176 return super.processQuery(requestBody, request, headers, index);
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) {
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;
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);
200 protected boolean validateRequest(HttpHeaders headers,
201 HttpServletRequest req,
202 ApiUtils.Action action,
203 String authPolicyFunctionName) throws Exception {
205 return authenticationShouldSucceed;