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.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity;
\r
37 import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface;
\r
38 import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException;
\r
39 import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult;
\r
40 import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult;
\r
41 import org.onap.aai.sa.searchdbabstraction.entity.SearchHits;
\r
42 import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult;
\r
43 import org.springframework.http.HttpHeaders;
\r
44 import org.springframework.http.HttpStatus;
\r
45 import org.springframework.http.ResponseEntity;
\r
48 public class DocumentTest {
\r
51 SearchServiceApi searchServiceApi;
\r
54 HttpServletRequest request;
\r
57 HttpHeaders headers;
\r
60 HttpServletResponse httpResponse;
\r
63 DocumentStoreInterface documentStore;
\r
66 MultivaluedMap<String, String> multivaluedMap;
\r
71 DocumentApi documentApi;
\r
74 public void setUp() {
\r
75 MockitoAnnotations.initMocks(this);
\r
76 documentApi = new DocumentApi(searchServiceApi);
\r
80 public void testDocumentClass_AllMethods() throws JsonProcessingException {
\r
81 Document doc = new Document();
\r
82 doc.setField("name-1", "value-1");
\r
83 Assert.assertTrue(doc.getFields().size() == 1);
\r
84 Assert.assertTrue(doc.toJson().contains("value-1"));
\r
85 Assert.assertNotNull(doc.toString());
\r
86 Assert.assertTrue(doc.toString().contains("name-1"));
\r
90 public void testProcessPost_NullContent() {
\r
91 String transactionId = "transactionId-1";
\r
92 String remoteAddr = "http://127.0.0.1";
\r
93 String content = null;
\r
94 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
95 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
96 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
97 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
98 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
99 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
100 ResponseEntity<String> response =
\r
101 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
102 Assert.assertNotNull(response);
\r
103 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
107 public void testProcessPost_NotNullContent() throws Exception {
\r
108 String transactionId = "transactionId-1";
\r
109 String remoteAddr = "http://127.0.0.1";
\r
110 String content = "content";
\r
111 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
112 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
113 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
114 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
115 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
116 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
117 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
118 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
119 .thenThrow(IllegalArgumentException.class);
\r
120 ResponseEntity response =
\r
121 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
122 Assert.assertNotNull(response);
\r
123 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
128 public void testProcessPost_ValidRequest() throws Exception {
\r
129 String transactionId = "transactionId-1";
\r
130 String remoteAddr = "http://127.0.0.1";
\r
131 String content = "content";
\r
132 DocumentOperationResult result = new DocumentOperationResult();
\r
133 result.setResultCode(150);
\r
134 result.setError(new ErrorResult("type-1", "reason-1"));
\r
135 result.setFailureCause("test-failure");
\r
136 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
137 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
138 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
139 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
140 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
141 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
142 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
143 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
145 Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
\r
146 Mockito.anyBoolean())).thenReturn(result);
\r
147 Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString());
\r
148 ResponseEntity<String> response =
\r
149 documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
\r
150 Assert.assertNotNull(response);
\r
151 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r
156 public void testProcessSearchWithGet_Created() throws Exception {
\r
157 String transactionId = "transactionId-1";
\r
158 String remoteAddr = "http://127.0.0.1";
\r
159 String content = "content";
\r
160 SearchOperationResult result = new SearchOperationResult();
\r
161 result.setResultCode(201);
\r
162 SearchHits hits = new SearchHits();
\r
163 hits.setTotalHits("2");
\r
164 result.setSearchResult(hits);
\r
165 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
166 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
167 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
168 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
169 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
170 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
171 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
172 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
174 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
175 ResponseEntity<String> response =
\r
176 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
177 Assert.assertNotNull(response);
\r
178 Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue());
\r
184 public void testProcessSearchWithGet_ValidateThrowsException() throws Exception {
\r
185 String transactionId = "transactionId-1";
\r
186 String remoteAddr = "http://127.0.0.1";
\r
187 String content = "content";
\r
188 SearchOperationResult result = new SearchOperationResult();
\r
189 result.setResultCode(201);
\r
190 SearchHits hits = new SearchHits();
\r
191 hits.setTotalHits("2");
\r
192 result.setSearchResult(hits);
\r
193 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
194 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
195 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
196 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
197 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
198 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
199 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
200 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
201 .thenThrow(IllegalArgumentException.class);
\r
202 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
203 ResponseEntity<String> response =
\r
204 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
205 Assert.assertNotNull(response);
\r
206 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
212 public void testProcessSearchWithGet_ValidateIsFalse() throws Exception {
\r
213 String transactionId = "transactionId-1";
\r
214 String remoteAddr = "http://127.0.0.1";
\r
215 String content = "content";
\r
216 SearchOperationResult result = new SearchOperationResult();
\r
217 result.setResultCode(201);
\r
218 SearchHits hits = new SearchHits();
\r
219 hits.setTotalHits("2");
\r
220 result.setSearchResult(hits);
\r
221 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);
\r
222 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
223 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
224 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
225 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
226 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
227 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
228 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
229 .thenReturn(false);
\r
230 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
231 ResponseEntity<String> response =
\r
232 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
233 Assert.assertNotNull(response);
\r
234 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
239 public void testProcessSearchWithGet_InvalidResult() throws Exception {
\r
240 String transactionId = "transactionId-1";
\r
241 String remoteAddr = "http://127.0.0.1";
\r
242 String content = "content";
\r
243 SearchOperationResult result = new SearchOperationResult();
\r
244 result.setResultCode(302);
\r
245 SearchHits hits = new SearchHits();
\r
246 hits.setTotalHits("2");
\r
247 result.setSearchResult(hits);
\r
248 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
249 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
250 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
251 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
252 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
253 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
254 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
255 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
257 Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);
\r
258 ResponseEntity<String> response =
\r
259 documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);
\r
260 Assert.assertNotNull(response);
\r
261 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
266 public void testProcessPut_NullContent() {
\r
267 String transactionId = "transactionId-1";
\r
268 String remoteAddr = "http://127.0.0.1";
\r
269 String content = null;
\r
270 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
271 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
272 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
273 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
274 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
275 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
276 ResponseEntity<String> response =
\r
277 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
278 Assert.assertNotNull(response);
\r
279 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
283 public void testProcessPut_RequestThrowsException() throws Exception {
\r
284 String transactionId = "transactionId-1";
\r
285 String remoteAddr = "http://127.0.0.1";
\r
286 String content = "content";
\r
287 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
288 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
289 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
290 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
291 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
292 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
293 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
294 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
295 .thenThrow(IllegalArgumentException.class);
\r
296 ResponseEntity<String> response =
\r
297 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
298 Assert.assertNotNull(response);
\r
299 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
303 public void testProcessPut_RequestInvalid() throws Exception {
\r
304 String transactionId = "transactionId-1";
\r
305 String remoteAddr = "http://127.0.0.1";
\r
306 String content = "content";
\r
307 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
308 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
309 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
310 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
311 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
312 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
313 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
314 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
315 .thenReturn(false);
\r
316 ResponseEntity<String> response =
\r
317 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
318 Assert.assertNotNull(response);
\r
319 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
324 public void testProcessPut_ResultInvalid() throws Exception {
\r
325 String transactionId = "transactionId-1";
\r
326 String remoteAddr = "http://127.0.0.1";
\r
327 String content = "content";
\r
328 DocumentOperationResult result = new DocumentOperationResult();
\r
329 result.setResultCode(302);
\r
330 result.setError(new ErrorResult("type-1", "reason-1"));
\r
331 result.setFailureCause("test-failure");
\r
332 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
333 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
334 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
335 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
336 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
337 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
338 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
339 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
341 Mockito.when(documentStore.updateDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
\r
342 Mockito.anyBoolean())).thenReturn(result);
\r
343 ResponseEntity<String> response =
\r
344 documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
345 Assert.assertNotNull(response);
\r
346 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
350 public void testProcessDelete_RequestThrowsException() throws Exception {
\r
351 String transactionId = "transactionId-1";
\r
352 String remoteAddr = "http://127.0.0.1";
\r
353 String content = "content";
\r
354 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
355 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
356 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
357 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
358 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
359 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
360 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
361 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
362 .thenThrow(IllegalArgumentException.class);
\r
363 ResponseEntity<String> response =
\r
364 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
365 Assert.assertNotNull(response);
\r
366 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
370 public void testProcessDelete_RequestInvalid() throws Exception {
\r
371 String transactionId = "transactionId-1";
\r
372 String remoteAddr = "http://127.0.0.1";
\r
373 String content = "content";
\r
374 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
375 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
376 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
377 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
378 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
379 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
380 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
381 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
382 .thenReturn(false);
\r
383 ResponseEntity<String> response =
\r
384 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
385 Assert.assertNotNull(response);
\r
386 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
391 public void testProcessDelete_ResultInvalid() throws Exception {
\r
392 String transactionId = "transactionId-1";
\r
393 String remoteAddr = "http://127.0.0.1";
\r
394 String content = "content";
\r
395 DocumentOperationResult result = new DocumentOperationResult();
\r
396 result.setResultCode(302);
\r
397 result.setError(new ErrorResult("type-1", "reason-1"));
\r
398 result.setFailureCause("test-failure");
\r
399 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
400 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
401 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
402 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
403 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
404 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
405 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
406 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
408 Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))
\r
409 .thenReturn(result);
\r
410 ResponseEntity<String> response =
\r
411 documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
412 Assert.assertNotNull(response);
\r
413 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
417 public void testProcessGet_RequestThrowsException() throws Exception {
\r
418 String transactionId = "transactionId-1";
\r
419 String remoteAddr = "http://127.0.0.1";
\r
420 String content = "content";
\r
421 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
422 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
423 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
424 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
425 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
426 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
427 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
428 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
429 .thenThrow(IllegalArgumentException.class);
\r
430 ResponseEntity<String> response =
\r
431 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
432 Assert.assertNotNull(response);
\r
433 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
437 public void testProcessGet_RequestInvalid() throws Exception {
\r
438 String transactionId = "transactionId-1";
\r
439 String remoteAddr = "http://127.0.0.1";
\r
440 String content = "content";
\r
441 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
442 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
443 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
444 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
445 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
446 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
447 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
448 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
449 .thenReturn(false);
\r
450 ResponseEntity<String> response =
\r
451 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
452 Assert.assertNotNull(response);
\r
453 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
457 public void testProcessGet_ResultInvalid() throws Exception {
\r
458 String transactionId = "transactionId-1";
\r
459 String remoteAddr = "http://127.0.0.1";
\r
460 String content = "content";
\r
461 DocumentOperationResult result = new DocumentOperationResult();
\r
462 result.setResultCode(302);
\r
463 result.setError(new ErrorResult("type-1", "reason-1"));
\r
464 result.setFailureCause("test-failure");
\r
465 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
466 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
467 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
468 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
469 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
470 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
471 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
472 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
474 Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))
\r
475 .thenReturn(result);
\r
476 ResponseEntity<String> response =
\r
477 documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);
\r
478 Assert.assertNotNull(response);
\r
479 Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
\r
483 public void testQueryWithGetWithPayload_NullContent() {
\r
484 String transactionId = "transactionId-1";
\r
485 String remoteAddr = "http://127.0.0.1";
\r
486 String content = null;
\r
487 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
488 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
489 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
490 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
491 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
492 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
493 ResponseEntity<String> response =
\r
494 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
495 Assert.assertNotNull(response);
\r
496 Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
\r
500 public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception {
\r
501 String transactionId = "transactionId-1";
\r
502 String remoteAddr = "http://127.0.0.1";
\r
503 String content = "content";
\r
504 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
505 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
506 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
507 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
508 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
509 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
510 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
511 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
512 .thenThrow(IllegalArgumentException.class);
\r
513 ResponseEntity<String> response =
\r
514 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
515 Assert.assertNotNull(response);
\r
516 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
520 public void testQueryWithGetWithPayload_RequestInvalid() throws Exception {
\r
521 String transactionId = "transactionId-1";
\r
522 String remoteAddr = "http://127.0.0.1";
\r
523 String content = "content";
\r
524 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
525 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
526 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
527 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
528 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
529 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
530 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
531 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
532 .thenReturn(false);
\r
533 ResponseEntity<String> response =
\r
534 documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);
\r
535 Assert.assertNotNull(response);
\r
536 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
540 public void testCreateProcessIndex_IndexApi_RequestInvalid() throws Exception {
\r
541 String transactionId = "transactionId-1";
\r
542 String remoteAddr = "http://127.0.0.1";
\r
543 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
544 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
545 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
546 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
547 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
548 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
549 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
550 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
551 .thenReturn(false);
\r
552 ResponseEntity<String> response =
\r
553 indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);
\r
554 Assert.assertNotNull(response);
\r
555 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
559 public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception {
\r
560 String transactionId = "transactionId-1";
\r
561 String remoteAddr = "http://127.0.0.1";
\r
562 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
563 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
564 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
565 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
566 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
567 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
568 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
569 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
570 .thenThrow(IllegalArgumentException.class);
\r
571 ResponseEntity<String> response =
\r
572 indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);
\r
573 Assert.assertNotNull(response);
\r
574 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
578 public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception {
\r
579 String transactionId = "transactionId-1";
\r
580 String remoteAddr = "http://127.0.0.1";
\r
581 String documentSchema = null;
\r
582 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
583 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
584 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
585 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
586 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
587 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
588 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
589 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
591 ResponseEntity<String> response =
\r
592 indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore);
\r
593 Assert.assertNotNull(response);
\r
594 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r
598 public void testProcessDelete_IndexApi_RequestInvalid() throws Exception {
\r
599 String transactionId = "transactionId-1";
\r
600 String remoteAddr = "http://127.0.0.1";
\r
601 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
602 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
603 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
604 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
605 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
606 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
607 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
608 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
609 .thenReturn(false);
\r
610 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
611 Assert.assertNotNull(response);
\r
612 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
616 public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception {
\r
617 String transactionId = "transactionId-1";
\r
618 String remoteAddr = "http://127.0.0.1";
\r
619 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
620 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
621 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
622 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
623 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
624 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
625 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
626 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
627 .thenThrow(IllegalArgumentException.class);
\r
628 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
629 Assert.assertNotNull(response);
\r
630 Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
\r
634 public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception {
\r
635 String transactionId = "transactionId-1";
\r
636 String remoteAddr = "http://127.0.0.1";
\r
637 // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);;
\r
638 Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);
\r
639 Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);
\r
640 Mockito.when(request.getMethod()).thenReturn("testMethod");
\r
641 Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));
\r
642 Mockito.when(request.getRemoteHost()).thenReturn("localhost");
\r
643 Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
\r
644 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
\r
646 Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class);
\r
647 ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);
\r
648 Assert.assertNotNull(response);
\r
649 Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());
\r