X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fsa%2Frest%2FSearchServiceApiHarness.java;h=072b0902b990d2b20d076228951db98cad08f2d8;hb=15af66b115f3e8046b2d0f2634fb77b3d835f730;hp=0621cd87e7f951427aff201cf36d9b3cb75dd1af;hpb=71393bb2bf9fb10962723e61cf0e70d9aa202645;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 0621cd8..072b090 100644 --- a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java +++ b/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java @@ -20,7 +20,7 @@ */ package org.onap.aai.sa.rest; - import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; @@ -38,172 +38,128 @@ import org.springframework.web.bind.annotation.RestController; 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) { - - return super.processInlineQuery(request, headers, index, queryText); - } - - @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) { - - return super.processQueryWithGet(requestBody, request, headers, index); - } - - @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; + 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); } - // 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) throws Exception { + @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 authenticationShouldSucceed; - } + 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) { + + return super.processInlineQuery(request, headers, index, queryText); + } + + @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) { + + return super.processQueryWithGet(requestBody, request, headers, index); + } + + @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) throws Exception { + + return authenticationShouldSucceed; + } }