Search in sources :

Example 21 with SearchIndexKey

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));
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 22 with SearchIndexKey

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));
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 23 with SearchIndexKey

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);
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndexKeys(org.finra.herd.model.api.xml.SearchIndexKeys) Test(org.junit.Test)

Example 24 with SearchIndexKey

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);
}
Also used : SearchIndexStatistics(org.finra.herd.model.api.xml.SearchIndexStatistics) HashMap(java.util.HashMap) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 25 with SearchIndexKey

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);
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Test(org.junit.Test)

Aggregations

SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)33 Test (org.junit.Test)28 SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)11 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)10 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)8 ArrayList (java.util.ArrayList)6 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 IndexSearchResult (org.finra.herd.model.api.xml.IndexSearchResult)5 IndexSearchResultKey (org.finra.herd.model.api.xml.IndexSearchResultKey)5 SearchIndexValidationCreateRequest (org.finra.herd.model.api.xml.SearchIndexValidationCreateRequest)5 TagKey (org.finra.herd.model.api.xml.TagKey)5 SearchIndexStatusEntity (org.finra.herd.model.jpa.SearchIndexStatusEntity)5 IndexSearchRequest (org.finra.herd.model.api.xml.IndexSearchRequest)4 IndexSearchResponse (org.finra.herd.model.api.xml.IndexSearchResponse)4 Timestamp (java.sql.Timestamp)3 IndexSearchFilter (org.finra.herd.model.api.xml.IndexSearchFilter)3 IndexSearchKey (org.finra.herd.model.api.xml.IndexSearchKey)3 IndexSearchResultTypeKey (org.finra.herd.model.api.xml.IndexSearchResultTypeKey)3 SearchIndexCreateRequest (org.finra.herd.model.api.xml.SearchIndexCreateRequest)3