2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 package org.onap.aai.sparky.search;
\r
25 import java.io.File;
\r
26 import java.io.IOException;
\r
27 import java.io.PrintWriter;
\r
28 import java.lang.reflect.Field;
\r
29 import java.lang.reflect.Modifier;
\r
31 import javax.servlet.http.HttpServletResponse;
\r
33 import org.junit.Before;
\r
34 import org.junit.Test;
\r
35 import org.mockito.Mockito;
\r
36 import org.onap.aai.sparky.dal.elasticsearch.SearchAdapter;
\r
37 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
\r
38 import org.onap.aai.sparky.dal.rest.OperationResult;
\r
39 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
\r
40 import org.onap.aai.sparky.viewandinspect.entity.QuerySearchEntity;
\r
42 public class VnfSearchServiceTest {
\r
44 VnfSearchService searchService;
\r
47 public void init() throws NoSuchFieldException, SecurityException, IllegalArgumentException,
\r
48 IllegalAccessException, IOException {
\r
49 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
\r
50 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION =
\r
51 System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/";
\r
52 ElasticSearchConfig.setConfig(null);
\r
54 searchService = new VnfSearchService();
\r
58 public void testSetZeroCountResponse() throws IOException {
\r
59 HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
\r
60 Mockito.doNothing().when(response).setStatus(1);
\r
61 Mockito.doNothing().when(response).setContentType(Mockito.anyString());
\r
62 PrintWriter writer = Mockito.mock(PrintWriter.class);
\r
63 Mockito.doNothing().when(writer).println(Mockito.anyString());
\r
64 Mockito.doNothing().when(writer).close();
\r
65 Mockito.when(response.getWriter()).thenReturn(writer);
\r
66 searchService.setZeroCountResponse(response);
\r
70 public void testSetEmptyAggResponse() throws IOException {
\r
71 HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
\r
72 Mockito.doNothing().when(response).setStatus(1);
\r
73 Mockito.doNothing().when(response).setContentType(Mockito.anyString());
\r
74 PrintWriter writer = Mockito.mock(PrintWriter.class);
\r
75 Mockito.doNothing().when(writer).println(Mockito.anyString());
\r
76 Mockito.doNothing().when(writer).close();
\r
77 Mockito.when(response.getWriter()).thenReturn(writer);
\r
78 searchService.setEmptyAggResponse(response);
\r
82 static void setFinalStatic() throws NoSuchFieldException, SecurityException,
\r
83 IllegalArgumentException, IllegalAccessException {
\r
84 Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");
\r
85 configField.setAccessible(true);
\r
87 Field modifiersField = Field.class.getDeclaredField("modifiers");
\r
88 modifiersField.setAccessible(true);
\r
89 modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL);
\r
91 configField.set(null,
\r
92 System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/elasticsearch.properties");
\r