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;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.HttpHeaders;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.onap.aai.sa.rest.ApiUtils;
32 import org.onap.aai.sa.rest.SearchServiceApi;
35 public class SearchServiceApiHarness extends SearchServiceApi {
38 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
40 private boolean authenticationShouldSucceed = true;
44 * Performs all one-time initialization required for the end point.
49 // Instantiate our Document Store DAO.
50 documentStore = new StubEsController();
55 @Path("/indexes/{index}")
56 @Consumes({MediaType.APPLICATION_JSON})
58 public Response processCreateIndex(String requestBody,
59 @Context HttpServletRequest request,
60 @Context HttpHeaders headers,
61 @PathParam("index") String index) {
63 return super.processCreateIndex(requestBody, request, headers, index);
67 @Path("/indexes/dynamic/{index}")
68 @Consumes({MediaType.APPLICATION_JSON})
70 public Response processCreateDynamicIndex(String requestBody,
71 @Context HttpServletRequest request,
72 @Context HttpHeaders headers,
73 @PathParam("index") String index) {
75 return super.processCreateDynamicIndex(requestBody, request, headers, index);
79 @Path("/indexes/{index}")
80 @Consumes({MediaType.APPLICATION_JSON})
82 public Response processDeleteIndex(String requestBody,
83 @Context HttpServletRequest request,
84 @Context HttpHeaders headers,
85 @PathParam("index") String index) {
87 return super.processDeleteIndex(requestBody, request, headers, index);
91 @Path("/indexes/{index}/documents/{id}")
92 @Consumes({MediaType.APPLICATION_JSON})
94 public Response processGetDocument(String requestBody,
95 @Context HttpServletRequest request,
96 @Context HttpServletResponse httpResponse,
97 @Context HttpHeaders headers,
98 @PathParam("index") String index,
99 @PathParam("id") String id) {
101 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
105 @Path("/indexes/{index}/documents")
106 @Consumes({MediaType.APPLICATION_JSON})
108 public Response processCreateDocWithoutId(String requestBody,
109 @Context HttpServletRequest request,
110 @Context HttpServletResponse httpResponse,
111 @Context HttpHeaders headers,
112 @PathParam("index") String index) {
114 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
118 @Path("/indexes/{index}/documents/{id}")
119 @Consumes({MediaType.APPLICATION_JSON})
121 public Response processUpsertDoc(String requestBody,
122 @Context HttpServletRequest request,
123 @Context HttpServletResponse httpResponse,
124 @Context HttpHeaders headers,
125 @PathParam("index") String index,
126 @PathParam("id") String id) {
128 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
132 @Path("/indexes/{index}/documents/{id}")
133 @Consumes({MediaType.APPLICATION_JSON})
135 public Response processDeleteDoc(String requestBody,
136 @Context HttpServletRequest request,
137 @Context HttpServletResponse httpResponse,
138 @Context HttpHeaders headers,
139 @PathParam("index") String index,
140 @PathParam("id") String id) {
142 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
146 @Path("/indexes/{index}/query/{queryText}")
147 @Consumes({MediaType.APPLICATION_JSON})
149 public Response processInlineQuery(String requestBody,
150 @Context HttpServletRequest request,
151 @Context HttpHeaders headers,
152 @PathParam("index") String index,
153 @PathParam("queryText") String queryText) {
155 return super.processInlineQuery(requestBody, request, headers, index, queryText);
159 @Path("/indexes/{index}/query")
160 @Consumes({MediaType.APPLICATION_JSON})
162 public Response processQueryWithGet(String requestBody,
163 @Context HttpServletRequest request,
164 @Context HttpHeaders headers,
165 @PathParam("index") String index) {
167 return super.processQueryWithGet(requestBody, request, headers, index);
171 @Path("/indexes/{index}/query")
172 @Consumes({MediaType.APPLICATION_JSON})
174 public Response processQuery(String requestBody,
175 @Context HttpServletRequest request,
176 @Context HttpHeaders headers,
177 @PathParam("index") String index) {
179 return super.processQuery(requestBody, request, headers, index);
184 @Consumes({MediaType.APPLICATION_JSON})
186 public Response processBulkRequest(String requestBody,
187 @Context HttpServletRequest request,
188 @Context HttpHeaders headers,
189 @PathParam("index") String index) {
191 // If the operations string contains a special keyword, set the
192 // harness to fail the authentication validation.
193 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
194 authenticationShouldSucceed = false;
197 // Just pass the request up to the parent, since that is the code
198 // that we really want to test.
199 //return super.processPost(operations, request, headers, index);
200 return super.processBulkRequest(requestBody, request, headers, index);
204 protected boolean validateRequest(HttpHeaders headers,
205 HttpServletRequest req,
206 ApiUtils.Action action,
207 String authPolicyFunctionName) throws Exception {
209 return authenticationShouldSucceed;