2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sa.rest;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.HttpHeaders;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
33 import org.onap.aai.sa.rest.ApiUtils;
34 import org.onap.aai.sa.rest.SearchServiceApi;
37 public class SearchServiceApiHarness extends SearchServiceApi {
40 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
42 private boolean authenticationShouldSucceed = true;
46 * Performs all one-time initialization required for the end point.
51 // Instantiate our Document Store DAO.
52 documentStore = new StubEsController();
57 @Path("/indexes/{index}")
58 @Consumes({MediaType.APPLICATION_JSON})
60 public Response processCreateIndex(String requestBody,
61 @Context HttpServletRequest request,
62 @Context HttpHeaders headers,
63 @PathParam("index") String index) {
65 return super.processCreateIndex(requestBody, request, headers, index);
69 @Path("/indexes/{index}")
70 @Consumes({MediaType.APPLICATION_JSON})
72 public Response processDeleteIndex(String requestBody,
73 @Context HttpServletRequest request,
74 @Context HttpHeaders headers,
75 @PathParam("index") String index) {
77 return super.processDeleteIndex(requestBody, request, headers, index);
81 @Path("/indexes/{index}/documents/{id}")
82 @Consumes({MediaType.APPLICATION_JSON})
84 public Response processGetDocument(String requestBody,
85 @Context HttpServletRequest request,
86 @Context HttpServletResponse httpResponse,
87 @Context HttpHeaders headers,
88 @PathParam("index") String index,
89 @PathParam("id") String id) {
91 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
95 @Path("/indexes/{index}/documents")
96 @Consumes({MediaType.APPLICATION_JSON})
98 public Response processCreateDocWithoutId(String requestBody,
99 @Context HttpServletRequest request,
100 @Context HttpServletResponse httpResponse,
101 @Context HttpHeaders headers,
102 @PathParam("index") String index) {
104 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
108 @Path("/indexes/{index}/documents/{id}")
109 @Consumes({MediaType.APPLICATION_JSON})
111 public Response processUpsertDoc(String requestBody,
112 @Context HttpServletRequest request,
113 @Context HttpServletResponse httpResponse,
114 @Context HttpHeaders headers,
115 @PathParam("index") String index,
116 @PathParam("id") String id) {
118 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
122 @Path("/indexes/{index}/documents/{id}")
123 @Consumes({MediaType.APPLICATION_JSON})
125 public Response processDeleteDoc(String requestBody,
126 @Context HttpServletRequest request,
127 @Context HttpServletResponse httpResponse,
128 @Context HttpHeaders headers,
129 @PathParam("index") String index,
130 @PathParam("id") String id) {
132 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
136 @Path("/indexes/{index}/query/{queryText}")
137 @Consumes({MediaType.APPLICATION_JSON})
139 public Response processInlineQuery(String requestBody,
140 @Context HttpServletRequest request,
141 @Context HttpHeaders headers,
142 @PathParam("index") String index,
143 @PathParam("queryText") String queryText) {
145 return super.processInlineQuery(requestBody, request, headers, index, queryText);
149 @Path("/indexes/{index}/query")
150 @Consumes({MediaType.APPLICATION_JSON})
152 public Response processQueryWithGet(String requestBody,
153 @Context HttpServletRequest request,
154 @Context HttpHeaders headers,
155 @PathParam("index") String index) {
157 return super.processQueryWithGet(requestBody, request, headers, index);
161 @Path("/indexes/{index}/query")
162 @Consumes({MediaType.APPLICATION_JSON})
164 public Response processQuery(String requestBody,
165 @Context HttpServletRequest request,
166 @Context HttpHeaders headers,
167 @PathParam("index") String index) {
169 return super.processQuery(requestBody, request, headers, index);
174 @Consumes({MediaType.APPLICATION_JSON})
176 public Response processBulkRequest(String requestBody,
177 @Context HttpServletRequest request,
178 @Context HttpHeaders headers,
179 @PathParam("index") String index) {
181 // If the operations string contains a special keyword, set the
182 // harness to fail the authentication validation.
183 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
184 authenticationShouldSucceed = false;
187 // Just pass the request up to the parent, since that is the code
188 // that we really want to test.
189 //return super.processPost(operations, request, headers, index);
190 return super.processBulkRequest(requestBody, request, headers, index);
194 protected boolean validateRequest(HttpHeaders headers,
195 HttpServletRequest req,
196 ApiUtils.Action action,
197 String authPolicyFunctionName) throws Exception {
199 return authenticationShouldSucceed;