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