Initial search service commit
[aai/search-data-service.git] / src / test / java / org / openecomp / sa / rest / SearchServiceApiHarness.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Search Data Service
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.sa.rest;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.ws.rs.*;
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;
34
35 @Path("test/")
36 public class SearchServiceApiHarness extends SearchServiceApi {
37
38
39   public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
40
41   private boolean authenticationShouldSucceed = true;
42
43
44   /**
45    * Performs all one-time initialization required for the end point.
46    */
47   @Override
48   public void init() {
49
50     // Instantiate our Document Store DAO.
51     documentStore = new StubEsController();
52   }
53
54
55   @PUT
56   @Path("/indexes/{index}")
57   @Consumes({MediaType.APPLICATION_JSON})
58   @Override
59   public Response processCreateIndex(String requestBody,
60                                      @Context HttpServletRequest request,
61                                      @Context HttpHeaders headers,
62                                      @PathParam("index") String index) {
63
64     return super.processCreateIndex(requestBody, request, headers, index);
65   }
66
67   @DELETE
68   @Path("/indexes/{index}")
69   @Consumes({MediaType.APPLICATION_JSON})
70   @Override
71   public Response processDeleteIndex(String requestBody,
72                                      @Context HttpServletRequest request,
73                                      @Context HttpHeaders headers,
74                                      @PathParam("index") String index) {
75
76     return super.processDeleteIndex(requestBody, request, headers, index);
77   }
78
79   @GET
80   @Path("/indexes/{index}/documents/{id}")
81   @Consumes({MediaType.APPLICATION_JSON})
82   @Override
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) {
89
90     return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
91   }
92
93   @POST
94   @Path("/indexes/{index}/documents")
95   @Consumes({MediaType.APPLICATION_JSON})
96   @Override
97   public Response processCreateDocWithoutId(String requestBody,
98                                             @Context HttpServletRequest request,
99                                             @Context HttpServletResponse httpResponse,
100                                             @Context HttpHeaders headers,
101                                             @PathParam("index") String index) {
102
103     return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
104   }
105
106   @PUT
107   @Path("/indexes/{index}/documents/{id}")
108   @Consumes({MediaType.APPLICATION_JSON})
109   @Override
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) {
116
117     return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
118   }
119
120   @DELETE
121   @Path("/indexes/{index}/documents/{id}")
122   @Consumes({MediaType.APPLICATION_JSON})
123   @Override
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) {
130
131     return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
132   }
133
134   @GET
135   @Path("/indexes/{index}/query/{queryText}")
136   @Consumes({MediaType.APPLICATION_JSON})
137   @Override
138   public Response processInlineQuery(String requestBody,
139                                      @Context HttpServletRequest request,
140                                      @Context HttpHeaders headers,
141                                      @PathParam("index") String index,
142                                      @PathParam("queryText") String queryText) {
143
144     return super.processInlineQuery(requestBody, request, headers, index, queryText);
145   }
146
147   @GET
148   @Path("/indexes/{index}/query")
149   @Consumes({MediaType.APPLICATION_JSON})
150   @Override
151   public Response processQueryWithGet(String requestBody,
152                                       @Context HttpServletRequest request,
153                                       @Context HttpHeaders headers,
154                                       @PathParam("index") String index) {
155
156     return super.processQueryWithGet(requestBody, request, headers, index);
157   }
158
159   @POST
160   @Path("/indexes/{index}/query")
161   @Consumes({MediaType.APPLICATION_JSON})
162   @Override
163   public Response processQuery(String requestBody,
164                                @Context HttpServletRequest request,
165                                @Context HttpHeaders headers,
166                                @PathParam("index") String index) {
167
168     return super.processQuery(requestBody, request, headers, index);
169   }
170
171   @POST
172   @Path("/bulk")
173   @Consumes({MediaType.APPLICATION_JSON})
174   @Override
175   public Response processBulkRequest(String requestBody,
176                                      @Context HttpServletRequest request,
177                                      @Context HttpHeaders headers,
178                                      @PathParam("index") String index) {
179
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;
184     }
185
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);
190   }
191
192   @Override
193   protected boolean validateRequest(HttpHeaders headers,
194                                     HttpServletRequest req,
195                                     ApiUtils.Action action,
196                                     String authPolicyFunctionName) throws Exception {
197
198     return authenticationShouldSucceed;
199   }
200 }