use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexHelperServiceTest method testIndexAllBusinessObjectDefinitions.
@Test
public void testIndexAllBusinessObjectDefinitions() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create a list of business object definition entities.
final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Collections.unmodifiableList(Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes2())));
// Get a chunk size.
int chunkSize = SearchIndexHelperServiceImpl.BUSINESS_OBJECT_DEFINITIONS_CHUNK_SIZE;
// Mock the external calls. Please note that we mock index size is set to be equal to the business object definition entity list size.
when(businessObjectDefinitionDao.getAllBusinessObjectDefinitions(0, chunkSize)).thenReturn(businessObjectDefinitionEntities);
when(businessObjectDefinitionDao.getAllBusinessObjectDefinitions(chunkSize, chunkSize)).thenReturn(new ArrayList<>());
when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(2L);
// Index all business object definitions defined in the system.
Future<Void> response = searchIndexHelperService.indexAllBusinessObjectDefinitions(searchIndexKey, SEARCH_INDEX_DOCUMENT_TYPE);
// Verify the external calls.
verify(businessObjectDefinitionDao).getAllBusinessObjectDefinitions(0, chunkSize);
verify(businessObjectDefinitionDao).getAllBusinessObjectDefinitions(chunkSize, chunkSize);
verify(businessObjectDefinitionHelper).executeFunctionForBusinessObjectDefinitionEntities(eq(SEARCH_INDEX_NAME), eq(SEARCH_INDEX_DOCUMENT_TYPE), eq(businessObjectDefinitionEntities), any());
verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any());
verify(searchIndexDaoHelper).updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name());
verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, searchIndexDaoHelper, tagDao, tagHelper);
// Validate the results.
assertNotNull(response);
assertThat(response, instanceOf(Future.class));
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexHelperServiceTest method testIndexAllTags.
@Test
public void testIndexAllTags() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create a list of tag entities.
final List<TagEntity> tagEntities = Collections.unmodifiableList(Arrays.asList(tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE_2, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2)));
// Mock the external calls. Please note that we mock index size is set to be equal to the tag entity list size.
when(tagDao.getTags()).thenReturn(tagEntities);
doNothing().when(indexFunctionsDao).createIndexDocument(any(), any(), any(), any());
when(indexFunctionsDao.getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(2L);
// Index all tags defined in the system.
Future<Void> response = searchIndexHelperService.indexAllTags(searchIndexKey, SEARCH_INDEX_DOCUMENT_TYPE);
// Verify the external calls.
verify(tagDao).getTags();
// verify(indexFunctionsDao).createIndexDocument(any(), any(), any(), any());
verify(tagHelper).executeFunctionForTagEntities(eq(SEARCH_INDEX_NAME), eq(SEARCH_INDEX_DOCUMENT_TYPE), eq(tagEntities), any());
verify(indexFunctionsDao).getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE);
verify(searchIndexDaoHelper).updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name());
verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, searchIndexDaoHelper, tagDao, tagHelper);
// Validate the results.
assertNotNull(response);
assertThat(response, instanceOf(Future.class));
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexServiceTest method testGetSearchIndexes.
@Test
public void testGetSearchIndexes() {
// Create a list of search index keys.
List<SearchIndexKey> searchIndexKeys = Arrays.asList(new SearchIndexKey(SEARCH_INDEX_NAME), new SearchIndexKey(SEARCH_INDEX_NAME_2));
// Mock the external calls.
when(searchIndexDao.getSearchIndexes()).thenReturn(searchIndexKeys);
// Get search indexes.
SearchIndexKeys response = searchIndexService.getSearchIndexes();
// Verify the external calls.
verify(searchIndexDao).getSearchIndexes();
verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
// Validate the returned object.
assertEquals(new SearchIndexKeys(searchIndexKeys), response);
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexServiceTest method testGetSearchIndex.
@Test
public void testGetSearchIndex() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create the search index entity.
SearchIndexEntity searchIndexEntity = createTestSearchIndexEntity();
// Mock some of the external call responses.
@SuppressWarnings("unchecked") DocsStats mockedDocsStats = mock(DocsStats.class);
java.util.Map<String, String> map = new HashMap<>();
map.put(IndexMetaData.SETTING_INDEX_UUID, SEARCH_INDEX_STATISTICS_INDEX_UUID);
map.put(IndexMetaData.SETTING_CREATION_DATE, Long.toString(SEARCH_INDEX_STATISTICS_CREATION_DATE.toGregorianCalendar().getTimeInMillis()));
Settings settings = Settings.builder().put(map).build();
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
when(indexFunctionsDao.getIndexSettings(SEARCH_INDEX_NAME)).thenReturn(settings);
when(indexFunctionsDao.getIndexStats(SEARCH_INDEX_NAME)).thenReturn(mockedDocsStats);
when(mockedDocsStats.getCount()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS);
when(mockedDocsStats.getDeleted()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("doc");
when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(0l);
// Get a search index.
SearchIndex response = searchIndexService.getSearchIndex(searchIndexKey);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
verify(mockedDocsStats).getCount();
verify(mockedDocsStats).getDeleted();
verify(indexFunctionsDao).getIndexSettings(SEARCH_INDEX_NAME);
verify(indexFunctionsDao).getIndexStats(SEARCH_INDEX_NAME);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any());
verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
// response.getSearchIndexStatistics().setIndexCreationDate(SEARCH_INDEX_STATISTICS_CREATION_DATE);
// Validate the returned object.
assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE_BDEF, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, new SearchIndexStatistics(SEARCH_INDEX_STATISTICS_CREATION_DATE, SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS, SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS, SEARCH_INDEX_STATISTICS_INDEX_UUID, 0l), USER_ID, CREATED_ON, UPDATED_ON), response);
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexServiceTest method testDeleteSearchIndex.
@Test
public void testDeleteSearchIndex() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create the search index entity.
SearchIndexEntity searchIndexEntity = createTestSearchIndexEntity();
// Mock the external calls.
when(indexFunctionsDao.isIndexExists(any())).thenReturn(true);
when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
// Delete a search index.
SearchIndex response = searchIndexService.deleteSearchIndex(searchIndexKey);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
verify(indexFunctionsDao).isIndexExists(any());
verify(indexFunctionsDao).deleteIndex(any());
verify(searchIndexDao).delete(searchIndexEntity);
verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
// Validate the returned object.
assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE_BDEF, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON), response);
}
Aggregations