Search in sources :

Example 71 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsWithMultipleTagsDoNotIncludeTagHierarchy.

@Test
public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsDoNotIncludeTagHierarchy() {
    // Create new tag keys
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2);
    // Create a new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY);
    // Create another new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, NOT_INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Create a new fields set that will be used when testing the index search business object definitions method
    Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(TAG_CODE);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntityTwo = new TagEntity();
    tagEntity.setTagCode(TAG_CODE_2);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
    assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
    assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
    assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
    // Verify the calls to external methods
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Namespace(org.finra.herd.model.dto.Namespace) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagKey(org.finra.herd.model.api.xml.TagKey) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Test(org.junit.Test)

Example 72 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionReturnsEmptyResponseForEmptyTagEntities.

@Test
public void testIndexSearchBusinessObjectDefinitionReturnsEmptyResponseForEmptyTagEntities() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    // Create  a new business object definition search key for use in the business object definition search key list with an empty tag key
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(new ElasticsearchResponseDto());
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, new HashSet<>());
    assertThat("Expected empty response", CollectionUtils.isEmpty(businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions()));
    // Verify the calls to external methods
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Test(org.junit.Test)

Example 73 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsWithMultipleTagsIncludeTagHierarchy.

@Test
public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsIncludeTagHierarchy() {
    // Create new tag keys
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2);
    // Create a new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY);
    // Create another new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Create a new fields set that will be used when testing the index search business object definitions method
    Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(TAG_CODE);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntityTwo = new TagEntity();
    tagEntity.setTagCode(TAG_CODE_2);
    // Create a tag child entity to enter into the tag children entities list
    TagEntity tagChildEntity = new TagEntity();
    tagChildEntity.setTagCode(TAG_CODE_2);
    // Create a tag children entity list to return from the tag dao helper tag children entities method
    List<TagEntity> tagChildrenEntityList = new ArrayList<>();
    tagChildrenEntityList.add(tagChildEntity);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo);
    when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(tagChildrenEntityList);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
    assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
    assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
    assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
    // Verify the calls to external methods
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(tagDaoHelper).getTagChildrenEntities(tagEntity);
    verify(tagDaoHelper).getTagChildrenEntities(tagEntityTwo);
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Namespace(org.finra.herd.model.dto.Namespace) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagKey(org.finra.herd.model.api.xml.TagKey) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Test(org.junit.Test)

Example 74 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagServiceTest method testGetBusinessObjectDefinitionTagsByTagWhenChildrenExists.

@Test
public void testGetBusinessObjectDefinitionTagsByTagWhenChildrenExists() throws Exception {
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create a root tag entity for the tag type.
    TagEntity rootTagEntity = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION);
    // Create two children for the root tag with tag display name in reverse order.
    List<TagEntity> childrenTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntity), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntity));
    // Create one grandchild of the root tag.
    TagEntity grandchildTagEntity = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, childrenTagEntities.get(0));
    // Create four business object definition entities (one for each tag nesting level used in this test) with display names in reverse order.
    List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME_3, NO_ATTRIBUTES), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME_2, NO_ATTRIBUTES), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME_3, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME, NO_ATTRIBUTES));
    // Create and persist business object definition tag entities for all tags in each level of the hierarchy.
    // Please note that in order to validate the sort order, the same business object definition is used for both immediate children of the root tag.
    businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(0), rootTagEntity);
    businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(1), childrenTagEntities.get(0));
    businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(1), childrenTagEntities.get(1));
    businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(2), grandchildTagEntity);
    // Set the maximum allowed tag nesting to be bigger than the number of levels in our tag hierarchy.
    modifyPropertySourceInEnvironment(new HashMap<String, Object>() {

        {
            put(ConfigurationValue.MAX_ALLOWED_TAG_NESTING.getKey(), 10);
        }
    });
    try {
        // Get business object definition tags for the root tags and all their children tags in the hierarchy with max nesting level set to 10.
        assertEquals(new BusinessObjectDefinitionTagKeys(Arrays.asList(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME_3), new TagKey(TAG_TYPE, TAG_CODE_4)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME_2), new TagKey(TAG_TYPE, TAG_CODE_3)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME_2), new TagKey(TAG_TYPE, TAG_CODE_2)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE)))), businessObjectDefinitionTagService.getBusinessObjectDefinitionTagsByTag(new TagKey(TAG_TYPE, TAG_CODE)));
    } finally {
        restorePropertySourceInEnvironment();
    }
    // Set the maximum allowed tag nesting to 1 - that should cut off the grandchild tag.
    modifyPropertySourceInEnvironment(new HashMap<String, Object>() {

        {
            put(ConfigurationValue.MAX_ALLOWED_TAG_NESTING.getKey(), 1);
        }
    });
    try {
        // Get business object definition tags for the root tags and all their children tags in the hierarchy with max nesting level set to 1.
        assertEquals(new BusinessObjectDefinitionTagKeys(Arrays.asList(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME_2), new TagKey(TAG_TYPE, TAG_CODE_3)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME_2), new TagKey(TAG_TYPE, TAG_CODE_2)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE)))), businessObjectDefinitionTagService.getBusinessObjectDefinitionTagsByTag(new TagKey(TAG_TYPE, TAG_CODE)));
    } finally {
        restorePropertySourceInEnvironment();
    }
}
Also used : BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionTagKeys(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKeys) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) Test(org.junit.Test)

Example 75 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearchInvalidIndexSearchFilter.

@Test
public void testIndexSearchInvalidIndexSearchFilter() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    // Create an index search filter that contains index search keys for tag and result type.
    final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(NO_EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY), new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))));
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, Collections.singletonList(indexSearchFilter), NO_INDEX_SEARCH_FACET_FIELDS, NO_ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // 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 external calls.
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    // Try to call the method under test.
    try {
        indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Index search keys should be a homogeneous list of either index search result type keys or tag keys.", e.getMessage());
    }
    // Verify the external calls.
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verifyNoMoreInteractionsHelper();
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Aggregations

TagEntity (org.finra.herd.model.jpa.TagEntity)111 Test (org.junit.Test)77 TagKey (org.finra.herd.model.api.xml.TagKey)55 ArrayList (java.util.ArrayList)44 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)33 Tag (org.finra.herd.model.api.xml.Tag)28 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)13 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)12 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)11 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 Predicate (javax.persistence.criteria.Predicate)9 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)9 TagCreateRequest (org.finra.herd.model.api.xml.TagCreateRequest)9 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)8 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)8 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)8