Cleanup project's name in Sonar
[aai/search-data-service.git] / src / test / java / org / onap / aai / 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.onap.aai.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 import org.onap.aai.sa.rest.ApiUtils;
34 import org.onap.aai.sa.rest.SearchServiceApi;
35
36 @Path("test/")
37 public class SearchServiceApiHarness extends SearchServiceApi {
38
39
40   public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
41
42   private boolean authenticationShouldSucceed = true;
43
44
45   /**
46    * Performs all one-time initialization required for the end point.
47    */
48   @Override
49   public void init() {
50
51     // Instantiate our Document Store DAO.
52     documentStore = new StubEsController();
53   }
54
55
56   @PUT
57   @Path("/indexes/{index}")
58   @Consumes({MediaType.APPLICATION_JSON})
59   @Override
60   public Response processCreateIndex(String requestBody,
61                                      @Context HttpServletRequest request,
62                                      @Context HttpHeaders headers,
63                                      @PathParam("index") String index) {
64
65     return super.processCreateIndex(requestBody, request, headers, index);
66   }
67
68   @DELETE
69   @Path("/indexes/{index}")
70   @Consumes({MediaType.APPLICATION_JSON})
71   @Override
72   public Response processDeleteIndex(String requestBody,
73                                      @Context HttpServletRequest request,
74                                      @Context HttpHeaders headers,
75                                      @PathParam("index") String index) {
76
77     return super.processDeleteIndex(requestBody, request, headers, index);
78   }
79
80   @GET
81   @Path("/indexes/{index}/documents/{id}")
82   @Consumes({MediaType.APPLICATION_JSON})
83   @Override
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) {
90
91     return super.processGetDocument(requestBody, request, httpResponse, headers, index, id);
92   }
93
94   @POST
95   @Path("/indexes/{index}/documents")
96   @Consumes({MediaType.APPLICATION_JSON})
97   @Override
98   public Response processCreateDocWithoutId(String requestBody,
99                                             @Context HttpServletRequest request,
100                                             @Context HttpServletResponse httpResponse,
101                                             @Context HttpHeaders headers,
102                                             @PathParam("index") String index) {
103
104     return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
105   }
106
107   @PUT
108   @Path("/indexes/{index}/documents/{id}")
109   @Consumes({MediaType.APPLICATION_JSON})
110   @Override
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) {
117
118     return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
119   }
120
121   @DELETE
122   @Path("/indexes/{index}/documents/{id}")
123   @Consumes({MediaType.APPLICATION_JSON})
124   @Override
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) {
131
132     return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id);
133   }
134
135   @GET
136   @Path("/indexes/{index}/query/{queryText}")
137   @Consumes({MediaType.APPLICATION_JSON})
138   @Override
139   public Response processInlineQuery(String requestBody,
140                                      @Context HttpServletRequest request,
141                                      @Context HttpHeaders headers,
142                                      @PathParam("index") String index,
143                                      @PathParam("queryText") String queryText) {
144
145     return super.processInlineQuery(requestBody, request, headers, index, queryText);
146   }
147
148   @GET
149   @Path("/indexes/{index}/query")
150   @Consumes({MediaType.APPLICATION_JSON})
151   @Override
152   public Response processQueryWithGet(String requestBody,
153                                       @Context HttpServletRequest request,
154                                       @Context HttpHeaders headers,
155                                       @PathParam("index") String index) {
156
157     return super.processQueryWithGet(requestBody, request, headers, index);
158   }
159
160   @POST
161   @Path("/indexes/{index}/query")
162   @Consumes({MediaType.APPLICATION_JSON})
163   @Override
164   public Response processQuery(String requestBody,
165                                @Context HttpServletRequest request,
166                                @Context HttpHeaders headers,
167                                @PathParam("index") String index) {
168
169     return super.processQuery(requestBody, request, headers, index);
170   }
171
172   @POST
173   @Path("/bulk")
174   @Consumes({MediaType.APPLICATION_JSON})
175   @Override
176   public Response processBulkRequest(String requestBody,
177                                      @Context HttpServletRequest request,
178                                      @Context HttpHeaders headers,
179                                      @PathParam("index") String index) {
180
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;
185     }
186
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);
191   }
192
193   @Override
194   protected boolean validateRequest(HttpHeaders headers,
195                                     HttpServletRequest req,
196                                     ApiUtils.Action action,
197                                     String authPolicyFunctionName) throws Exception {
198
199     return authenticationShouldSucceed;
200   }
201 }