2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License ati
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.openecomp.sa.rest;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
30 import javax.ws.rs.core.Context;
31 import javax.ws.rs.core.HttpHeaders;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
36 public class SearchServiceApiHarness extends SearchServiceApi {
39 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
41 private boolean authenticationShouldSucceed = true;
45 * Performs all one-time initialization required for the end point.
50 // Instantiate our Document Store DAO.
51 documentStore = new StubEsController();
56 @Path("/indexes/{index}")
57 @Consumes({MediaType.APPLICATION_JSON})
59 public Response processCreateIndex(String requestBody,
60 @Context HttpServletRequest request,
61 @Context HttpHeaders headers,
62 @PathParam("index") String index) {
64 return super.processCreateIndex(requestBody, request, headers, index);
68 @Path("/indexes/{index}")
69 @Consumes({MediaType.APPLICATION_JSON})
71 public Response processDeleteIndex(String requestBody,
72 @Context HttpServletRequest request,
73 @Context HttpHeaders headers,
74 @PathParam("index") String index) {
76 return super.processDeleteIndex(requestBody, request, headers, index);
80 @Path("/indexes/{index}/documents/{id}")
81 @Consumes({MediaType.APPLICATION_JSON})
83 public Response processGetDocument(String requestBody,
84 @Context HttpServletRequest request,
85 @Context HttpServletResponse httpResponse,
86 @Context HttpHeaders headers,
87 @PathParam("index") String index,
88 @PathParam("id") String id) {
90 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
94 @Path("/indexes/{index}/documents")
95 @Consumes({MediaType.APPLICATION_JSON})
97 public Response processCreateDocWithoutId(String requestBody,
98 @Context HttpServletRequest request,
99 @Context HttpServletResponse httpResponse,
100 @Context HttpHeaders headers,
101 @PathParam("index") String index) {
103 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
107 @Path("/indexes/{index}/documents/{id}")
108 @Consumes({MediaType.APPLICATION_JSON})
110 public Response processUpsertDoc(String requestBody,
111 @Context HttpServletRequest request,
112 @Context HttpServletResponse httpResponse,
113 @Context HttpHeaders headers,
114 @PathParam("index") String index,
115 @PathParam("id") String id) {
117 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
121 @Path("/indexes/{index}/documents/{id}")
122 @Consumes({MediaType.APPLICATION_JSON})
124 public Response processDeleteDoc(String requestBody,
125 @Context HttpServletRequest request,
126 @Context HttpServletResponse httpResponse,
127 @Context HttpHeaders headers,
128 @PathParam("index") String index,
129 @PathParam("id") String id) {
131 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
135 @Path("/indexes/{index}/query/{queryText}")
136 @Consumes({MediaType.APPLICATION_JSON})
138 public Response processInlineQuery(String requestBody,
139 @Context HttpServletRequest request,
140 @Context HttpHeaders headers,
141 @PathParam("index") String index,
142 @PathParam("queryText") String queryText) {
144 return super.processInlineQuery(requestBody, request, headers, index, queryText);
148 @Path("/indexes/{index}/query")
149 @Consumes({MediaType.APPLICATION_JSON})
151 public Response processQueryWithGet(String requestBody,
152 @Context HttpServletRequest request,
153 @Context HttpHeaders headers,
154 @PathParam("index") String index) {
156 return super.processQueryWithGet(requestBody, request, headers, index);
160 @Path("/indexes/{index}/query")
161 @Consumes({MediaType.APPLICATION_JSON})
163 public Response processQuery(String requestBody,
164 @Context HttpServletRequest request,
165 @Context HttpHeaders headers,
166 @PathParam("index") String index) {
168 return super.processQuery(requestBody, request, headers, index);
173 @Consumes({MediaType.APPLICATION_JSON})
175 public Response processBulkRequest(String requestBody,
176 @Context HttpServletRequest request,
177 @Context HttpHeaders headers,
178 @PathParam("index") String index) {
180 // If the operations string contains a special keyword, set the
181 // harness to fail the authentication validation.
182 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
183 authenticationShouldSucceed = false;
186 // Just pass the request up to the parent, since that is the code
187 // that we really want to test.
188 //return super.processPost(operations, request, headers, index);
189 return super.processBulkRequest(requestBody, request, headers, index);
193 protected boolean validateRequest(HttpHeaders headers,
194 HttpServletRequest req,
195 ApiUtils.Action action,
196 String authPolicyFunctionName) throws Exception {
198 return authenticationShouldSucceed;