2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017-2018 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 package org.onap.aai.sa.rest;
\r
23 import com.fasterxml.jackson.core.JsonProcessingException;
\r
24 import javax.servlet.http.HttpServletRequest;
\r
25 import javax.servlet.http.HttpServletResponse;
\r
26 // import javax.ws.rs.core.HttpHeaders;
\r
27 import javax.ws.rs.core.MultivaluedMap;
\r
28 import org.junit.Assert;
\r
29 import org.junit.Before;
\r
30 import org.junit.Ignore;
\r
31 import org.junit.Test;
\r
32 import org.mockito.InjectMocks;
\r
33 import org.mockito.Mock;
\r
34 import org.mockito.Mockito;
\r
35 import org.mockito.MockitoAnnotations;
\r
36 import org.mockito.invocation.InvocationOnMock;
\r
37 import org.mockito.stubbing.Answer;
\r
38 import org.onap.aai.sa.searchdbabstraction.elasticsearch.config.ElasticSearchConfig;
\r
39 import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity;
\r
40 import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface;
\r
41 import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.ElasticSearchHttpController;
\r
42 import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException;
\r
43 import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult;
\r
44 import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult;
\r
45 import org.onap.aai.sa.searchdbabstraction.entity.SearchHits;
\r
46 import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult;
\r
47 import org.springframework.http.HttpHeaders;
\r
48 import org.springframework.http.HttpStatus;
\r
49 import org.springframework.http.ResponseEntity;
\r
50 import java.util.Properties;
\r
53 public class DocumentTest {
\r
56 SearchServiceApi searchServiceApi;
\r
59 HttpServletRequest request;
\r
62 HttpHeaders headers;
\r
65 HttpServletResponse httpResponse;
\r
68 DocumentStoreInterface documentStore;
\r
71 MultivaluedMap<String, String> multivaluedMap;
\r
76 DocumentApi documentApi;
\r
79 ElasticSearchHttpController httpController;
\r
82 public void setUp() {
\r
83 MockitoAnnotations.initMocks(this);
\r
84 documentApi = new DocumentApi(searchServiceApi);
\r
88 public void testDocumentClass_AllMethods() throws JsonProcessingException {
\r
89 Document doc = new Document();
\r
90 doc.setField("name-1", "value-1");
\r
91 Assert.assertTrue(doc.getFields().size() == 1);
\r
92 Assert.assertTrue(doc.toJson().contains("value-1"));
\r
93 Assert.assertNotNull(doc.toString());
\r
94 Assert.assertTrue(doc.toString().contains("name-1"));
\r
98 public void testProcessPost_NullContent() {
\r
99 String transactionId = "transactionId-1";
\r
100 String remoteAddr = "http://127.0.0.1";
\r
101 String content = null;
\r
102 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
103 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
104 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
105 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
106 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
107 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
108 ResponseEntity<String> response =
\r
109 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
110 Assert.assertNotNull(response);
\r
111 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
114 @SuppressWarnings("unchecked")
\r
116 public void testProcessPost_NotNullContent() throws Exception {
\r
117 String transactionId = "transactionId-1";
\r
118 String remoteAddr = "http://127.0.0.1";
\r
119 String content = "content";
\r
120 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
121 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
122 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
123 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
124 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
125 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
126 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
127 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
128 .thenThrow(IllegalArgumentException.class);
\r
129 ResponseEntity<?> response =
\r
130 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
131 Assert.assertNotNull(response);
\r
132 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
137 public void testProcessPost_ValidRequest() throws Exception {
\r
138 String transactionId = "transactionId-1";
\r
139 String remoteAddr = "http://127.0.0.1";
\r
140 String content = "content";
\r
141 DocumentOperationResult result = new DocumentOperationResult();
\r
142 result.setResultCode(150);
\r
143 result.setError(new ErrorResult("type-1", "reason-1"));
\r
144 result.setFailureCause("test-failure");
\r
145 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
146 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
147 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
148 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
149 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
150 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
151 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
152 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
154 Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
\r
155 Mockito.anyBoolean())).thenReturn(result);
\r
156 Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString());
\r
157 ResponseEntity<String> response =
\r
158 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
159 Assert.assertNotNull(response);
\r
160 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r
165 public void testProcessSearchWithGet_Created() throws Exception {
\r
166 String transactionId = "transactionId-1";
\r
167 String remoteAddr = "http://127.0.0.1";
\r
168 String content = "content";
\r
169 SearchOperationResult result = new SearchOperationResult();
\r
170 result.setResultCode(201);
\r
171 SearchHits hits = new SearchHits();
\r
172 hits.setTotalHits("2");
\r
173 result.setSearchResult(hits);
\r
174 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
175 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
176 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
177 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
178 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
179 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
180 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
181 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
183 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
184 ResponseEntity<String> response =
\r
185 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
186 Assert.assertNotNull(response);
\r
187 Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue());
\r
191 @SuppressWarnings("unchecked")
\r
193 public void testProcessSearchWithGet_ValidateThrowsException() throws Exception {
\r
194 String transactionId = "transactionId-1";
\r
195 String remoteAddr = "http://127.0.0.1";
\r
196 String content = "content";
\r
197 SearchOperationResult result = new SearchOperationResult();
\r
198 result.setResultCode(201);
\r
199 SearchHits hits = new SearchHits();
\r
200 hits.setTotalHits("2");
\r
201 result.setSearchResult(hits);
\r
202 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
203 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
204 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
205 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
206 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
207 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
208 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
209 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
210 .thenThrow(IllegalArgumentException.class);
\r
211 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
212 ResponseEntity<String> response =
\r
213 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
214 Assert.assertNotNull(response);
\r
215 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
220 public void testProcessSearchWithGet_ValidateIsFalse() throws Exception {
\r
221 String transactionId = "transactionId-1";
\r
222 String remoteAddr = "http://127.0.0.1";
\r
223 String content = "content";
\r
224 SearchOperationResult result = new SearchOperationResult();
\r
225 result.setResultCode(201);
\r
226 SearchHits hits = new SearchHits();
\r
227 hits.setTotalHits("2");
\r
228 result.setSearchResult(hits);
\r
229 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
230 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
231 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
232 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
233 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
234 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
235 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
236 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
237 .thenReturn(false);
\r
238 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
239 ResponseEntity<String> response =
\r
240 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
241 Assert.assertNotNull(response);
\r
242 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
247 public void testProcessSearchWithGet_InvalidResult() throws Exception {
\r
248 String transactionId = "transactionId-1";
\r
249 String remoteAddr = "http://127.0.0.1";
\r
250 String content = "content";
\r
251 SearchOperationResult result = new SearchOperationResult();
\r
252 result.setResultCode(302);
\r
253 SearchHits hits = new SearchHits();
\r
254 hits.setTotalHits("2");
\r
255 result.setSearchResult(hits);
\r
256 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
257 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
258 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
259 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
260 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
261 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
262 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
263 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
265 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
266 ResponseEntity<String> response =
\r
267 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
268 Assert.assertNotNull(response);
\r
269 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
274 public void testProcessPut_NullContent() {
\r
275 String transactionId = "transactionId-1";
\r
276 String remoteAddr = "http://127.0.0.1";
\r
277 String content = null;
\r
278 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
279 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
280 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
281 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
282 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
283 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
284 ResponseEntity<String> response =
\r
285 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
286 Assert.assertNotNull(response);
\r
287 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
290 @SuppressWarnings("unchecked")
\r
292 public void testProcessPut_RequestThrowsException() throws Exception {
\r
293 String transactionId = "transactionId-1";
\r
294 String remoteAddr = "http://127.0.0.1";
\r
295 String content = "content";
\r
296 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
297 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
298 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
299 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
300 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
301 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
302 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
303 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
304 .thenThrow(IllegalArgumentException.class);
\r
305 ResponseEntity<String> response =
\r
306 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
307 Assert.assertNotNull(response);
\r
308 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
312 public void testProcessPut_RequestInvalid() throws Exception {
\r
313 String transactionId = "transactionId-1";
\r
314 String remoteAddr = "http://127.0.0.1";
\r
315 String content = "content";
\r
316 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
317 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
318 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
319 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
320 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
321 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
322 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
323 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
324 .thenReturn(false);
\r
325 ResponseEntity<String> response =
\r
326 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
327 Assert.assertNotNull(response);
\r
328 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
332 public void testProcessPut_ResultInvalid() throws Exception {
\r
333 String transactionId = "transactionId-1";
\r
334 String remoteAddr = "http://127.0.0.1";
\r
335 String content = "content";
\r
336 DocumentOperationResult result = new DocumentOperationResult();
\r
337 result.setResultCode(302);
\r
338 result.setError(new ErrorResult("type-1", "reason-1"));
\r
339 result.setFailureCause("test-failure");
\r
340 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
341 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
342 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
343 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
344 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
345 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
346 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
347 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
349 Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
\r
350 Mockito.anyBoolean())).thenReturn(result);
\r
351 ResponseEntity<String> response =
\r
352 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
353 Assert.assertNotNull(response);
\r
354 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
357 @SuppressWarnings("unchecked")
\r
359 public void testProcessDelete_RequestThrowsException() throws Exception {
\r
360 String transactionId = "transactionId-1";
\r
361 String remoteAddr = "http://127.0.0.1";
\r
362 String content = "content";
\r
363 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
364 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
365 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
366 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
367 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
368 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
369 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
370 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
371 .thenThrow(IllegalArgumentException.class);
\r
372 ResponseEntity<String> response =
\r
373 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
374 Assert.assertNotNull(response);
\r
375 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
379 public void testProcessDelete_RequestInvalid() throws Exception {
\r
380 String transactionId = "transactionId-1";
\r
381 String remoteAddr = "http://127.0.0.1";
\r
382 String content = "content";
\r
383 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
384 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
385 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
386 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
387 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
388 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
389 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
390 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
391 .thenReturn(false);
\r
392 ResponseEntity<String> response =
\r
393 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
394 Assert.assertNotNull(response);
\r
395 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
400 public void testProcessDelete_ResultInvalid() throws Exception {
\r
401 String transactionId = "transactionId-1";
\r
402 String remoteAddr = "http://127.0.0.1";
\r
403 String content = "content";
\r
404 DocumentOperationResult result = new DocumentOperationResult();
\r
405 result.setResultCode(302);
\r
406 result.setError(new ErrorResult("type-1", "reason-1"));
\r
407 result.setFailureCause("test-failure");
\r
408 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
409 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
410 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
411 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
412 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
413 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
414 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
415 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
417 Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))
\r
418 .thenReturn(result);
\r
419 ResponseEntity<String> response =
\r
420 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
421 Assert.assertNotNull(response);
\r
422 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
425 @SuppressWarnings("unchecked")
\r
427 public void testProcessGet_RequestThrowsException() throws Exception {
\r
428 String transactionId = "transactionId-1";
\r
429 String remoteAddr = "http://127.0.0.1";
\r
430 String content = "content";
\r
431 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
432 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
433 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
434 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
435 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
436 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
437 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
438 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
439 .thenThrow(IllegalArgumentException.class);
\r
440 ResponseEntity<String> response =
\r
441 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
442 Assert.assertNotNull(response);
\r
443 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
447 public void testProcessGet_RequestInvalid() throws Exception {
\r
448 String transactionId = "transactionId-1";
\r
449 String remoteAddr = "http://127.0.0.1";
\r
450 String content = "content";
\r
451 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
452 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
453 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
454 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
455 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
456 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
457 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
458 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
459 .thenReturn(false);
\r
460 ResponseEntity<String> response =
\r
461 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
462 Assert.assertNotNull(response);
\r
463 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
467 public void testProcessGet_ResultInvalid() throws Exception {
\r
468 String transactionId = "transactionId-1";
\r
469 String remoteAddr = "http://127.0.0.1";
\r
470 String content = "content";
\r
471 DocumentOperationResult result = new DocumentOperationResult();
\r
472 result.setResultCode(302);
\r
473 result.setError(new ErrorResult("type-1", "reason-1"));
\r
474 result.setFailureCause("test-failure");
\r
475 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
476 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
477 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
478 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
479 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
480 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
481 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
482 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
484 Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))
\r
485 .thenReturn(result);
\r
486 ResponseEntity<String> response =
\r
487 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
488 Assert.assertNotNull(response);
\r
489 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
493 public void testQueryWithGetWithPayload_NullContent() {
\r
494 String transactionId = "transactionId-1";
\r
495 String remoteAddr = "http://127.0.0.1";
\r
496 String content = null;
\r
497 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
498 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
499 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
500 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
501 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
502 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
503 ResponseEntity<String> response =
\r
504 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
505 Assert.assertNotNull(response);
\r
506 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
509 @SuppressWarnings("unchecked")
\r
511 public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception {
\r
512 String transactionId = "transactionId-1";
\r
513 String remoteAddr = "http://127.0.0.1";
\r
514 String content = "content";
\r
515 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
516 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
517 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
518 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
519 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
520 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
521 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
522 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
523 .thenThrow(IllegalArgumentException.class);
\r
524 ResponseEntity<String> response =
\r
525 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
526 Assert.assertNotNull(response);
\r
527 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
531 public void testQueryWithGetWithPayload_RequestInvalid() throws Exception {
\r
532 String transactionId = "transactionId-1";
\r
533 String remoteAddr = "http://127.0.0.1";
\r
534 String content = "content";
\r
535 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
536 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
537 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
538 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
539 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
540 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
541 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
542 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
543 .thenReturn(false);
\r
544 ResponseEntity<String> response =
\r
545 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
546 Assert.assertNotNull(response);
\r
547 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
551 public void testCreateProcessIndex_IndexApi_RequestInvalid() throws Exception {
\r
552 String transactionId = "transactionId-1";
\r
553 String remoteAddr = "http://127.0.0.1";
\r
554 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
555 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
556 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
557 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
558 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
559 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
560 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
561 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
562 .thenReturn(false);
\r
563 ResponseEntity<String> response =
\r
564 indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);
\r
565 Assert.assertNotNull(response);
\r
566 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
569 @SuppressWarnings("unchecked")
\r
571 public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception {
\r
572 String transactionId = "transactionId-1";
\r
573 String remoteAddr = "http://127.0.0.1";
\r
574 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
575 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
576 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
577 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
578 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
579 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
580 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
581 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
582 .thenThrow(IllegalArgumentException.class);
\r
583 ResponseEntity<String> response =
\r
584 indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);
\r
585 Assert.assertNotNull(response);
\r
586 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
590 public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception {
\r
591 String transactionId = "transactionId-1";
\r
592 String remoteAddr = "http://127.0.0.1";
\r
593 String documentSchema = null;
\r
594 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
595 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
596 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
597 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
598 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
599 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
600 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
601 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
603 ResponseEntity<String> response =
\r
604 indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore);
\r
605 Assert.assertNotNull(response);
\r
606 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r
610 public void testProcessDelete_IndexApi_RequestInvalid() throws Exception {
\r
611 String transactionId = "transactionId-1";
\r
612 String remoteAddr = "http://127.0.0.1";
\r
613 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
614 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
615 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
616 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
617 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
618 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
619 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
620 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
621 .thenReturn(false);
\r
622 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
623 Assert.assertNotNull(response);
\r
624 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
627 @SuppressWarnings("unchecked")
\r
629 public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception {
\r
630 String transactionId = "transactionId-1";
\r
631 String remoteAddr = "http://127.0.0.1";
\r
632 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
633 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
634 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
635 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
636 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
637 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
638 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
639 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
640 .thenThrow(IllegalArgumentException.class);
\r
641 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
642 Assert.assertNotNull(response);
\r
643 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
646 @SuppressWarnings("unchecked")
\r
648 public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception {
\r
649 String transactionId = "transactionId-1";
\r
650 String remoteAddr = "http://127.0.0.1";
\r
651 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
652 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
653 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
654 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
655 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
656 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
657 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
658 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
660 Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class);
\r
661 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
662 Assert.assertNotNull(response);
\r
663 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r
667 public void testUserAuthorization() throws Exception {
\r
668 String transactionId = "transactionId-1";
\r
669 String remoteAddr = "http://127.0.0.1";
\r
670 String content = "content";
\r
671 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
672 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
673 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
674 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
675 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
676 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
677 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
678 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
679 .thenCallRealMethod();
\r
681 Mockito.doAnswer(new Answer<ElasticSearchConfig>() {
\r
682 public ElasticSearchConfig answer(InvocationOnMock invocation) {
\r
683 Properties properties = new Properties();
\r
684 return new ElasticSearchConfig(properties);
\r
686 }).when(httpController).getElasticSearchConfig();
\r
688 searchServiceApi.documentStore = httpController;
\r
690 ResponseEntity<String> response =
\r
691 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
692 Assert.assertNotNull(response);
\r
693 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
695 Mockito.doAnswer(new Answer<ElasticSearchConfig>() {
\r
696 public ElasticSearchConfig answer(InvocationOnMock invocation) {
\r
697 Properties properties = new Properties();
\r
698 properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "true");
\r
699 return new ElasticSearchConfig(properties);
\r
701 }).when(httpController).getElasticSearchConfig();
\r
704 response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
705 Assert.assertNotNull(response);
\r
706 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
708 Mockito.doAnswer(new Answer<ElasticSearchConfig>() {
\r
709 public ElasticSearchConfig answer(InvocationOnMock invocation) {
\r
710 Properties properties = new Properties();
\r
711 properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "false");
\r
712 return new ElasticSearchConfig(properties);
\r
714 }).when(httpController).getElasticSearchConfig();
\r
716 DocumentOperationResult result = new DocumentOperationResult();
\r
717 result.setResultCode(302);
\r
718 result.setError(new ErrorResult("type-1", "reason-1"));
\r
719 result.setFailureCause("test-failure");
\r
720 Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
\r
721 Mockito.anyBoolean())).thenReturn(result);
\r
722 response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
723 Assert.assertNotNull(response);
\r
724 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r