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.openecomp.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;
34 public class SearchServiceApiHarness extends SearchServiceApi {
37 public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
39 private boolean authenticationShouldSucceed = true;
43 * Performs all one-time initialization required for the end point.
48 // Instantiate our Document Store DAO.
49 documentStore = new StubEsController();
54 @Path("/indexes/{index}")
55 @Consumes({MediaType.APPLICATION_JSON})
57 public Response processCreateIndex(String requestBody,
58 @Context HttpServletRequest request,
59 @Context HttpHeaders headers,
60 @PathParam("index") String index) {
62 return super.processCreateIndex(requestBody, request, headers, index);
66 @Path("/indexes/{index}")
67 @Consumes({MediaType.APPLICATION_JSON})
69 public Response processDeleteIndex(String requestBody,
70 @Context HttpServletRequest request,
71 @Context HttpHeaders headers,
72 @PathParam("index") String index) {
74 return super.processDeleteIndex(requestBody, request, headers, index);
78 @Path("/indexes/{index}/documents/{id}")
79 @Consumes({MediaType.APPLICATION_JSON})
81 public Response processGetDocument(String requestBody,
82 @Context HttpServletRequest request,
83 @Context HttpServletResponse httpResponse,
84 @Context HttpHeaders headers,
85 @PathParam("index") String index,
86 @PathParam("id") String id) {
88 return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
92 @Path("/indexes/{index}/documents")
93 @Consumes({MediaType.APPLICATION_JSON})
95 public Response processCreateDocWithoutId(String requestBody,
96 @Context HttpServletRequest request,
97 @Context HttpServletResponse httpResponse,
98 @Context HttpHeaders headers,
99 @PathParam("index") String index) {
101 return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
105 @Path("/indexes/{index}/documents/{id}")
106 @Consumes({MediaType.APPLICATION_JSON})
108 public Response processUpsertDoc(String requestBody,
109 @Context HttpServletRequest request,
110 @Context HttpServletResponse httpResponse,
111 @Context HttpHeaders headers,
112 @PathParam("index") String index,
113 @PathParam("id") String id) {
115 return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
119 @Path("/indexes/{index}/documents/{id}")
120 @Consumes({MediaType.APPLICATION_JSON})
122 public Response processDeleteDoc(String requestBody,
123 @Context HttpServletRequest request,
124 @Context HttpServletResponse httpResponse,
125 @Context HttpHeaders headers,
126 @PathParam("index") String index,
127 @PathParam("id") String id) {
129 return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
133 @Path("/indexes/{index}/query/{queryText}")
134 @Consumes({MediaType.APPLICATION_JSON})
136 public Response processInlineQuery(String requestBody,
137 @Context HttpServletRequest request,
138 @Context HttpHeaders headers,
139 @PathParam("index") String index,
140 @PathParam("queryText") String queryText) {
142 return super.processInlineQuery(requestBody, request, headers, index, queryText);
146 @Path("/indexes/{index}/query")
147 @Consumes({MediaType.APPLICATION_JSON})
149 public Response processQueryWithGet(String requestBody,
150 @Context HttpServletRequest request,
151 @Context HttpHeaders headers,
152 @PathParam("index") String index) {
154 return super.processQueryWithGet(requestBody, request, headers, index);
158 @Path("/indexes/{index}/query")
159 @Consumes({MediaType.APPLICATION_JSON})
161 public Response processQuery(String requestBody,
162 @Context HttpServletRequest request,
163 @Context HttpHeaders headers,
164 @PathParam("index") String index) {
166 return super.processQuery(requestBody, request, headers, index);
171 @Consumes({MediaType.APPLICATION_JSON})
173 public Response processBulkRequest(String requestBody,
174 @Context HttpServletRequest request,
175 @Context HttpHeaders headers,
176 @PathParam("index") String index) {
178 // If the operations string contains a special keyword, set the
179 // harness to fail the authentication validation.
180 if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
181 authenticationShouldSucceed = false;
184 // Just pass the request up to the parent, since that is the code
185 // that we really want to test.
186 //return super.processPost(operations, request, headers, index);
187 return super.processBulkRequest(requestBody, request, headers, index);
191 protected boolean validateRequest(HttpHeaders headers,
192 HttpServletRequest req,
193 ApiUtils.Action action,
194 String authPolicyFunctionName) throws Exception {
196 return authenticationShouldSucceed;