Search in sources :

Example 91 with TagEntity

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

the class TagServiceIndexTest method testUpdateSearchIndexDocumentTagCreate.

@Test
public void testUpdateSearchIndexDocumentTagCreate() throws Exception {
    List<TagEntity> tagEntityList = new ArrayList<>();
    TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION);
    TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2);
    tagEntityList.add(tagEntity1);
    tagEntityList.add(tagEntity2);
    List<Integer> tagIds = new ArrayList<>();
    tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId()));
    // Create a document on the search index
    SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_CREATE);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList);
    when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING");
    // Call the method under test
    tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto);
    // Verify the calls to external methods
    verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagDao, times(1)).getTagsByIds(tagIds);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagKey(org.finra.herd.model.api.xml.TagKey) SearchIndexUpdateDto(org.finra.herd.model.dto.SearchIndexUpdateDto) Test(org.junit.Test)

Example 92 with TagEntity

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

the class TagServiceIndexTest method testIndexSpotCheckPercentageValidationTags.

@Test
public void testIndexSpotCheckPercentageValidationTags() throws Exception {
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class)).thenReturn(0.2);
    when(tagDao.getPercentageOfAllTags(0.2)).thenReturn(rootTagEntities);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING");
    when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(true);
    // Call the method under test
    boolean isSpotCheckPercentageValid = tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_TYPE_TAG);
    assertThat("Tag service index spot check random validation is false when it should have been true.", isSpotCheckPercentageValid, is(true));
    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class);
    verify(tagDao).getPercentageOfAllTags(0.2);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
    verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper, jsonHelper);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Test(org.junit.Test)

Example 93 with TagEntity

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

the class TagServiceIndexTest method testIndexSpotCheckPercentageValidationTagsObjectMappingException.

@Test
public void testIndexSpotCheckPercentageValidationTagsObjectMappingException() throws Exception {
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class)).thenReturn(0.2);
    when(tagDao.getPercentageOfAllTags(0.2)).thenReturn(rootTagEntities);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
    // Call the method under test
    boolean isSpotCheckPercentageValid = tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_TYPE_TAG);
    assertThat("Tag service index spot check random validation is true when it should have been false.", isSpotCheckPercentageValid, is(false));
    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class);
    verify(tagDao).getPercentageOfAllTags(0.2);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verifyNoMoreInteractions(tagDao, configurationHelper, jsonHelper);
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Test(org.junit.Test)

Example 94 with TagEntity

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

the class TagServiceIndexTest method testUpdateSearchIndexDocumentTagUpdateEmpty.

@Test
public void testUpdateSearchIndexDocumentTagUpdateEmpty() throws Exception {
    List<TagEntity> tagEntityList = new ArrayList<>();
    TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION);
    TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2);
    tagEntityList.add(tagEntity1);
    tagEntityList.add(tagEntity2);
    List<Integer> tagIds = new ArrayList<>();
    tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId()));
    // Create a document on the search index
    SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(tagDao.getTagsByIds(tagIds)).thenReturn(tagEntityList);
    when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("");
    // Call the method under test
    tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto);
    // Verify the calls to external methods
    verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagDao, times(1)).getTagsByIds(tagIds);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verify(indexFunctionsDao, times(1)).updateIndexDocuments(any(), any(), any());
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagKey(org.finra.herd.model.api.xml.TagKey) SearchIndexUpdateDto(org.finra.herd.model.dto.SearchIndexUpdateDto) Test(org.junit.Test)

Example 95 with TagEntity

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

the class TagServiceIndexTest method testUpdateSearchIndexDocumentTagUnknown.

@Test
public void testUpdateSearchIndexDocumentTagUnknown() throws Exception {
    List<TagEntity> tagEntityList = new ArrayList<>();
    TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_DESCRIPTION);
    TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(new TagKey(TAG_TYPE_2, TAG_CODE_2), TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2);
    tagEntityList.add(tagEntity1);
    tagEntityList.add(tagEntity2);
    List<Integer> tagIds = new ArrayList<>();
    tagEntityList.forEach(tagEntity -> tagIds.add(tagEntity.getId()));
    // Unknown modification type
    SearchIndexUpdateDto searchIndexUpdateDto = new SearchIndexUpdateDto(MESSAGE_TYPE_TAG_UPDATE, tagIds, "UNKNOWN");
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    // Call the method under test
    tagService.updateSearchIndexDocumentTag(searchIndexUpdateDto);
    // Verify the calls to external methods
    verify(configurationHelper, times(1)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagKey(org.finra.herd.model.api.xml.TagKey) SearchIndexUpdateDto(org.finra.herd.model.dto.SearchIndexUpdateDto) 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