diff options
Diffstat (limited to 'src/test/java/org/openecomp/sa/rest/SearchServiceApiHarness.java')
-rw-r--r-- | src/test/java/org/openecomp/sa/rest/SearchServiceApiHarness.java | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/src/test/java/org/openecomp/sa/rest/SearchServiceApiHarness.java b/src/test/java/org/openecomp/sa/rest/SearchServiceApiHarness.java new file mode 100644 index 0000000..1306740 --- /dev/null +++ b/src/test/java/org/openecomp/sa/rest/SearchServiceApiHarness.java @@ -0,0 +1,200 @@ +/** + * ============LICENSE_START======================================================= + * Search Data Service + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License ati + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.sa.rest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("test/") +public class SearchServiceApiHarness extends SearchServiceApi { + + + public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION"; + + private boolean authenticationShouldSucceed = true; + + + /** + * Performs all one-time initialization required for the end point. + */ + @Override + public void init() { + + // Instantiate our Document Store DAO. + documentStore = new StubEsController(); + } + + + @PUT + @Path("/indexes/{index}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processCreateIndex(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + return super.processCreateIndex(requestBody, request, headers, index); + } + + @DELETE + @Path("/indexes/{index}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processDeleteIndex(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + return super.processDeleteIndex(requestBody, request, headers, index); + } + + @GET + @Path("/indexes/{index}/documents/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processGetDocument(String requestBody, + @Context HttpServletRequest request, + @Context HttpServletResponse httpResponse, + @Context HttpHeaders headers, + @PathParam("index") String index, + @PathParam("id") String id) { + + return super.processGetDocument(requestBody, request, httpResponse, headers, index, id); + } + + @POST + @Path("/indexes/{index}/documents") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processCreateDocWithoutId(String requestBody, + @Context HttpServletRequest request, + @Context HttpServletResponse httpResponse, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index); + } + + @PUT + @Path("/indexes/{index}/documents/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processUpsertDoc(String requestBody, + @Context HttpServletRequest request, + @Context HttpServletResponse httpResponse, + @Context HttpHeaders headers, + @PathParam("index") String index, + @PathParam("id") String id) { + + return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id); + } + + @DELETE + @Path("/indexes/{index}/documents/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processDeleteDoc(String requestBody, + @Context HttpServletRequest request, + @Context HttpServletResponse httpResponse, + @Context HttpHeaders headers, + @PathParam("index") String index, + @PathParam("id") String id) { + + return super.processDeleteDoc(requestBody, request, httpResponse, headers, index, id); + } + + @GET + @Path("/indexes/{index}/query/{queryText}") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processInlineQuery(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index, + @PathParam("queryText") String queryText) { + + return super.processInlineQuery(requestBody, request, headers, index, queryText); + } + + @GET + @Path("/indexes/{index}/query") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processQueryWithGet(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + return super.processQueryWithGet(requestBody, request, headers, index); + } + + @POST + @Path("/indexes/{index}/query") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processQuery(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + return super.processQuery(requestBody, request, headers, index); + } + + @POST + @Path("/bulk") + @Consumes({MediaType.APPLICATION_JSON}) + @Override + public Response processBulkRequest(String requestBody, + @Context HttpServletRequest request, + @Context HttpHeaders headers, + @PathParam("index") String index) { + + // If the operations string contains a special keyword, set the + // harness to fail the authentication validation. + if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) { + authenticationShouldSucceed = false; + } + + // Just pass the request up to the parent, since that is the code + // that we really want to test. + //return super.processPost(operations, request, headers, index); + return super.processBulkRequest(requestBody, request, headers, index); + } + + @Override + protected boolean validateRequest(HttpHeaders headers, + HttpServletRequest req, + ApiUtils.Action action, + String authPolicyFunctionName) throws Exception { + + return authenticationShouldSucceed; + } +} |