@Override public boolean indexSizeCheckValidationTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long tagDatabaseTableSize = tagDao.getCountOfAllTags(); if (tagDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, tag database table size {}, does not equal index size {}.", tagDatabaseTableSize, indexSize); } return tagDatabaseTableSize == indexSize; }
@Override public boolean indexSizeCheckValidationTags(String indexName) { final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); // Simple count validation, index size should equal entity list size final long indexSize = indexFunctionsDao.getNumberOfTypesInIndex(indexName, documentType); final long tagDatabaseTableSize = tagDao.getCountOfAllTags(); if (tagDatabaseTableSize != indexSize) { LOGGER.error("Index validation failed, tag database table size {}, does not equal index size {}.", tagDatabaseTableSize, indexSize); } return tagDatabaseTableSize == indexSize; }
@Test public void testIndexSizeCheckValidationTags() throws Exception { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(tagDao.getCountOfAllTags()).thenReturn(100L); // Call the method under test boolean isIndexSizeValid = tagService.indexSizeCheckValidationTags(SEARCH_INDEX_TYPE_TAG); assertThat("Tag service index size validation is false when it should have been true.", isIndexSizeValid, is(true)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(tagDao).getCountOfAllTags(); verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper); }
@Test public void testIndexSizeCheckValidationTagsFalse() throws Exception { // Mock the call to external methods when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE"); when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(100L); when(tagDao.getCountOfAllTags()).thenReturn(200L); // Call the method under test boolean isIndexSizeValid = tagService.indexSizeCheckValidationTags(SEARCH_INDEX_TYPE_TAG); assertThat("Tag service index size validation is true when it should have been false.", isIndexSizeValid, is(false)); // Verify the calls to external methods verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class); verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any()); verify(tagDao).getCountOfAllTags(); verifyNoMoreInteractions(tagDao, configurationHelper); }
@Test public void testGetCountOfAllTags() { // 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)); // Get the count of all tags assertEquals(rootTagEntities.size(), tagDao.getCountOfAllTags()); } }