use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class SearchIndexValidationServiceTest method searchIndexValidation.
private void searchIndexValidation(SearchIndexKey searchIndexKey, SearchIndexValidationCreateRequest searchIndexValidationCreateRequest, String searchIndexType) {
// Create the search index type entity
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(searchIndexType);
// Create a search index entity
SearchIndexEntity searchIndexEntity = new SearchIndexEntity();
searchIndexEntity.setName(SEARCH_INDEX_NAME);
searchIndexEntity.setType(searchIndexTypeEntity);
// validation response
boolean sizeCheck = ThreadLocalRandom.current().nextDouble() < 0.5;
boolean spotCheckPercentage = ThreadLocalRandom.current().nextDouble() < 0.5;
boolean spotCheckMostRecent = ThreadLocalRandom.current().nextDouble() < 0.5;
// Mock some of the external call responses.
@SuppressWarnings("unchecked") Future<Void> mockedFuture = mock(Future.class);
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
when(businessObjectDefinitionService.indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(new AsyncResult<>(null));
when(businessObjectDefinitionService.indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(sizeCheck);
when(businessObjectDefinitionService.indexSpotCheckPercentageValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(spotCheckPercentage);
when(businessObjectDefinitionService.indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(spotCheckMostRecent);
when(tagService.indexValidateAllTags(SEARCH_INDEX_NAME)).thenReturn(new AsyncResult<>(null));
when(tagService.indexSizeCheckValidationTags(SEARCH_INDEX_NAME)).thenReturn(sizeCheck);
when(tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_NAME)).thenReturn(spotCheckPercentage);
when(tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_NAME)).thenReturn(spotCheckMostRecent);
// Create a search index.
SearchIndexValidation response = searchIndexValidationService.createSearchIndexValidation(searchIndexValidationCreateRequest);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
if (searchIndexType.equals(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())) {
// verify that full validation is invoked only if specified in the request
if (searchIndexValidationCreateRequest.isPerformFullSearchIndexValidation()) {
verify(tagService, times(1)).indexValidateAllTags(SEARCH_INDEX_NAME);
} else {
verify(tagService, times(0)).indexValidateAllTags(SEARCH_INDEX_NAME);
}
verify(tagService).indexSizeCheckValidationTags(SEARCH_INDEX_NAME);
verify(tagService).indexSpotCheckPercentageValidationTags(SEARCH_INDEX_NAME);
verify(tagService).indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_NAME);
verifyNoMoreInteractions(alternateKeyHelper, searchIndexDaoHelper, tagService);
// Validate the returned object.
assertEquals(new SearchIndexValidation(searchIndexKey, response.getValidateStartTime(), sizeCheck, spotCheckPercentage, spotCheckMostRecent), response);
} else {
// verify that full validation is invoked only if specified in the request
if (searchIndexValidationCreateRequest.isPerformFullSearchIndexValidation()) {
verify(businessObjectDefinitionService, times(1)).indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME);
} else {
verify(businessObjectDefinitionService, times(0)).indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME);
}
verify(businessObjectDefinitionService).indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
verify(businessObjectDefinitionService).indexSpotCheckPercentageValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
verify(businessObjectDefinitionService).indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
verifyNoMoreInteractions(alternateKeyHelper, searchIndexDaoHelper, businessObjectDefinitionService);
// Validate the returned object.
assertEquals(new SearchIndexValidation(searchIndexKey, response.getValidateStartTime(), sizeCheck, spotCheckPercentage, spotCheckMostRecent), response);
}
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class SearchIndexTypeDaoImpl method getSearchIndexTypeByCode.
@Override
public SearchIndexTypeEntity getSearchIndexTypeByCode(String code) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<SearchIndexTypeEntity> criteria = builder.createQuery(SearchIndexTypeEntity.class);
// The criteria root is the search index type.
Root<SearchIndexTypeEntity> searchIndexTypeEntityRoot = criteria.from(SearchIndexTypeEntity.class);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate predicate = builder.equal(builder.upper(searchIndexTypeEntityRoot.get(SearchIndexTypeEntity_.code)), code.toUpperCase());
// Add all clauses to the query.
criteria.select(searchIndexTypeEntityRoot).where(predicate);
// Execute the query and return the result.
return executeSingleResultQuery(criteria, String.format("Found more than one search index type with code \"%s\".", code));
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class IndexSearchServiceTest method testIndexSearchWithMatch.
@Test
public void testIndexSearchWithMatch() {
// Create a tag key.
TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
// Create an index search request.
final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
// Create a set of fields.
final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
// Create a set of match fields.
final Set<String> match = Sets.newHashSet(MATCH_COLUMN);
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
// Create a new index search results
final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
// Create a list to contain the index search results
final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
indexSearchResults.add(indexSearchResultTag);
// Construct an index search response
final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
// Construct a search index entity
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
// Create a tag type entity.
TagTypeEntity tagTypeEntity = new TagTypeEntity();
tagTypeEntity.setCode(tagKey.getTagTypeCode());
// Create a tag entity.
TagEntity tagEntity = new TagEntity();
tagEntity.setTagCode(tagKey.getTagCode());
tagEntity.setTagType(tagTypeEntity);
// Mock the call to the index search service
when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
when(indexSearchDao.indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
// Call the method under test.
IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, match);
// Verify the external calls.
verify(tagHelper).validateTagKey(tagKey);
verify(tagDaoHelper).getTagEntity(tagKey);
verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
verify(indexSearchDao).indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(indexSearchResponse, result);
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class IndexSearchServiceTest method testIndexSearch.
@Test
public void testIndexSearch() {
// Create a tag key.
TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
// Create an index search request.
final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
// Create a set of fields.
final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
// Create a new index search results
final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
// Create a list to contain the index search results
final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
indexSearchResults.add(indexSearchResultTag);
// Construct an index search response
final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
// Construct a search index entity
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
// Create a tag type entity.
TagTypeEntity tagTypeEntity = new TagTypeEntity();
tagTypeEntity.setCode(tagKey.getTagTypeCode());
// Create a tag entity.
TagEntity tagEntity = new TagEntity();
tagEntity.setTagCode(tagKey.getTagCode());
tagEntity.setTagType(tagTypeEntity);
// Mock the call to the index search service
when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
when(indexSearchDao.indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
// Call the method under test.
IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
// Verify the external calls.
verify(tagHelper).validateTagKey(tagKey);
verify(tagDaoHelper).getTagEntity(tagKey);
verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
verify(indexSearchDao).indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(indexSearchResponse, result);
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class IndexSearchServiceTest method testIndexSearchMissingOptionalParameters.
@Test
public void testIndexSearchMissingOptionalParameters() {
// Create an index search request.
final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, NO_INDEX_SEARCH_FILTERS, NO_INDEX_SEARCH_FACET_FIELDS, NO_ENABLE_HIT_HIGHLIGHTING);
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
// Create a new index search result key and populate it with a tag key
final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
// Create a new index search results
final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
// Create a list to contain the index search results
final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
indexSearchResults.add(indexSearchResultTag);
// Construct an index search response
final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
// Construct a search index entity
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
// Mock the call to the index search service
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
when(indexSearchDao.indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
// Call the method under test.
IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH);
// Verify the external calls.
verify(indexSearchDao).indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(indexSearchResponse, result);
}
Aggregations