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/{index}")
68 @Consumes({MediaType.APPLICATION_JSON})
70 public Response processDeleteIndex(String requestBody,
71 @Context HttpServletRequest request,
72 @Context HttpHeaders headers,
73 @PathParam("index") String index) {
75 return super.processDeleteIndex(requestBody, request, headers, index);
79 @Path("/indexes/{index}/documents/{id}")
80 @Consumes({MediaType.APPLICATION_JSON})
82 public Response processGetDocument(String requestBody,
83 @Context HttpServletRequest request,
84 @Context HttpServletResponse httpResponse,
85 @Context HttpHeaders headers,
86 @PathParam("index") String index,
87 @PathParam("id") String id) {
89 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
93 @Path("/indexes/{index}/documents")
94 @Consumes({MediaType.APPLICATION_JSON})
96 public Response processCreateDocWithoutId(String requestBody,
97 @Context HttpServletRequest request,
98 @Context HttpServletResponse httpResponse,
99 @Context HttpHeaders headers,
100 @PathParam("index") String index) {
102 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
106 @Path("/indexes/{index}/documents/{id}")
107 @Consumes({MediaType.APPLICATION_JSON})
109 public Response processUpsertDoc(String requestBody,
110 @Context HttpServletRequest request,
111 @Context HttpServletResponse httpResponse,
112 @Context HttpHeaders headers,
113 @PathParam("index") String index,
114 @PathParam("id") String id) {
116 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
120 @Path("/indexes/{index}/documents/{id}")
121 @Consumes({MediaType.APPLICATION_JSON})
123 public Response processDeleteDoc(String requestBody,
124 @Context HttpServletRequest request,
125 @Context HttpServletResponse httpResponse,
126 @Context HttpHeaders headers,
127 @PathParam("index") String index,
128 @PathParam("id") String id) {
130 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
134 @Path("/indexes/{index}/query/{queryText}")
135 @Consumes({MediaType.APPLICATION_JSON})
137 public Response processInlineQuery(String requestBody,
138 @Context HttpServletRequest request,
139 @Context HttpHeaders headers,
140 @PathParam("index") String index,
141 @PathParam("queryText") String queryText) {
143 return super.processInlineQuery(requestBody, request, headers, index, queryText);
147 @Path("/indexes/{index}/query")
148 @Consumes({MediaType.APPLICATION_JSON})
150 public Response processQueryWithGet(String requestBody,
151 @Context HttpServletRequest request,
152 @Context HttpHeaders headers,
153 @PathParam("index") String index) {
155 return super.processQueryWithGet(requestBody, request, headers, index);
159 @Path("/indexes/{index}/query")
160 @Consumes({MediaType.APPLICATION_JSON})
162 public Response processQuery(String requestBody,
163 @Context HttpServletRequest request,
164 @Context HttpHeaders headers,
165 @PathParam("index") String index) {
167 return super.processQuery(requestBody, request, headers, index);
172 @Consumes({MediaType.APPLICATION_JSON})
174 public Response processBulkRequest(String requestBody,
175 @Context HttpServletRequest request,
176 @Context HttpHeaders headers,
177 @PathParam("index") String index) {
179 // If the operations string contains a special keyword, set the
180 // harness to fail the authentication validation.
181 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
182 authenticationShouldSucceed = false;
185 // Just pass the request up to the parent, since that is the code
186 // that we really want to test.
187 //return super.processPost(operations, request, headers, index);
188 return super.processBulkRequest(requestBody, request, headers, index);
192 protected boolean validateRequest(HttpHeaders headers,
193 HttpServletRequest req,
194 ApiUtils.Action action,
195 String authPolicyFunctionName) throws Exception {
197 return authenticationShouldSucceed;