Adding UI extensibility
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / viewandinspect / SearchServletTest.java
1 /**
2  * ============LICENSE_START=================================================== SPARKY (AAI UI
3  * service) ============================================================================ Copyright ©
4  * 2017 AT&T Intellectual Property. Copyright © 2017 Amdocs All rights reserved.
5  * ============================================================================ Licensed under the
6  * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License. ============LICENSE_END=====================================================
15  *
16  * ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.
17  */
18
19 package org.onap.aai.sparky.viewandinspect;
20
21 /*
22  * import org.openecomp.sparky.config.oxm.OxmEntityDescriptor; import
23  * org.openecomp.sparky.config.oxm.OxmModelLoader; import
24  * org.openecomp.sparky.dal.elasticsearch.SearchAdapter; import
25  * org.openecomp.sparky.dal.elasticsearch.entity.AutoSuggestDocumentEntity; import
26  * org.openecomp.sparky.dal.elasticsearch.entity.AutoSuggestDocumentEntityFields; import
27  * org.openecomp.sparky.dal.elasticsearch.entity.AutoSuggestElasticHitEntity; import
28  * org.openecomp.sparky.dal.elasticsearch.entity.AutoSuggestElasticHitsEntity; import
29  * org.openecomp.sparky.dal.elasticsearch.entity.AutoSuggestElasticSearchResponse; import
30  * org.openecomp.sparky.dal.elasticsearch.entity.BucketEntity; import
31  * org.openecomp.sparky.dal.elasticsearch.entity.ElasticHitsEntity; import
32  * org.openecomp.sparky.dal.elasticsearch.entity.ElasticSearchAggegrationResponse; import
33  * org.openecomp.sparky.dal.elasticsearch.entity.ElasticSearchAggregation; import
34  * org.openecomp.sparky.dal.elasticsearch.entity.ElasticSearchCountResponse; import
35  * org.openecomp.sparky.dal.elasticsearch.entity.PayloadEntity; import
36  * org.openecomp.sparky.dal.rest.OperationResult; import
37  * org.openecomp.sparky.dal.sas.config.SearchServiceConfig; import
38  * org.openecomp.sparky.dal.sas.entity.EntityCountResponse; import
39  * org.openecomp.sparky.dal.sas.entity.GroupByAggregationResponseEntity; import
40  * org.openecomp.sparky.dal.sas.entity.SearchAbstractionEntityBuilder; import
41  * org.openecomp.sparky.search.VnfSearchService; import
42  * org.openecomp.sparky.search.config.SuggestionConfig; import
43  * org.openecomp.sparky.search.filters.FilteredSearchHelper; import
44  * org.openecomp.sparky.search.filters.entity.UiFilterEntity; import
45  * org.openecomp.sparky.search.filters.entity.UiFilterValueEntity; import
46  * org.openecomp.sparky.search.filters.entity.UiFiltersEntity; import
47  * org.openecomp.sparky.suggestivesearch.SuggestionEntity; import
48  * org.openecomp.sparky.util.ExceptionHelper; import org.openecomp.sparky.util.HttpServletHelper;
49  * import org.openecomp.sparky.util.NodeUtils; import
50  * org.openecomp.sparky.viewandinspect.entity.QuerySearchEntity; import
51  * org.openecomp.sparky.viewandinspect.entity.SearchResponse; import org.slf4j.MDC;
52  * 
53  * import org.onap.aai.cl.mdc.MdcContext; import com.fasterxml.jackson.core.JsonProcessingException;
54  * import com.fasterxml.jackson.databind.ObjectMapper; import
55  * com.fasterxml.jackson.databind.SerializationFeature; import
56  * com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.net.MediaType;
57  * 
58  * 
59  * /** The Class SearchServletTest.
60  */
61
62 /*
63  * public class SearchServletTest {
64  * 
65  * private static final String VNF_ROUTE = "vnf"; private static final String VIEW_INSPECT_ROUTE =
66  * "viewInspect";
67  * 
68  * private HttpServletRequest commonRequest = null; private HttpServletResponse commonResponse =
69  * null; private PrintWriter printWriter = null; private StringWriter responseStringWriter = null;
70  * private SearchServiceWrapper searchWrapper = null; private SearchAdapter searchAdapter = null;
71  * private VnfSearchService vnfSearchService = null; private ObjectMapper mapper = null; private
72  * SecureRandom rand = null; private OxmModelLoader loader; private Map<String, OxmEntityDescriptor>
73  * descriptors = null; private SuggestionConfig suggestionConfig = null; private SearchServiceConfig
74  * esConfig = null;
75  * 
76  * @BeforeClass public static void initBeforeClass() throws IOException { if (null ==
77  * System.getProperty("CONFIG_HOME")) { /* Set "CONFIG_HOME" environment variable so path of filter
78  * & view schema files are correct when they're loaded during SearchServiceWrapper instantiation
79  */
80 /*
81  * String configHomePath = (new File(".").getCanonicalPath() + "/appconfig-local").replace('\\',
82  * '/'); System.setProperty("CONFIG_HOME", configHomePath); } }
83  * 
84  * /** Inits the.
85  *
86  * @throws Exception the exception
87  */
88 /*
89  * @Before public void init() throws Exception { commonRequest =
90  * HttpServletHelper.getMockHttpServletRequest(); responseStringWriter = new StringWriter();
91  * printWriter = new PrintWriter(responseStringWriter); commonResponse =
92  * HttpServletHelper.getMockHttpServletResponse(printWriter); mapper = new ObjectMapper();
93  * 
94  * // permit serialization of objects with no members
95  * mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
96  * 
97  * rand = new SecureRandom();
98  * 
99  * loader = Mockito.mock(OxmModelLoader.class); descriptors = new HashMap<String,
100  * OxmEntityDescriptor>();
101  * 
102  * esConfig = new SearchServiceConfig(); suggestionConfig = SuggestionConfig.getConfig();
103  * 
104  * // Use SearchServiceWrapper and VnfSearchService for suggestionConfig Map<String, String> svcs =
105  * new HashMap<String, String>(); svcs.put("autosuggestIndexname", "SearchServiceWrapper");
106  * svcs.put("indexName", "VnfSearchService"); suggestionConfig.setSearchIndexToSearchService(svcs);
107  * 
108  * esConfig.setIndexName("esi-localhost"); esConfig.setType("default");
109  * 
110  * searchAdapter = Mockito.mock(SearchAdapter.class); vnfSearchService =
111  * Mockito.mock(VnfSearchService.class);
112  * 
113  * initializeEntityDescriptors();
114  * 
115  * searchWrapper = new SearchServiceWrapper(); searchWrapper.setSasConfig(esConfig);
116  * searchWrapper.setSearch(searchAdapter); searchWrapper.setVnfSearch(vnfSearchService);
117  * searchWrapper.setSuggestionConfig(suggestionConfig); searchWrapper.setOxmModelLoader(loader); }
118  * 
119  * @Test public void validateAccessors() { assertNotNull("Vnf Search Service should not be null",
120  * searchWrapper.getVnfSearch()); }
121  * 
122  * @Test public void validateInitializer() {
123  * 
124  * try { assertNotNull("Oxm Model loader should not be null", searchWrapper.getOxmModelLoader());
125  * assertNotNull("SearchAbstractionConfig should not be null", searchWrapper.getSasConfig());
126  * assertNotNull("SearchAdapter should not be null", searchWrapper.getSearch()); assertNotNull(
127  * "Suggestion Config should not be null", searchWrapper.getSuggestionConfig()); assertNotNull(
128  * "VnfSearchService should not be null", searchWrapper.getVnfSearch());
129  * 
130  * searchWrapper.setOxmModelLoader(null); searchWrapper.setSasConfig(null);
131  * searchWrapper.setSearch(null); searchWrapper.setSuggestionConfig(null);
132  * searchWrapper.setVnfSearch(null);
133  * 
134  * assertNull("Oxm Model loader should be null", searchWrapper.getOxmModelLoader()); assertNull(
135  * "SearchAbstractionConfig should be null", searchWrapper.getSasConfig()); assertNull(
136  * "SearchAdapter should be null", searchWrapper.getSearch()); assertNull(
137  * "Suggestion Config should be null", searchWrapper.getSuggestionConfig()); assertNull(
138  * "VnfSearchService should be null", searchWrapper.getVnfSearch());
139  * 
140  * } catch (Exception exc) { fail("Servlet Initialization Failed with error = " + exc.getMessage());
141  * }
142  * 
143  * }
144  * 
145  * /** Test doGet() and doPost() for a non-existent end-point. A test objective would be to either
146  * return a 404 Not Found.
147  */
148 /*
149  * @Test public void validateMdcContextLoggingVariablesWhenExplicitlySet() {
150  * 
151  * final String transactionId = "1234"; final String serviceName = "AAI-UI"; final String
152  * partnerName = "SparkyApp";
153  * 
154  * HttpServletHelper.assignRequestHeader(commonRequest, "X-TransactionId", transactionId);
155  * HttpServletHelper.assignRequestHeader(commonRequest, "X-FromAppId", partnerName);
156  * 
157  * HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/");
158  * 
159  * try {
160  * 
161  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
162  */
163
164 /*
165  * OperationResult result = doEvaluationTestMDC(true, commonRequest, commonResponse);
166  * 
167  * assertEquals(transactionId,MDC.get(MdcContext.MDC_REQUEST_ID));
168  * assertEquals(serviceName,MDC.get(MdcContext.MDC_SERVICE_NAME));
169  * assertEquals(partnerName,MDC.get(MdcContext.MDC_PARTNER_NAME));
170  * 
171  * } catch (Exception exc) { exc.printStackTrace(); fail("Unexpected exception = " +
172  * exc.getLocalizedMessage()); }
173  * 
174  * }
175  * 
176  * /** Test doGet() and doPost() for a non-existent end-point. A test objective would be to either
177  * return a 404 Not Found.
178  */
179 /*
180  * @Test public void validateMdcContextLoggingVariablesWhenNotExplicitlySet() {
181  * 
182  * /*final String transactionId = "1234"; final String serviceName = "AAI-UI"; final String
183  * partnerName = "SparkyApp";
184  * 
185  * HttpServletHelper.assignRequestHeader(commonRequest, "X-TransactionId", transactionId);
186  * HttpServletHelper.assignRequestHeader(commonRequest, "X-FromAppId", serviceName);
187  */
188
189 /*
190  * HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/");
191  * 
192  * try {
193  * 
194  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
195  */
196
197 /*
198  * OperationResult result = doEvaluationTestMDC(true, commonRequest, commonResponse);
199  * 
200  * assertNotNull(MDC.get(MdcContext.MDC_REQUEST_ID));
201  * assertNotNull(MDC.get(MdcContext.MDC_SERVICE_NAME));
202  * assertNotNull(MDC.get(MdcContext.MDC_PARTNER_NAME));
203  * 
204  * } catch (Exception exc) { exc.printStackTrace(); fail("Unexpected exception = " +
205  * exc.getLocalizedMessage()); }
206  * 
207  * }
208  * 
209  * 
210  * 
211  * /** Test doGet() and doPost() for a non-existent end-point.
212  */
213 /*
214  * @Test public void validateViewAndInspectSearchError_invalidRequestUri() {
215  * 
216  * HttpServletHelper.assignRequestUri(commonRequest, "search/this/path/does/not/exist/");
217  * 
218  * try {
219  * 
220  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
221  */
222 /*
223  * OperationResult result = doEvaluation(true, commonRequest, commonResponse); assertEquals(404,
224  * result.getResultCode()); assertTrue(result.getResult().contains("Ignored request-uri"));
225  * 
226  * } catch (Exception exc) { exc.printStackTrace(); fail("Unexpected exception = " +
227  * exc.getLocalizedMessage()); }
228  * 
229  * }
230  * 
231  * /** Test doGet() and doPost() for Unified Query Search success path
232  */
233 /*
234  * @Test public void validateQuerySearch_successPath() {
235  * 
236  * try {
237  * 
238  * QuerySearchEntity searchEntity = new QuerySearchEntity(); searchEntity.setMaxResults("10");
239  * searchEntity.setQueryStr("the quick brown fox");
240  * 
241  * HttpServletHelper.assignRequestUri(commonRequest, "search/querysearch");
242  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(),
243  * NodeUtils.convertObjectToJson(searchEntity, false));
244  * 
245  * 
246  * // set search-abstraction-response that we expect to get back from real system, but stubbed
247  * through a mock // to fulfill collaborator behavior
248  * 
249  * OperationResult mockedEntitySearchResponse = new OperationResult();
250  * mockedEntitySearchResponse.setResultCode(200);
251  * mockedEntitySearchResponse.setResult(NodeUtils.convertObjectToJson(
252  * SearchAbstractionEntityBuilder.getSuccessfulEntitySearchResponse(), false));
253  * 
254  * // TODO: make parameters expect certain values to lock in invocation attempt against a specific
255  * input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString()))
256  * .thenReturn(mockedEntitySearchResponse);
257  * 
258  * List<SuggestionEntity> autoSuggestions = new ArrayList<SuggestionEntity>();
259  * 
260  * autoSuggestions.add(new SuggestionEntity("1234", "vnf", "VNFs", null)); autoSuggestions.add(new
261  * SuggestionEntity("1111", "vnf", "Created VNFs", null)); autoSuggestions.add(new
262  * SuggestionEntity("1122", "vnf", "ACTIVE VNFs", null)); autoSuggestions.add(new
263  * SuggestionEntity("2233", "vnf", "ACTIVE and Error VNFs", null)); autoSuggestions.add(new
264  * SuggestionEntity("3344", "vnf", "ACTIVE and NOT ORCHESTRATED VNFs", null));
265  * autoSuggestions.add(new SuggestionEntity("4455", "vnf", "ACTIVE and Running VNFs", null));
266  * autoSuggestions.add(new SuggestionEntity("5566", "vnf", "Activated VNFs", null));
267  * autoSuggestions.add(new SuggestionEntity("6677", "vnf", "CAPPED VNFs", null));
268  * autoSuggestions.add(new SuggestionEntity("7788", "vnf", "CAPPED and Created VNFs", null));
269  * 
270  * Mockito.when(vnfSearchService.getSuggestionsResults(Mockito.anyObject(), Mockito.anyInt()))
271  * .thenReturn(autoSuggestions);
272  * 
273  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
274  */
275 /*
276  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
277  * 
278  * 
279  * assertEquals(200, result.getResultCode());
280  * 
281  * SearchResponse searchResponse = mapper.readValue(result.getResult(), SearchResponse.class);
282  * 
283  * assertEquals(10, searchResponse.getTotalFound());
284  * 
285  * int numVnf = 0; int numViewInspect = 0;
286  * 
287  * for ( SuggestionEntity suggestion : searchResponse.getSuggestions()) {
288  * 
289  * if ( VNF_ROUTE.equals(suggestion.getRoute())) { numVnf++; } else if (
290  * VIEW_INSPECT_ROUTE.equals(suggestion.getRoute())) { numViewInspect++; } }
291  * 
292  * assertEquals(5, numVnf); assertEquals(5, numViewInspect);
293  * 
294  * //assertTrue(result.getResult().contains("Ignored request-uri"));
295  * 
296  * } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); }
297  * 
298  * }
299  * 
300  * /** Test doGet() and doPost() for Unified Query Search success path
301  */
302 /*
303  * @Test
304  * 
305  * @Ignore public void validateSummaryByEntityTypeCount_successPath() {
306  * 
307  * try {
308  * 
309  * HttpServletHelper.assignRequestUri(commonRequest, "search/summarybyentitytype/count");
310  * 
311  * Map<String,String> payloadFields = new HashMap<String,String>(); payloadFields.put("hashId",
312  * "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); payloadFields.put("groupby",
313  * "orchestration-status");
314  * 
315  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(),
316  * NodeUtils.convertObjectToJson(payloadFields, false));
317  * 
318  * /* In this test we don't want to mock the vnf search service, only it's collaborator interactions
319  * with a REST endpoint.
320  */
321 /*
322  * vnfSearchService = new VnfSearchService(); vnfSearchService.setSearch(searchAdapter);
323  * searchWrapper.setVnfSearch(vnfSearchService);
324  * 
325  * /* The first network response to mock is the one to elastic search to get the suggestion entity
326  * by hash id
327  * 
328  * http://localhost:9200/entityautosuggestindex-localhost/_search
329  * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"}}}
330  */
331 /*
332  * AutoSuggestElasticSearchResponse elasticResponse = new AutoSuggestElasticSearchResponse();
333  * 
334  * elasticResponse.setTook(1);
335  * 
336  * elasticResponse.setTimedOut(false); elasticResponse.addShard("total", "5");
337  * elasticResponse.addShard("successful", "5"); elasticResponse.addShard("failed", "0");
338  * 
339  * AutoSuggestElasticHitEntity elasticHit = new AutoSuggestElasticHitEntity();
340  * elasticHit.setIndex("entityautosuggestindex-localhost"); elasticHit.setType("default");
341  * elasticHit.setId("2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d");
342  * elasticHit.setScore("1");
343  * 
344  * AutoSuggestDocumentEntityFields suggestDocFields = new AutoSuggestDocumentEntityFields();
345  * suggestDocFields.addInput("VNFs"); suggestDocFields.addInput("generic-vnfs");
346  * suggestDocFields.setOutput("VNFs"); suggestDocFields.setPayload(new PayloadEntity());
347  * suggestDocFields.setWeight(100);
348  * 
349  * AutoSuggestDocumentEntity autoSuggestDoc = new AutoSuggestDocumentEntity();
350  * autoSuggestDoc.setFields(suggestDocFields);
351  * 
352  * elasticHit.setSource(autoSuggestDoc);
353  * 
354  * AutoSuggestElasticHitsEntity hits = new AutoSuggestElasticHitsEntity(); hits.addHit(elasticHit);
355  * 
356  * elasticResponse.setHits(hits);
357  * 
358  * 
359  * OperationResult mockedSearchResponse = new OperationResult();
360  * mockedSearchResponse.setResultCode(200);
361  * 
362  * mockedSearchResponse.setResult(NodeUtils.convertObjectToJson(elasticResponse, false));
363  * 
364  * 
365  * /* The second response is the count API dip to elastic search
366  */
367 /*
368  * ElasticSearchCountResponse countResponse = new ElasticSearchCountResponse();
369  * countResponse.setCount(3170); countResponse.addShard("total", "5");
370  * countResponse.addShard("successful", "5"); countResponse.addShard("failed", "0");
371  * 
372  * OperationResult searchResponseForCount = new OperationResult();
373  * searchResponseForCount.setResultCode(200);
374  * 
375  * searchResponseForCount.setResult(NodeUtils.convertObjectToJson(countResponse, false));
376  * 
377  * // TODO: make parameters expect certain values to lock in invocation attempt against a specific
378  * input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString()))
379  * .thenReturn(mockedSearchResponse).thenReturn(searchResponseForCount);
380  * 
381  * 
382  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
383  */
384 /*
385  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
386  * 
387  * 
388  * assertEquals(200, result.getResultCode());
389  * 
390  * // //{"shards":{"total":"5","failed":"0","successful":"5"},"count":3170}
391  * 
392  * EntityCountResponse entityCountResponse = mapper.readValue(result.getResult(),
393  * EntityCountResponse.class);
394  * 
395  * assertEquals(3170, entityCountResponse.getCount());
396  * 
397  * } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); }
398  * 
399  * }
400  * 
401  * 
402  * /** Test doGet() and doPost() for Unified Query Search success path
403  */
404 /*
405  * @Test
406  * 
407  * @Ignore public void validateSummaryByEntityType_successPath() {
408  * 
409  * try {
410  * 
411  * HttpServletHelper.assignRequestUri(commonRequest, "search/summarybyentitytype");
412  * 
413  * Map<String,String> payloadFields = new HashMap<String,String>(); payloadFields.put("hashId",
414  * "662d1b57c31df70d7ef57ec53c0ace81578ec77b6bc5de055a57c7547ec122dd"); payloadFields.put("groupby",
415  * "orchestration-status");
416  * 
417  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(),
418  * NodeUtils.convertObjectToJson(payloadFields, false));
419  * 
420  * /* In this test we don't want to mock the vnf search service, only it's collaborator interactions
421  * with a REST endpoint.
422  */
423 /*
424  * vnfSearchService = new VnfSearchService(); vnfSearchService.setSearch(searchAdapter);
425  * searchWrapper.setVnfSearch(vnfSearchService);
426  * 
427  * /* The first network response to mock is the one to elastic search to get the suggestion entity
428  * by hash id
429  * 
430  * http://localhost:9200/entityautosuggestindex-localhost/_search
431  * {"query":{"term":{"_id":"2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d"}}}
432  */
433
434 /*
435  * AutoSuggestElasticSearchResponse elasticResponse = new AutoSuggestElasticSearchResponse();
436  * 
437  * elasticResponse.setTook(1);
438  * 
439  * elasticResponse.setTimedOut(false); elasticResponse.addShard("total", "5");
440  * elasticResponse.addShard("successful", "5"); elasticResponse.addShard("failed", "0");
441  * 
442  * AutoSuggestElasticHitEntity elasticHit = new AutoSuggestElasticHitEntity();
443  * elasticHit.setIndex("entityautosuggestindex-localhost"); elasticHit.setType("default");
444  * elasticHit.setId("2172a3c25ae56e4995038ffbc1f055692bfc76c0b8ceda1205bc745a9f7a805d");
445  * elasticHit.setScore("1");
446  * 
447  * AutoSuggestDocumentEntityFields suggestDocFields = new AutoSuggestDocumentEntityFields();
448  * suggestDocFields.addInput("VNFs"); suggestDocFields.addInput("generic-vnfs");
449  * suggestDocFields.setOutput("VNFs"); suggestDocFields.setPayload(new PayloadEntity());
450  * suggestDocFields.setWeight(100);
451  * 
452  * AutoSuggestDocumentEntity autoSuggestDoc = new AutoSuggestDocumentEntity();
453  * autoSuggestDoc.setFields(suggestDocFields);
454  * 
455  * elasticHit.setSource(autoSuggestDoc);
456  * 
457  * AutoSuggestElasticHitsEntity hits = new AutoSuggestElasticHitsEntity(); hits.addHit(elasticHit);
458  * 
459  * elasticResponse.setHits(hits);
460  * 
461  * 
462  * OperationResult mockedSearchResponse = new OperationResult();
463  * mockedSearchResponse.setResultCode(200);
464  * 
465  * mockedSearchResponse.setResult(NodeUtils.convertObjectToJson(elasticResponse, false));
466  * 
467  * 
468  * /* The second response is the aggregation API dip to elastic search
469  */
470 /*
471  * ElasticSearchAggegrationResponse aggResponse = new ElasticSearchAggegrationResponse();
472  * 
473  * aggResponse.setTook(20); aggResponse.setTimedOut(false);
474  * 
475  * aggResponse.addShard("total","5"); aggResponse.addShard("successful","5");
476  * aggResponse.addShard("failed","0");
477  * 
478  * ElasticHitsEntity hitsEntity = new ElasticHitsEntity();
479  * 
480  * hitsEntity.setTotal(3170); hitsEntity.setMaxScore(0);
481  * 
482  * aggResponse.setHits(hitsEntity);
483  * 
484  * ElasticSearchAggregation defaultAggregation = new ElasticSearchAggregation();
485  * 
486  * defaultAggregation.setDocCountErrorUpperBound(0); defaultAggregation.setSumOtherDocCount(0);
487  * defaultAggregation.addBucket(new BucketEntity("created",1876)); defaultAggregation.addBucket(new
488  * BucketEntity("Created",649)); defaultAggregation.addBucket(new BucketEntity("Activated",158));
489  * defaultAggregation.addBucket(new BucketEntity("active",59)); defaultAggregation.addBucket(new
490  * BucketEntity("NOT ORCHESTRATED",42)); defaultAggregation.addBucket(new
491  * BucketEntity("Pending-Create",10)); defaultAggregation.addBucket(new BucketEntity("Running",9));
492  * defaultAggregation.addBucket(new BucketEntity("Configured",7)); defaultAggregation.addBucket(new
493  * BucketEntity("pending-create",7)); defaultAggregation.addBucket(new BucketEntity("Error",3));
494  * defaultAggregation.addBucket(new BucketEntity("planned",3)); defaultAggregation.addBucket(new
495  * BucketEntity("PLANNED",2)); defaultAggregation.addBucket(new BucketEntity("ERROR",1));
496  * defaultAggregation.addBucket(new BucketEntity("RUNNING",1)); defaultAggregation.addBucket(new
497  * BucketEntity("example-orchestration-status-val-6176",1));
498  * 
499  * aggResponse.addAggregation("default", defaultAggregation);
500  * 
501  * OperationResult searchResponseForAggregation = new OperationResult();
502  * searchResponseForAggregation.setResultCode(200);
503  * 
504  * searchResponseForAggregation.setResult(NodeUtils.convertObjectToJson(aggResponse, false));
505  * 
506  * // TODO: make parameters expect certain values to lock in invocation attempt against a specific
507  * input sequence Mockito.when(searchAdapter.doPost(anyString(), anyString(), anyString()))
508  * .thenReturn(mockedSearchResponse).thenReturn(searchResponseForAggregation);
509  * 
510  * 
511  * /* Testing the doGet() operation will hit the doPost() operation in the servlet as well
512  */
513 /*
514  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
515  * 
516  * 
517  * assertEquals(200, result.getResultCode());
518  * 
519  * // //{"shards":{"total":"5","failed":"0","successful":"5"},"count":3170}
520  * 
521  * GroupByAggregationResponseEntity groupByResponse = mapper.readValue(result.getResult(),
522  * GroupByAggregationResponseEntity.class);
523  * 
524  * assertEquals(2828, groupByResponse.getAggEntity().getTotalChartHits()); assertEquals(15,
525  * groupByResponse.getAggEntity().getBuckets().size());
526  * 
527  * } catch (Exception exc) { fail("Unexpected exception = " + exc.getLocalizedMessage()); } }
528  * 
529  * @Test public void validateHandleDiscoverSearchFilters_vnfSearchViewName() throws IOException {
530  * String requestBody = "{ \"viewName\" : \"VnfSearch\" }"; String expectedResponse =
531  * "{\"filters\":[{\"filterId\":\"1\",\"filterName\":\"Orchestration-Status\",\"displayName\":\"Orchestration Status\",\"dataType\":\"list\"},{\"filterId\":\"2\",\"filterName\":\"Prov-Status\",\"displayName\":\"Provisioning Status\",\"dataType\":\"list\"}]}"
532  * ;
533  * 
534  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilters");
535  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
536  * 
537  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
538  * 
539  * assertEquals(expectedResponse, result.getResult().trim()); }
540  * 
541  * @Test public void validateFilterAggregation_successPath() { String requestBodyFilePath =
542  * "filters/filterAggregationEndpoint_successPath_requestBody.json"; String expectedResponseFilePath
543  * = "filters/filterAggregationEndpoint_successPath_expectedResponse.json"; String
544  * operationResultFilePath = "filters/filterAggregationEndpoint_successPath_operationResult.json";
545  * 
546  * String requestBody = getResourceFileContents(requestBodyFilePath); String expectedResponse =
547  * getResourceFileContents(expectedResponseFilePath);
548  * 
549  * HttpServletHelper.assignRequestUri(commonRequest, "search/filterAggregation");
550  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
551  * 
552  * OperationResult operationResult = new OperationResult();
553  * operationResult.setResult(getResourceFileContents(operationResultFilePath));
554  * 
555  * vnfSearchService = new VnfSearchService(); vnfSearchService.setSearch(searchAdapter);
556  * searchWrapper.setVnfSearch(vnfSearchService);
557  * 
558  * Mockito.when(searchAdapter.doPost(anyString(), anyString(),
559  * anyString())).thenReturn(operationResult);
560  * 
561  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
562  * 
563  * assertEquals(expectedResponse.trim(), result.getResult().trim()); }
564  * 
565  * @Test public void validateFilterAggregation_emptyRequestFilterArray() throws IOException { String
566  * requestBodyFilePath =
567  * "filters/filterAggregationEndpoint_emptyRequestFilterArray_requestBody.json"; String
568  * expectedResponseFilePath =
569  * "filters/filterAggregationEndpoint_emptyRequestFilterArray_expectedResponse.json";
570  * 
571  * String requestBody = getResourceFileContents(requestBodyFilePath); String expectedResponse =
572  * getResourceFileContents(expectedResponseFilePath);
573  * 
574  * HttpServletHelper.assignRequestUri(commonRequest, "search/filterAggregation");
575  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
576  * 
577  * vnfSearchService = new VnfSearchService(); vnfSearchService.setSearch(searchAdapter);
578  * searchWrapper.setVnfSearch(vnfSearchService);
579  * 
580  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
581  * 
582  * assertEquals(expectedResponse.trim(), result.getResult().trim()); }
583  * 
584  * @Test public void validateFilterAggregation_emptyRequestBody() throws IOException { String
585  * expectedResponseFilePath =
586  * "filters/filterAggregationEndpoint_emptyRequestBody_expectedResponse.json";
587  * 
588  * String expectedResponse = getResourceFileContents(expectedResponseFilePath);
589  * 
590  * HttpServletHelper.assignRequestUri(commonRequest, "search/filterAggregation");
591  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), "{}");
592  * 
593  * vnfSearchService = new VnfSearchService(); vnfSearchService.setSearch(searchAdapter);
594  * searchWrapper.setVnfSearch(vnfSearchService);
595  * 
596  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
597  * 
598  * assertEquals(expectedResponse.trim(), result.getResult().trim()); }
599  * 
600  * @Test public void validateHandleDiscoverSearchFilters_diuiViewName() throws IOException { String
601  * requestBody = "{ \"viewName\" : \"dataIntegrity\" }"; String expectedResponse =
602  * "{\"filters\":[{\"filterId\":\"3\",\"filterName\":\"Severity\",\"displayName\":\"Severity\",\"dataType\":\"list\"},{\"filterId\":\"4\",\"filterName\":\"Category\",\"displayName\":\"Category\",\"dataType\":\"list\"},{\"filterId\":\"5\",\"filterName\":\"Date\",\"displayName\":\"Date\",\"dataType\":\"date\"},{\"filterId\":\"6\",\"filterName\":\"EntityType\",\"displayName\":\"Entity Type\",\"dataType\":\"list\"}]}"
603  * ;
604  * 
605  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilters");
606  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
607  * 
608  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
609  * 
610  * assertEquals(expectedResponse, result.getResult().trim()); }
611  * 
612  * @Test public void validateHandleDiscoverSearchFilterValues_validId() throws IOException { String
613  * requestBody = "{ \"filterIdList\" : [ { \"filterId\" : \"1\" } ] }"; String expectedResponse =
614  * "{\"filters\":[{\"filterId\":\"1\",\"filterName\":\"Orchestration-Status\",\"displayName\":\"Orchestration Status\",\"dataType\":\"list\",\"filterValueList\":[{\"filterValue\":\"created\",\"displayName\":\"created\"}]}]}"
615  * ;
616  * 
617  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilterValues");
618  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
619  * 
620  * FilteredSearchHelper filteredSearchHelper = Mockito.mock(FilteredSearchHelper.class);
621  * searchWrapper.setFilteredSearchHelper(filteredSearchHelper);
622  * 
623  * UiFilterValueEntity uiFilterValueEntity = new UiFilterValueEntity(null, "created", "created");
624  * 
625  * UiFilterEntity uiFilterEntity = new UiFilterEntity(); uiFilterEntity.setDataType("list");
626  * uiFilterEntity.setDisplayName("Orchestration Status"); uiFilterEntity.setFilterId("1");
627  * uiFilterEntity.setFilterName("Orchestration-Status");
628  * uiFilterEntity.addFilterValue(uiFilterValueEntity);
629  * 
630  * UiFiltersEntity uiFiltersEntity = new UiFiltersEntity();
631  * uiFiltersEntity.addFilter(uiFilterEntity);
632  * 
633  * Mockito.when(filteredSearchHelper.doFilterEnumeration(Mockito.anyList()))
634  * .thenReturn(uiFiltersEntity);
635  * 
636  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
637  * 
638  * assertEquals(expectedResponse, result.getResult().trim()); }
639  * 
640  * @Test public void validateHandleDiscoverSearchFilterValues_multipleValidIds() throws IOException
641  * { String requestBody =
642  * "{ \"filterIdList\" : [ { \"filterId\" : \"1\" }, { \"filterId\" : \"2\" } ] }"; String
643  * expectedResponse =
644  * "{\"filters\":[{\"filterId\":\"1\",\"filterName\":\"Orchestration-Status\",\"displayName\":\"Orchestration Status\",\"dataType\":\"list\",\"filterValueList\":[{\"filterValue\":\"created\",\"displayName\":\"created\"}]},{\"filterId\":\"2\",\"filterName\":\"Prov-Status\",\"displayName\":\"Provisioning Status\",\"dataType\":\"list\",\"filterValueList\":[{\"filterValue\":\"active\",\"displayName\":\"active\"}]}]}"
645  * ;
646  * 
647  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilterValues");
648  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
649  * 
650  * FilteredSearchHelper filteredSearchHelper = Mockito.mock(FilteredSearchHelper.class);
651  * searchWrapper.setFilteredSearchHelper(filteredSearchHelper);
652  * 
653  * UiFiltersEntity uiFiltersEntity = new UiFiltersEntity();
654  * 
655  * UiFilterValueEntity uiFilter1ValueEntity = new UiFilterValueEntity(null, "created", "created");
656  * UiFilterEntity uiFilterEntity1 = new UiFilterEntity(); uiFilterEntity1.setDataType("list");
657  * uiFilterEntity1.setDisplayName("Orchestration Status"); uiFilterEntity1.setFilterId("1");
658  * uiFilterEntity1.setFilterName("Orchestration-Status");
659  * uiFilterEntity1.addFilterValue(uiFilter1ValueEntity); uiFiltersEntity.addFilter(uiFilterEntity1);
660  * 
661  * UiFilterValueEntity uiFilter2ValueEntity = new UiFilterValueEntity(null, "active", "active");
662  * UiFilterEntity uiFilterEntity2 = new UiFilterEntity(); uiFilterEntity2.setDataType("list");
663  * uiFilterEntity2.setDisplayName("Provisioning Status"); uiFilterEntity2.setFilterId("2");
664  * uiFilterEntity2.setFilterName("Prov-Status");
665  * uiFilterEntity2.addFilterValue(uiFilter2ValueEntity); uiFiltersEntity.addFilter(uiFilterEntity2);
666  * 
667  * Mockito.when(filteredSearchHelper.doFilterEnumeration(Mockito.anyList()))
668  * .thenReturn(uiFiltersEntity);
669  * 
670  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
671  * 
672  * assertEquals(expectedResponse, result.getResult().trim()); }
673  * 
674  * @Test public void validateHandleDiscoverSearchFilterValues_invalidId() throws IOException {
675  * String requestBody = "{ \"filterIdList\" : [ { \"filterId\" : \"999\" } ] }"; String
676  * expectedResponse = "{\"filters\":[]}";
677  * 
678  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilterValues");
679  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
680  * 
681  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
682  * 
683  * assertEquals(expectedResponse, result.getResult().trim()); }
684  * 
685  * @Test public void validateHandleDiscoverSearchFilterValues_validIdAndInvalidId() throws
686  * IOException { String requestBody =
687  * "{ \"filterIdList\" : [ { \"filterId\" : \"1\" }, { \"filterId\" : \"999\" } ] }"; String
688  * expectedResponse =
689  * "{\"filters\":[{\"filterId\":\"1\",\"filterName\":\"Orchestration-Status\",\"displayName\":\"Orchestration Status\",\"dataType\":\"list\",\"filterValueList\":[{\"filterValue\":\"created\",\"displayName\":\"created\"}]}]}"
690  * ;
691  * 
692  * HttpServletHelper.assignRequestUri(commonRequest, "search/discoverFilterValues");
693  * HttpServletHelper.setRequestPayload(commonRequest, MediaType.JSON_UTF_8.toString(), requestBody);
694  * 
695  * FilteredSearchHelper filteredSearchHelper = Mockito.mock(FilteredSearchHelper.class);
696  * searchWrapper.setFilteredSearchHelper(filteredSearchHelper);
697  * 
698  * UiFilterValueEntity uiFilterValueEntity = new UiFilterValueEntity(null, "created", "created");
699  * 
700  * UiFilterEntity uiFilterEntity = new UiFilterEntity(); uiFilterEntity.setDataType("list");
701  * uiFilterEntity.setDisplayName("Orchestration Status"); uiFilterEntity.setFilterId("1");
702  * uiFilterEntity.setFilterName("Orchestration-Status");
703  * uiFilterEntity.addFilterValue(uiFilterValueEntity);
704  * 
705  * UiFiltersEntity uiFiltersEntity = new UiFiltersEntity();
706  * uiFiltersEntity.addFilter(uiFilterEntity);
707  * 
708  * Mockito.when(filteredSearchHelper.doFilterEnumeration(Mockito.anyList()))
709  * .thenReturn(uiFiltersEntity);
710  * 
711  * OperationResult result = doEvaluation(true, commonRequest, commonResponse);
712  * 
713  * assertEquals(expectedResponse, result.getResult().trim()); }
714  * 
715  * /** Builds the resource entity descriptor.
716  *
717  * @param entityType the entity type
718  * 
719  * @param attributeNames the attribute names
720  * 
721  * @param searchableAttributes the searchable attributes
722  * 
723  * @return the oxm entity descriptor
724  */
725 /*
726  * @SuppressWarnings("unchecked") private OxmEntityDescriptor buildResourceEntityDescriptor(String
727  * entityType, String attributeNames, String searchableAttributes) { OxmEntityDescriptor descriptor
728  * = new OxmEntityDescriptor(); descriptor.setEntityName(entityType);
729  * 
730  * if (attributeNames != null) {
731  * descriptor.setPrimaryKeyAttributeName(Arrays.asList(attributeNames.split(","))); }
732  * 
733  * if (searchableAttributes != null) {
734  * descriptor.setSearchableAttributes(Arrays.asList(searchableAttributes.split(","))); }
735  * 
736  * return descriptor; }
737  * 
738  * /** Initialize entity descriptors.
739  */
740 /*
741  * private void initializeEntityDescriptors() { descriptors.put("customer",
742  * buildResourceEntityDescriptor("customer", "service-instance-id", "f1,f2,f3")); }
743  * 
744  * /** Builds the view and inspect search request.
745  *
746  * @param maxResults the max results
747  * 
748  * @param queryStr the query str
749  * 
750  * @return the string
751  * 
752  * @throws JsonProcessingException the json processing exception
753  */
754 /*
755  * public String buildViewAndInspectSearchRequest(Integer maxResults, String queryStr) throws
756  * JsonProcessingException {
757  * 
758  * /* { "maxResults" : "10", "searchStr" : "<search bar text>" }
759  */
760 /*
761  * ObjectNode rootNode = mapper.createObjectNode();
762  * 
763  * if (maxResults != null) { rootNode.put("maxResults", maxResults); }
764  * 
765  * if (queryStr != null) { rootNode.put("queryStr", queryStr); }
766  * 
767  * return NodeUtils.convertObjectToJson(rootNode, true);
768  * 
769  * }
770  * 
771  * public String getResourceFileContents(String filePath) { StringBuilder result = new
772  * StringBuilder("");
773  * 
774  * ClassLoader classLoader = getClass().getClassLoader(); File file = new
775  * File(classLoader.getResource(filePath).getFile());
776  * 
777  * try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { String line =
778  * scanner.nextLine(); result.append(line).append("\n"); }
779  * 
780  * scanner.close();
781  * 
782  * } catch (IOException e) { e.printStackTrace(); }
783  * 
784  * return result.toString(); }
785  * 
786  * 
787  * /** Do evaluation.
788  *
789  * @param doGet the do get
790  * 
791  * @param req the req
792  * 
793  * @param res the res
794  * 
795  * @return the string
796  *//*
797    * private OperationResult doEvaluationTestMDC(boolean doGet, HttpServletRequest req,
798    * HttpServletResponse res) {
799    * 
800    * /* Test method invocation
801    */
802 /*
803  * SearchServlet searchServlet = new SearchServlet(); try { searchServlet.init(); } catch
804  * (ServletException e) { // TODO Auto-generated catch block e.printStackTrace(); }
805  * ArgumentCaptor<Integer> responseCodeCaptor = ArgumentCaptor.forClass(Integer.class);
806  * 
807  * try { if (doGet) { searchServlet.doGet(req, res); } else { searchServlet.doPost(req, res); } }
808  * catch (ServletException exc) { fail(ExceptionHelper.extractStackTraceElements(5, exc)); } catch
809  * (IOException exc) { fail(ExceptionHelper.extractStackTraceElements(5, exc)); }
810  * 
811  * responseStringWriter.flush(); Mockito.verify(commonResponse,
812  * Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture());
813  * 
814  * OperationResult result = new OperationResult();
815  * 
816  * result.setResultCode(responseCodeCaptor.getValue());
817  * result.setResult(responseStringWriter.toString());
818  * 
819  * return result;
820  * 
821  * }
822  * 
823  * /** Do evaluation.
824  *
825  * @param doGet the do get
826  * 
827  * @param req the req
828  * 
829  * @param res the res
830  * 
831  * @return the string
832  *//*
833    * private OperationResult doEvaluation(boolean doGet, HttpServletRequest req, HttpServletResponse
834    * res) {
835    * 
836    * /* Test method invocation
837    */
838 /*
839  * ArgumentCaptor<Integer> responseCodeCaptor = ArgumentCaptor.forClass(Integer.class);
840  * 
841  * try { if (doGet) { searchWrapper.doGet(req, res); } else { searchWrapper.doPost(req, res); } }
842  * catch (ServletException exc) { fail(ExceptionHelper.extractStackTraceElements(5, exc)); } catch
843  * (IOException exc) { fail(ExceptionHelper.extractStackTraceElements(5, exc)); }
844  * 
845  * responseStringWriter.flush(); Mockito.verify(commonResponse,
846  * Mockito.atLeast(1)).setStatus(responseCodeCaptor.capture());
847  * 
848  * OperationResult result = new OperationResult();
849  * 
850  * result.setResultCode(responseCodeCaptor.getValue());
851  * result.setResult(responseStringWriter.toString());
852  * 
853  * return result;
854  * 
855  * }
856  * 
857  * }
858  */