Add missing distributionManagement section to poms
[aai/search-data-service.git] / search-data-service-app / src / test / java / org / onap / aai / sa / rest / SearchServiceApiHarness.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 package org.onap.aai.sa.rest;
22
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.springframework.http.HttpHeaders;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.stereotype.Component;
28 import org.springframework.web.bind.annotation.PathVariable;
29 import org.springframework.web.bind.annotation.RequestBody;
30 import org.springframework.web.bind.annotation.RequestHeader;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.RestController;
34
35 @Component
36 @RestController
37 @RequestMapping("/test")
38 public class SearchServiceApiHarness extends SearchServiceApi {
39
40
41     public static final String FAIL_AUTHENTICATION_TRIGGER = "FAIL AUTHENTICATION";
42
43     private boolean authenticationShouldSucceed = true;
44
45
46     /**
47      * Performs all one-time initialization required for the end point.
48      */
49     @Override
50     public void init() {
51
52         // Instantiate our Document Store DAO.
53         documentStore = new StubEsController();
54     }
55
56     @Override
57     @RequestMapping(value = "/indexes/dynamic/{index}", method = RequestMethod.PUT, consumes = {"application/json"})
58     public ResponseEntity<String> processCreateDynamicIndex(@RequestBody String requestBody, HttpServletRequest request,
59             @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
60
61         return super.processCreateDynamicIndex(requestBody, request, headers, index);
62     }
63
64
65     @Override
66     @RequestMapping(value = "/indexes/{index}", method = RequestMethod.PUT, consumes = {"application/json"})
67     public ResponseEntity<String> processCreateIndex(@RequestBody String requestBody, HttpServletRequest request,
68             @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
69
70         return super.processCreateIndex(requestBody, request, headers, index);
71     }
72
73     @Override
74     @RequestMapping(value = "/indexes/{index}", method = RequestMethod.DELETE, consumes = {"application/json"})
75     public ResponseEntity<String> processDeleteIndex(HttpServletRequest request, @RequestHeader HttpHeaders headers,
76             @PathVariable("index") String index) {
77
78         return super.processDeleteIndex(request, headers, index);
79     }
80
81     @Override
82     @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.GET)
83     public ResponseEntity<String> processGetDocument(HttpServletRequest request, HttpServletResponse httpResponse,
84             @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) {
85
86         return super.processGetDocument(request, httpResponse, headers, index, id);
87     }
88
89     @Override
90     @RequestMapping(value = "/indexes/{index}/documents", method = RequestMethod.POST,
91             consumes = {"application/json", "application/xml"})
92     public ResponseEntity<String> processCreateDocWithoutId(@RequestBody String requestBody, HttpServletRequest request,
93             HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
94
95         return super.processCreateDocWithoutId(requestBody, request, httpResponse, headers, index);
96     }
97
98     @Override
99     @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.PUT,
100             consumes = {"application/json", "application/xml"})
101     public ResponseEntity<String> processUpsertDoc(@RequestBody String requestBody, HttpServletRequest request,
102             HttpServletResponse httpResponse, @RequestHeader HttpHeaders headers, @PathVariable("index") String index,
103             @PathVariable("id") String id) {
104
105         return super.processUpsertDoc(requestBody, request, httpResponse, headers, index, id);
106     }
107
108     @Override
109     @RequestMapping(value = "/indexes/{index}/documents/{id}", method = RequestMethod.DELETE,
110             consumes = {"application/json"})
111     public ResponseEntity<String> processDeleteDoc(HttpServletRequest request, HttpServletResponse httpResponse,
112             @RequestHeader HttpHeaders headers, @PathVariable("index") String index, @PathVariable("id") String id) {
113
114         return super.processDeleteDoc(request, httpResponse, headers, index, id);
115     }
116
117     @Override
118     @RequestMapping(value = "/indexes/{index}/query/{queryText}", method = RequestMethod.GET)
119     public ResponseEntity<String> processInlineQuery(HttpServletRequest request, @RequestHeader HttpHeaders headers,
120             @PathVariable("index") String index, @PathVariable("queryText") String queryText) {
121
122         return super.processInlineQuery(request, headers, index, queryText);
123     }
124
125     @Override
126     @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.GET, consumes = {"application/json"})
127     public ResponseEntity<String> processQueryWithGet(@RequestBody String requestBody, HttpServletRequest request,
128             @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
129
130         return super.processQueryWithGet(requestBody, request, headers, index);
131     }
132
133     @Override
134     @RequestMapping(value = "/indexes/{index}/query", method = RequestMethod.POST, consumes = {"application/json"})
135     public ResponseEntity<String> processQuery(@RequestBody String requestBody, HttpServletRequest request,
136             @RequestHeader HttpHeaders headers, @PathVariable("index") String index) {
137
138         return super.processQuery(requestBody, request, headers, index);
139     }
140
141     @Override
142     @RequestMapping(value = "/bulk", method = RequestMethod.POST, consumes = {"application/json"},
143             produces = {"application/json"})
144     public ResponseEntity<String> processBulkRequest(@RequestBody String requestBody, HttpServletRequest request,
145             @RequestHeader HttpHeaders headers) {
146
147         // If the operations string contains a special keyword, set the
148         // harness to fail the authentication validation.
149         if (requestBody.contains(FAIL_AUTHENTICATION_TRIGGER)) {
150             authenticationShouldSucceed = false;
151         }
152
153         // Just pass the request up to the parent, since that is the code
154         // that we really want to test.
155         // return super.processPost(operations, request, headers, index);
156         return super.processBulkRequest(requestBody, request, headers);
157     }
158
159     @Override
160     protected boolean validateRequest(HttpHeaders headers, HttpServletRequest req, ApiUtils.Action action,
161             String authPolicyFunctionName) {
162         return authenticationShouldSucceed;
163     }
164 }