X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fsa%2Frest%2FSearchServiceApiHarness.java;h=93e1d490b1ae71a279999800e098eaf3703ec546;hb=refs%2Fchanges%2F67%2F68467%2F1;hp=80c058d60154f6cad4febde4e34ffab56dc6494f;hpb=d6348739c632fb69c8833078effbb902adc7f702;p=aai%2Fsearch-data-service.git diff --git a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java b/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java index 80c058d..93e1d49 100644 --- a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java +++ b/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java @@ -22,178 +22,143 @@ package org.onap.aai.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; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@Component +@RestController +@RequestMapping("/test") +public class SearchServiceApiHarness extends SearchServiceApi { -import org.onap.aai.sa.rest.ApiUtils; -import org.onap.aai.sa.rest.SearchServiceApi; -@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(); + } + + @Override + @RequestMapping(value = "/indexes/dynamic/{index}", method = RequestMethod.PUT, consumes = {"application/json"}) + public ResponseEntity processCreateDynamicIndex(@RequestBody String requestBody, HttpServletRequest request, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index) { + + return super.processCreateDynamicIndex(requestBody, request, headers, index); + } + + + @Override + @RequestMapping(value = "/indexes/{index}", method = RequestMethod.PUT, consumes = {"application/json"}) + public ResponseEntity processCreateIndex(@RequestBody String requestBody, HttpServletRequest request, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index) { + + return super.processCreateIndex(requestBody, request, headers, index); + } + + @Override + @RequestMapping(value = "/indexes/{index}", method = RequestMethod.DELETE, consumes = {"application/json"}) + public ResponseEntity processDeleteIndex(HttpServletRequest request, @RequestHeader HttpHeaders headers, + @PathVariable("index") String index) { + + return super.processDeleteIndex(request, headers, index); + } + + @Override + @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.GET) + public ResponseEntity processGetDocument(HttpServletRequest request, HttpServletResponse httpResponse, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) { + return super.processGetDocument(request, httpResponse, headers, index, id); + } + + @Override + @RequestMapping(value = "/indexes/{index}/documents", method = RequestMethod.POST, + consumes = {"application/json", "application/xml"}) + public ResponseEntity processCreateDocWithoutId(@RequestBody String requestBody, HttpServletRequest request, + HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index) { + + return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index); + } + + @Override + @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.PUT, + consumes = {"application/json", "application/xml"}) + public ResponseEntity processUpsertDoc(@RequestBody String requestBody, HttpServletRequest request, + HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index, + @PathVariable("id") String id) { + + return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id); + } + + @Override + @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.DELETE, + consumes = {"application/json"}) + public ResponseEntity processDeleteDoc(HttpServletRequest request, HttpServletResponse httpResponse, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) { + + return super.processDeleteDoc(request, httpResponse, headers, index, id); + } + + @Override + @RequestMapping(value = "/indexes/{index}/query/{queryText}", method = RequestMethod.GET) + public ResponseEntity processInlineQuery(HttpServletRequest request, @RequestHeader HttpHeaders headers, + @PathVariable("index") String index, @PathVariable("queryText") String queryText) { - 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; + return super.processInlineQuery(request, headers, index, queryText); } - // 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 + @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.GET, consumes = {"application/json"}) + public ResponseEntity processQueryWithGet(@RequestBody String requestBody, HttpServletRequest request, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index) { - @Override - protected boolean validateRequest(HttpHeaders headers, - HttpServletRequest req, - ApiUtils.Action action, - String authPolicyFunctionName) throws Exception { + return super.processQueryWithGet(requestBody, request, headers, index); + } - return authenticationShouldSucceed; - } + @Override + @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.POST, consumes = {"application/json"}) + public ResponseEntity processQuery(@RequestBody String requestBody, HttpServletRequest request, + @RequestHeader HttpHeaders headers, @PathVariable("index") String index) { + + return super.processQuery(requestBody, request, headers, index); + } + + @Override + @RequestMapping(value = "/bulk", method = RequestMethod.POST, consumes = {"application/json"}, + produces = {"application/json"}) + public ResponseEntity processBulkRequest(@RequestBody String requestBody, HttpServletRequest request, + @RequestHeader HttpHeaders headers) { + + // 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); + } + + @Override + protected boolean validateRequest(HttpHeaders headers, HttpServletRequest req, ApiUtils.Action action, + String authPolicyFunctionName) { + return authenticationShouldSucceed; + } }