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}", method = RequestMethod.PUT, consumes = {"application/json"})
58 public ResponseEntity<String> processCreateDynamicIndex(@RequestBody String requestBody, HttpServletRequest request,
59 @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
61 return super.processCreateDynamicIndex(requestBody, request, headers, index);
66 @RequestMapping(value = "/indexes/{index}", method = RequestMethod.PUT, consumes = {"application/json"})
67 public ResponseEntity<String> processCreateIndex(@RequestBody String requestBody, HttpServletRequest request,
68 @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
70 return super.processCreateIndex(requestBody, request, headers, index);
74 @RequestMapping(value = "/indexes/{index}", method = RequestMethod.DELETE, consumes = {"application/json"})
75 public ResponseEntity<String> processDeleteIndex(HttpServletRequest request, @RequestHeader HttpHeaders headers,
76 @PathVariable("index") String index) {
78 return super.processDeleteIndex(request, headers, index);
82 @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.GET)
83 public ResponseEntity<String> processGetDocument(HttpServletRequest request, HttpServletResponse httpResponse,
84 @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) {
86 return super.processGetDocument(request, httpResponse, headers, index, id);
90 @RequestMapping(value = "/indexes/{index}/documents", method = RequestMethod.POST,
91 consumes = {"application/json", "application/xml"})
92 public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody, HttpServletRequest request,
93 HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
95 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
99 @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.PUT,
100 consumes = {"application/json", "application/xml"})
101 public ResponseEntity<String> processUpsertDoc(@RequestBody String requestBody, HttpServletRequest request,
102 HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index,
103 @PathVariable("id") String id) {
105 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
109 @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.DELETE,
110 consumes = {"application/json"})
111 public ResponseEntity<String> processDeleteDoc(HttpServletRequest request, HttpServletResponse httpResponse,
112 @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) {
114 return super.processDeleteDoc(request, httpResponse, headers, index, id);
118 @RequestMapping(value = "/indexes/{index}/query/{queryText}", method = RequestMethod.GET)
119 public ResponseEntity<String> processInlineQuery(HttpServletRequest request, @RequestHeader HttpHeaders headers,
120 @PathVariable("index") String index, @PathVariable("queryText") String queryText) {
122 return super.processInlineQuery(request, headers, index, queryText);
126 @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.GET, consumes = {"application/json"})
127 public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody, HttpServletRequest request,
128 @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
130 return super.processQueryWithGet(requestBody, request, headers, index);
134 @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.POST, consumes = {"application/json"})
135 public ResponseEntity<String> processQuery(@RequestBody String requestBody, HttpServletRequest request,
136 @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
138 return super.processQuery(requestBody, request, headers, index);
142 @RequestMapping(value = "/bulk", method = RequestMethod.POST, consumes = {"application/json"},
143 produces = {"application/json"})
144 public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody, HttpServletRequest request,
145 @RequestHeader HttpHeaders headers) {
147 // If the operations string contains a special keyword, set the
148 // harness to fail the authentication validation.
149 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
150 authenticationShouldSucceed = false;
153 // Just pass the request up to the parent, since that is the code
154 // that we really want to test.
155 // return super.processPost(operations, request, headers, index);
156 return super.processBulkRequest(requestBody, request, headers);
160 protected boolean validateRequest(HttpHeaders headers, HttpServletRequest req, ApiUtils.Action action,
161 String authPolicyFunctionName) {
162 return authenticationShouldSucceed;