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 // @Path("/indexes/dynamic/{index}")
54 // @Consumes({MediaType.APPLICATION_JSON})
56 @RequestMapping (value="/indexes/dynamic/{index}",
57 method = RequestMethod.PUT,
58 consumes = { "application/json"})
59 public ResponseEntity<String> processCreateDynamicIndex(@RequestBody String requestBody,
60 HttpServletRequest request,
61 @RequestHeader HttpHeaders headers,
62 @PathVariable("index") String index) {
64 return super.processCreateDynamicIndex(requestBody, request, headers, index);
69 @RequestMapping (value="/indexes/{index}",
70 method = RequestMethod.PUT,
71 consumes = { "application/json"})
72 public ResponseEntity<String> processCreateIndex(@RequestBody String requestBody,
73 HttpServletRequest request,
74 @RequestHeader HttpHeaders headers,
75 @PathVariable("index") String index) {
77 return super.processCreateIndex(requestBody, request, headers, index);
81 @RequestMapping (value="/indexes/{index}",
82 method = RequestMethod.DELETE,
83 consumes = { "application/json"})
84 public ResponseEntity<String> processDeleteIndex(@RequestBody String requestBody,
85 HttpServletRequest request,
86 @RequestHeader HttpHeaders headers,
87 @PathVariable("index") String index) {
89 return super.processDeleteIndex(requestBody, request, headers, index);
93 @RequestMapping (value="/indexes/{index}/documents/{id}",
94 method = RequestMethod.GET,
95 produces = { "application/json"},
96 consumes = { "application/json", "application/xml" })
97 public ResponseEntity<String> processGetDocument(
98 @RequestBody String requestBody,
99 HttpServletRequest request,
100 HttpServletResponse httpResponse,
101 @RequestHeader HttpHeaders headers,
102 @PathVariable("index") String index,
103 @PathVariable("id") String id) {
105 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
109 @RequestMapping (value="/indexes/{index}/documents",
110 method = RequestMethod.POST,
111 consumes = { "application/json", "application/xml" })
112 public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody,
113 HttpServletRequest request,
114 HttpServletResponse httpResponse,
115 @RequestHeader HttpHeaders headers,
116 @PathVariable("index") String index) {
118 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
122 @RequestMapping (value="/indexes/{index}/documents/{id}",
123 method = RequestMethod.PUT,
124 consumes = { "application/json", "application/xml" })
125 public ResponseEntity<String> processUpsertDoc(@RequestBody String requestBody,
126 HttpServletRequest request,
127 HttpServletResponse httpResponse,
128 @RequestHeader HttpHeaders headers,
129 @PathVariable("index") String index,
130 @PathVariable("id") String id) {
132 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
136 @RequestMapping(value = "/indexes/{index}/documents/{id}",
137 method = RequestMethod.DELETE,
138 consumes = { "application/json"})
139 public ResponseEntity<String> processDeleteDoc(@RequestBody String requestBody,
140 HttpServletRequest request,
141 HttpServletResponse httpResponse,
142 @RequestHeader HttpHeaders headers,
143 @PathVariable("index") String index,
144 @PathVariable("id") String id) {
146 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
150 @RequestMapping(value = "/indexes/{index}/query/{queryText}",
151 method = RequestMethod.GET,
152 consumes = { "application/json"})
153 public ResponseEntity<String> processInlineQuery(String requestBody,
154 HttpServletRequest request,
155 @RequestHeader HttpHeaders headers,
156 @PathVariable("index") String index,
157 @PathVariable("queryText") String queryText) {
159 return super.processInlineQuery(requestBody, request, headers, index, queryText);
163 @RequestMapping(value = "/indexes/{index}/query",
164 method = RequestMethod.GET,
165 consumes = { "application/json"})
166 public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody,
167 HttpServletRequest request,
168 @RequestHeader HttpHeaders headers,
169 @PathVariable("index") String index) {
171 return super.processQueryWithGet(requestBody, request, headers, index);
175 @RequestMapping(value = "/indexes/{index}/query",
176 method = RequestMethod.POST,
177 consumes = { "application/json"})
178 public ResponseEntity<String> processQuery(String requestBody,
179 HttpServletRequest request,
180 @RequestHeader HttpHeaders headers,
181 @PathVariable("index") String index) {
183 return super.processQuery(requestBody, request, headers, index);
187 @RequestMapping(value = "/bulk",
188 method = RequestMethod.POST,
189 consumes = { "application/json", "application/xml" })
190 public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody,
191 HttpServletRequest request,
192 @RequestHeader HttpHeaders headers) {
194 // If the operations string contains a special keyword, set the
195 // harness to fail the authentication validation.
196 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
197 authenticationShouldSucceed = false;
200 // Just pass the request up to the parent, since that is the code
201 // that we really want to test.
202 //return super.processPost(operations, request, headers, index);
203 return super.processBulkRequest(requestBody, request, headers);
207 protected boolean validateRequest(HttpHeaders headers,
208 HttpServletRequest req,
209 ApiUtils.Action action,
210 String authPolicyFunctionName) throws Exception {
212 return authenticationShouldSucceed;