use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceIndexTest method testIndexSpotCheckMostRecentValidationTagsObjectMappingException.
@Test
public void testIndexSpotCheckMostRecentValidationTagsObjectMappingException() 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_MOST_RECENT_NUMBER, Integer.class)).thenReturn(10);
when(tagDao.getMostRecentTags(10)).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))));
when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(false);
// Call the method under test
boolean isSpotCheckMostRecentValid = tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_TYPE_TAG);
assertThat("Tag service index spot check most recent validation is true when it should have been false.", isSpotCheckMostRecentValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
verify(tagDao).getMostRecentTags(10);
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, tagHelper);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceIndexTest method testIndexSpotCheckMostRecentValidationTagsFalse.
@Test
public void testIndexSpotCheckMostRecentValidationTagsFalse() 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_MOST_RECENT_NUMBER, Integer.class)).thenReturn(10);
when(tagDao.getMostRecentTags(10)).thenReturn(rootTagEntities);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
when(tagHelper.safeObjectMapperWriteValueAsString(any(TagEntity.class))).thenReturn("JSON_STRING");
// Call the method under test
boolean isSpotCheckMostRecentValid = tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_TYPE_TAG);
assertThat("Tag service index spot check most recent validation is true when it should have been false.", isSpotCheckMostRecentValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
verify(tagDao).getMostRecentTags(10);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
verifyNoMoreInteractions(tagDao, configurationHelper, jsonHelper, tagHelper);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceIndexTest method testIndexSpotCheckPercentageValidationTagsFalse.
@Test
public void testIndexSpotCheckPercentageValidationTagsFalse() 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(false);
// 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));
verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper, jsonHelper);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceIndexTest method testUpdateSearchIndexDocumentTagCreateEmpty.
@Test
public void testUpdateSearchIndexDocumentTagCreateEmpty() 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("");
doNothing().when(indexFunctionsDao).createIndexDocuments(any(), any(), any());
// 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)).createIndexDocuments(any(), any(), any());
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceTest method testCreateTagMissingOptionalParametersPassedAsWhitespace.
@Test
public void testCreateTagMissingOptionalParametersPassedAsWhitespace() {
// Create and persist a tag type entity.
tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create a tag key.
TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
// Create a tag with description passed in as whitespace.
Tag tag = tagService.createTag(new TagCreateRequest(tagKey, TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, BLANK_TEXT, NO_PARENT_TAG_KEY));
// Get the tag entity.
TagEntity tagEntity = tagDao.getTagByKey(tagKey);
assertNotNull(tagEntity);
// Validate the response object.
assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, BLANK_TEXT, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), tag);
}
Aggregations