SearchIndexServiceImpl implements SearchIndexService { protected void createSearchIndexHelper(SearchIndexKey searchIndexKey, String searchIndexType) { String mapping; String settings; String alias; if (SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name().equalsIgnoreCase(searchIndexType)) { mapping = configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_MAPPINGS_JSON_V2.getKey()); settings = configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SETTINGS_JSON_V2.getKey()); alias = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class); } else if (SearchIndexTypeEntity.SearchIndexTypes.TAG.name().equalsIgnoreCase(searchIndexType)) { mapping = configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_TAG_MAPPINGS_JSON_V2.getKey()); settings = configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_TAG_SETTINGS_JSON_V2.getKey()); alias = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_INDEX_NAME, String.class); } else { throw new IllegalArgumentException(String.format("Search index type with code \"%s\" is not supported.", searchIndexType)); } indexFunctionsDao.createIndex(searchIndexKey.getSearchIndexName(), mapping, settings, alias); if (SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name().equalsIgnoreCase(searchIndexType)) { searchIndexHelperService.indexAllBusinessObjectDefinitions(searchIndexKey); } else { searchIndexHelperService.indexAllTags(searchIndexKey); } }  @Override SearchIndex createSearchIndex(SearchIndexCreateRequest request); @Override SearchIndex deleteSearchIndex(SearchIndexKey searchIndexKey); @Override SearchIndex getSearchIndex(SearchIndexKey searchIndexKey); @Override SearchIndexKeys getSearchIndexes();  }
@Test public void testCreateSearchIndexHelper() { SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME); String searchIndexType = SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(); @SuppressWarnings("unchecked") Future<Void> mockedFuture = mock(Future.class); when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class)).thenReturn(SEARCH_INDEX_ALIAS_BDEF); when(configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_MAPPINGS_JSON_V2.getKey())).thenReturn(SEARCH_INDEX_MAPPING); when(configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SETTINGS_JSON_V2.getKey())).thenReturn(SEARCH_INDEX_SETTINGS); when(searchIndexHelperService.indexAllBusinessObjectDefinitions(searchIndexKey)).thenReturn(mockedFuture); searchIndexServiceImpl.createSearchIndexHelper(searchIndexKey, searchIndexType); verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class); verify(configurationDaoHelper).getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_MAPPINGS_JSON_V2.getKey()); verify(configurationDaoHelper).getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SETTINGS_JSON_V2.getKey()); verify(indexFunctionDao).createIndex(any(), any(), any(), any()); verify(searchIndexHelperService).indexAllBusinessObjectDefinitions(searchIndexKey); verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, indexFunctionDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper); }
@Test public void testCreateSearchIndexHelperInvalidSearchIndexType() { try { searchIndexServiceImpl.createSearchIndexHelper(new SearchIndexKey(SEARCH_INDEX_NAME), SEARCH_INDEX_TYPE); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Search index type with code \"%s\" is not supported.", SEARCH_INDEX_TYPE), e.getMessage()); } verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper); }