SearchServiceImpl implements SearchService { @SuppressWarnings("unchecked") public List<String> getDefaultFacetFields() throws RestException { Optional<AlertsUIUserSettings> alertUserSettings = alertsUIService.getAlertsUIUserSettings(); if (!alertUserSettings.isPresent() || alertUserSettings.get().getFacetFields() == null) { String facetFieldsProperty = environment .getProperty(SEARCH_FACET_FIELDS_SPRING_PROPERTY, String.class, ""); String sourceTypeField = ConfigurationsUtils.getFieldName(globalConfigService.get(), SENSOR_TYPE_FIELD_PROPERTY, Constants.SENSOR_TYPE.replace('.', ':')); List<String> facetFields = new ArrayList<>(); facetFields.add(sourceTypeField); if (facetFieldsProperty != null) { facetFields.addAll(Arrays.asList(facetFieldsProperty.split(","))); } return facetFields; } else { return alertUserSettings.get().getFacetFields(); } } @Autowired  SearchServiceImpl(IndexDao dao,
      Environment environment,
      SensorIndexingConfigService sensorIndexingConfigService,
      GlobalConfigService globalConfigService,
      AlertsUIService alertsUIService); @Override SearchResponse search(SearchRequest searchRequest); @Override GroupResponse group(GroupRequest groupRequest); @Override Optional<Map<String, Object>> getLatest(GetRequest request); @Override Map<String, FieldType> getColumnMetadata(List<String> indices); @SuppressWarnings("unchecked") List<String> getDefaultFacetFields();  }
@Test public void testGetDefaultFacetFieldsGlobalConfig() throws RestException { when(environment.getProperty(SEARCH_FACET_FIELDS_SPRING_PROPERTY, String.class, "")) .thenReturn("ip_src_addr"); Map<String, Object> globalConfig = new HashMap<>(); globalConfig.put(SENSOR_TYPE_FIELD_PROPERTY, "source.type"); when(globalConfigService.get()).thenReturn(globalConfig); when(alertsUIService.getAlertsUIUserSettings()).thenReturn(Optional.empty()); List<String> defaultFields = searchService.getDefaultFacetFields(); List<String> expectedFields = new ArrayList<>(); expectedFields.add("source.type"); expectedFields.add("ip_src_addr"); assertEquals(expectedFields, defaultFields); }
@Test public void testGetDefaultFacetFieldsEmptyGlobalConfig() throws RestException { when(environment.getProperty(SEARCH_FACET_FIELDS_SPRING_PROPERTY, String.class, "")) .thenReturn("ip_src_addr"); Map<String, Object> globalConfig = new HashMap<>(); when(globalConfigService.get()).thenReturn(globalConfig); when(alertsUIService.getAlertsUIUserSettings()).thenReturn(Optional.empty()); List<String> defaultFields = searchService.getDefaultFacetFields(); List<String> expectedFields = new ArrayList<>(); expectedFields.add("source:type"); expectedFields.add("ip_src_addr"); assertEquals(expectedFields, defaultFields); }