@Test
public void testAddIndexSearchFilterBooleanClauseWithTagHierarchy()
{

    TagKey tagKey = new TagKey();
    tagKey.setTagCode(TAG_CODE);
    tagKey.setTagTypeCode(TAG_TYPE_CODE);
    TagKey childTagKey = new TagKey();
    childTagKey.setTagCode(TAG_CODE_2);
    childTagKey.setTagTypeCode(TAG_TYPE_CODE);
    IndexSearchResultTypeKey indexSearchResultTypeKey = new IndexSearchResultTypeKey();
    indexSearchResultTypeKey.setIndexSearchResultType(INDEX_SEARCH_RESULT_TYPE);
    List<IndexSearchKey> indexSearchKeys = new ArrayList<>();
    IndexSearchKey indexSearchKey = new IndexSearchKey();
    indexSearchKey.setIncludeTagHierarchy(true);
    indexSearchKey.setTagKey(tagKey);
    indexSearchKey.setIndexSearchResultTypeKey(indexSearchResultTypeKey);
    indexSearchKeys.add(indexSearchKey);
    List<IndexSearchFilter> indexSearchFilters = new ArrayList<>();
    IndexSearchFilter indexSearchFilter1 = new IndexSearchFilter();
    indexSearchFilter1.setIsExclusionSearchFilter(true);
    indexSearchFilter1.setIndexSearchKeys(indexSearchKeys);
    IndexSearchFilter indexSearchFilter2 = new IndexSearchFilter();
    indexSearchFilter2.setIsExclusionSearchFilter(false);
    indexSearchFilter2.setIndexSearchKeys(indexSearchKeys);
    indexSearchFilters.add(indexSearchFilter1);
    indexSearchFilters.add(indexSearchFilter2);
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode(tagKey.getTagCode());
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(tagKey.getTagCode());
    tagEntity.setTagType(tagTypeEntity);
    TagEntity childTagEntity = new TagEntity();
    childTagEntity.setTagCode(childTagKey.getTagCode());
    childTagEntity.setTagType(tagTypeEntity);
    childTagEntity.setParentTagEntity(tagEntity);
    tagEntity.setChildrenTagEntities(Lists.newArrayList(childTagEntity));
    // Setup the when clauses
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(Lists.newArrayList(childTagEntity));
    BoolQueryBuilder result = elasticsearchHelper.addIndexSearchFilterBooleanClause(indexSearchFilters, "bdefIndex", "tagIndex");
    assertThat("Result is null.", result, is(notNullValue()));
    // Verify the when clauses
    verify(tagDaoHelper, times(2)).getTagEntity(tagKey);
    verify(tagDaoHelper, times(2)).getTagChildrenEntities(tagEntity);
    verifyNoMoreInteractionsHelper();
}